Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vladonemo committed Jan 29, 2016
1 parent 440d967 commit 1bb17d2
Show file tree
Hide file tree
Showing 6 changed files with 944 additions and 795 deletions.
24 changes: 23 additions & 1 deletion Source/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;

using Moq.Proxy;
using System.Linq.Expressions;
using Moq.Properties;
Expand Down Expand Up @@ -189,7 +191,27 @@ public static bool IsMockeable(this Type typeToMock)
return typeToMock.IsInterface || typeToMock.IsAbstract || typeToMock.IsDelegate() || (typeToMock.IsClass && !typeToMock.IsSealed);
}

public static bool CanOverride(this MethodBase method)
public static bool IsSerializableMockable(this Type typeToMock)
{
return typeToMock.ContainsDeserializationConstructor() && typeToMock.IsGetObjectDataVirtual();
}

private static bool IsGetObjectDataVirtual(this Type typeToMock)
{
var getObjectDataMethod = typeToMock.GetInterfaceMap(typeof(ISerializable)).TargetMethods[0];
return !getObjectDataMethod.IsPrivate && getObjectDataMethod.IsVirtual && !getObjectDataMethod.IsFinal;
}

private static bool ContainsDeserializationConstructor(this Type typeToMock)
{
return typeToMock.GetConstructor(
BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
null,
new[] {typeof (SerializationInfo), typeof (StreamingContext)},
null) != null;
}

public static bool CanOverride(this MethodBase method)
{
return method.IsVirtual && !method.IsFinal && !method.IsPrivate;
}
Expand Down
Loading

0 comments on commit 1bb17d2

Please sign in to comment.