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
Try the following code:

 public class FakedClass
        public void SomeMethod(out string name, out int id)
            throw new NotImplementedException();

    public class TestedClass
        private FakedClass Member;

        public TestedClass(FakedClass member)
            Member = member;    
        public void DoSomething()
            string strToPass = string.Empty;
            int idToPass = 0;

            Member.SomeMethod(out strToPass, out idToPass);

            Assert.AreEqual("abc", strToPass);
            Assert.AreEqual(42, idToPass);

    public class OutParamFakeTest
        public void TestOutParameter()
            string strToReturn = "abc";
            int idToReturn = 42;

            var fake = Isolate.Fake.Instance<FakedClass>();
            Isolate.WhenCalled(() => fake.SomeMethod(out strToReturn, out idToReturn)).IgnoreCall();

            var testedClass = new TestedClass(fake);


The Assert in DoSomething() fails!?
The only difference between the above example and the example in the Typemock documentation is that I am trying to fake the out param of a method on a faked object versus the documentation example which fakes the out param of a method on a real object; is this the problem?
asked by patrick.gill@verint. (2.6k points)

2 Answers

0 votes

This seems to be a bug in out parameter handling on fakes. I am logging it and we'll fix it in a future version. As a work around you can instantiate FakedClass either using a constructor, or using Isolate.Fake.Instance<FakedClass>(Members.CallOriginal) - these options will cause the instance to behave like a normal FakedClass instance, except for the methods put through WhenCalled().

Typemock Support
answered by doron (17.2k points)
0 votes
Workaround using Isolate.Fake.Instance<FakedClass>(Members.CallOriginal) worked.
answered by patrick.gill@verint. (2.6k points)