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
0 votes
        [TestMethod]
        public void Foo()
        {
            using (RecordExpectations recorder = new RecordExpectations())
            {
                Class1 c1 = Class2.GetClass1();
                recorder.Return(c1); // recorder.ReturnDefaultImplementation();
                

                int i1 = c1.Foo();
                recorder.Return(123);
            };

            Class1 c2 = Class2.GetClass1();
            int i2 = c2.Foo();
            Assert.IsTrue(i2 == 123);
        }


The question is, is there any differens between calling recorder.Return(c1) or calling recorder.ReturnDefaultImplementation() in that case? Or better say, is there any differense between calling recorder.return(obj) or recorder.ReturnDefaultImplementation() when method returns another object? And what is best practive for such cases.

Thanks.
asked by tom3m (9.7k points)

1 Answer

0 votes
Hi,
Technically there is not much difference between the two, although I would use the ReturnDefualtImplementation option. The other way is not the "proper" way to go.

Regarding your second question. You use Recorder.return(obj) when you want to return your own specified value. i.e. In order for the test to pass you need to return a specific value/instance. Returning default implementation is used when you don't really care what is returned from the method (mainly since its not used afterwords).

Hope this helps.
answered by lior (13.2k points)
...