Verify value of reference parameter with Moq

前端 未结 4 1447
南方客
南方客 2021-01-03 23:30

I just switched to Moq and have run into a problem. I\'m testing a method that creates a new instance of a business object, sets the properties of the object from user inpu

4条回答
  •  太阳男子
    2021-01-03 23:48

    I have encountered similar issue. Bit I got the solution by using the latest Moq and passing the value like

    var instance = new Bar(); Mock.Setup(foo => foo.Submit(ref instance)).Returns(true);

    Earlier as well, I was using the same method, but i was not getting return as true.

    Inside the actual function instance was getting created and overwriting the instance passed from the unit test class was causing the issue. I removed instance creation inside the actual class and then it worked.

    Hope it will help you.

    thanks

提交回复
热议问题