chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
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));
        }
    }
}
asked by lgolding@microsoft.c (4k points)

2 Answers

0 votes
Hi Larry,

One problem I can see with the test is that the Verify statement has a nested chain - Isolator does not currently support nested chains in the lambdas provided to it. Breaking the nesting should work better:
var argValue = args.Value;
Isolate.Verify.WasCalledWithExactArguments(() => fakeB.G(argValue)); 


Please try running this and let me know if it fixed the issue.

Thanks,
Doron
Typemock Support
answered by doron (17.2k points)
0 votes
That works, thanks.

Larry
answered by lgolding@microsoft.c (4k points)
...