Hi,
I have the following test code
[TestMethod()]
public void EnumerateTest()
{
ResourceEnumerateClientManager target = new ResourceEnumerateClientManager();
string xPathCondition = string.Empty; // TODO: Initialize to an appropriate value
Message fakeMesage = Isolate.Fake.Instance<Message>();
Isolate.WhenCalled(() => fakeMesage.IsFault).WillReturn(true);
Isolate.Fake.StaticMethods<Message>();
Isolate.WhenCalled(() => Message.CreateMessage(MessageVersion.Default, string.Empty)).WillReturn(fakeMesage);
EnumerateClient fakeEnumerateClient = Isolate.Fake.Instance<EnumerateClient>();
Isolate.WhenCalled(() => fakeEnumerateClient.Enumerate(fakeMesage)).WillReturn(fakeMesage);
Isolate.Swap.NextInstance<EnumerateClient>().With(fakeEnumerateClient);
target.Enumerate<ResourceBase>(xPathCondition);
// Verify expected value
}
Message is WCF message (System.ServiceModel.Channels.Message). When the following statement is run...
Isolate.WhenCalled(() => Message.CreateMessage(MessageVersion.Default, string.Empty)).WillReturn(fakeMesage);
... I get the following error message
Test method TypeMockTests.UnitTests.EnumerateTest threw exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object..
And the stack is
TypeMock.MockManager.a(String A_0, String A_1, Object A_2, Object A_3, Boolean A_4, Object[] A_5)
TypeMock.InternalMockManager.getReturn(Object that, String typeName, String methodName, Object methodParameters, Boolean isInjected, Object p1, Object p2)
System.ServiceModel.Channels.Message.CreateMessage(MessageVersion version, String action)
b__4() in c:
akeshTypeMockTestsTypeMockTestsUnitTests.cs: line 100
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
System.Delegate.DynamicInvokeImpl(Object[] args)
System.Delegate.DynamicInvoke(Object[] args)
c9.e()
c9.a(Object A_0)
a(T A_0)
TypeMockTests.UnitTests.EnumerateTest() in c:
akeshTypeMockTestsTypeMockTestsUnitTests.cs: line 100
Thanks.