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
Welcome to Typemock Community! Here you can ask and receive answers from other community members. If you liked or disliked an answer or thread: react with an up- or downvote.
0 votes
Hello,

If I do:

var fake = Isolate.Fake.Instance<A>();
Isolate.SwapNextInstance<A>();
Isolate.WhenCalled(() => fake.Statement).CallOriginal();
Isolate.WhenCalled(() => fake.Statement = "").CallOriginal();

Is it possible to get the swapped value? So this swapped instance I want to get the Statement value. Can it be done?

Thanks.
asked by bmains (13.2k points)

1 Answer

0 votes
Hi,

I am not sure I understood what you meant.

If you want to verify that Statement was set to a specific value you can do it using the Verify methods. By the way, Isolator True Properties feature makes the test pass without setting "CallOriginal" on the properties.

For example:
var fake = Isolate.Fake.Instance<A>();
Isolate.SwapNextInstance<A>().With(fake);

var a = new A();
a.Statement = "A";

Isolate.Verify.WasCalledWithExactArguments(() => { fake.Statement = "A"; });
Assert.AreEqual("A", a.Statement);


If you want to perform an action when the value is being set you can do it using the "DoInstead" functinallity.

For example:
var fake = Isolate.Fake.Instance<A>();
Isolate.SwapNextInstance<A>().With(fake);

string propertValue = string.Empty;

Isolate.WhenCalled(() => fake.Statement)
    .DoInstead(context => propertValue);

Isolate.WhenCalled(() => fake.Statement = "")
    .DoInstead(context =>
    {
        propertValue = (string) context.Parameters[0];
        return propertValue;
    });



var a = new A();
a.Statement = "A";

Isolate.Verify.WasCalledWithExactArguments(() => { fake.Statement = "A"; });
Assert.AreEqual("A", a.Statement);


Please let me know if it helps.

Best Regards,
Elisha
Typemock Support Team
answered by Elisha (12k points)
...