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

Hey guys,

Say I have this piece of code ( class "AnExample"):

  public class AnExample

    {

        private string SomePrivateField;

        private int SomeOtherPrivateField= 0;

 public ClassUnderTest()

        {

            SomePrivateField = "Blablabla";

        }

}

I want to fake the instance of "SomePrivateField" and make it return "Hello!" rather than "Blablabla". How do I do it?

When I try with Isolate.Fake.Instance<AnExample> the test fails with the message that the actual output is "Blablabla" and not "Hello!". Any insights?

asked by Sonya_g (640 points)
edited by Sonya_g

1 Answer

0 votes
Something like this works for me:

var example = new AnExample();
Isolate.NonPublic.InstanceField(example, \"_privateString\").Value = \"Bar\";            Assert.AreEqual(\"Bar\", example.GetMessage());
answered by petermorlion (640 points)
...