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
Hi,

any reason why the following doesn't work:
     [Test]
        [Isolated]
        public void TestRefArgument()
        {
            List<int> fakeList = new List<int>() {   BELOW_WARNING, 
                                                    ABOVE_WARNING, 
                                                    BELOW_WARNING, 
                                                    BELOW_WARNING, 
                                                    BELOW_WARNING };
            //var fake = new FakedClass();
            var fake = Isolate.Fake.Instance<FakedClass>();
            Isolate.WhenCalled(() => fake.SomeMethod(out fakeList)).IgnoreCall();
            Isolate.Swap.NextInstance<FakedClass>().With(fake);

            var target = new UnderTest2();
            var actual = target.CheckForCrapWarning("");

            Assert.AreEqual(true,actual);
        }

class FakedClass
    {

        public void SomeMethod(out List<int> list)
        {
            list = null;
        }
    }

    public class UnderTest2
    {
        private const int _WARNING_THRESHOLD = 30;
        //read the file fill the data into the array,
        //do some logic over array
        public bool CheckForCrapWarning(string fileName)
        {
            FakedClass parser = new FakedClass();
            List<int> listToPass = new List<int>();
            parser.SomeMethod(out listToPass);

            foreach (var value in listToPass)
            {
                if (value > _WARNING_THRESHOLD)
                    return true;
            }
            return false;
        }
    }



:!: if you replace the fake creation with a live instance (see the remark), suddenly everything starts working ok.


:oops: also the example in the documentation has several mistakes.
asked by error (6.6k points)

5 Answers

0 votes
Hi Lior,

We have a known bug with ref/out parameters when using recursive fakes You can use Members.ReturnNulls or other behavior other than the default when creating the fake, this will make the test pass.

Thanks for pointing out the documentation errors :oops: we'll fix that.
answered by ohad (35.4k points)
0 votes
Thanks. It would be very helpful (read extremely time-saving) if you would add a 'known bugs' section to the documentation for faking out/ref parameters. That way, anyone that reads how to use this feature would also know the work-around.

Cheers,

Darin
answered by Darin_Creason (3.5k points)
0 votes
Hi Darin,
We have a known issue section in our developer guide. :)
Check it out here
answered by ohad (35.4k points)
0 votes
Any updates on this issue?
answered by error (6.6k points)
0 votes
This issue status has not changed yet - when it will I will post an update on this thread
answered by dhelper (11.9k points)
...