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,

I'm trying to fake method that returns collection in Isolator for example: Hashtable
but what the fake method returned is Null while i'm expecting an Empty Hashtable.

I would expect the next test to pass:
    public class HashClass
    {
        public Hashtable Foo()
        {
            return null;
        }
    }
        [TestMethod]
        public void FakeCollections()
        {            
            var fake = Isolate.Fake.Instance<HashClass>();
            Hashtable hashtable = fake.Foo();
            Assert.IsNotNull(hashtable);
        }


- James
asked by JamesKing (8.2k points)

2 Answers

0 votes
Hi,

I'm glad to tell you that we are working on this right now to act as you described.
Meanwhile i can suggest a walk around solution using WhenCalled with WillReturn feature like this :

       [Test]
        public void ReturnCollectionWorks()
        {
            var fake = Isolate.Fake.Instance<HashClass>();
            Isolate.WhenCalled(() => fake.Foo()).WillReturn(new Hashtable());
            Hashtable hash = fake.Foo();
            Assert.IsNotNull(hash);
        }
answered by Shai Barak (1.5k points)
0 votes
Great !
I'm happy to hear that.
And thanks for the workaround! :D

- James
answered by JamesKing (8.2k points)
...