With TypeMock 5.3.0.0, Visual Studio 2008 SP1:
In the test below, I create an Args object with a property Value = "x". The test fails, claiming the expected method was never called. In the debugger I see that args.Value is correctly set to "x", but after executing Isolate.WhenCalled, args.Value has been reset to null!
Thanks,
Larry
namespace DisappearingPropertyValue
{
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TypeMock.ArrangeActAssert;
public class Args
{
public string Value { get; set; }
}
public class A
{
public static void F(Args args)
{
(new B()).G(args.Value);
}
}
public class B
{
public void G(string s) { }
}
[TestClass]
public class UnitTest1
{
[TestMethod]
public void MethodIsCalledWithExpectedValue()
{
Args args = new Args { Value = "x" };
B fakeB = Isolate.Fake.Instance<B>();
// Before: args.Value == "x"
Isolate.WhenCalled(() => fakeB.G(args.Value)).WithExactArguments().IgnoreCall();
// After: args.Value == null
Isolate.Swap.NextInstance<B>().With(fakeB);
A.F(args);
Isolate.Verify.WasCalledWithExactArguments(() => fakeB.G(args.Value));
}
}
}