Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to setup method out parameter to return mock in c#

I have service mock, which calls method, where one of parameters is out parameter.
How is it possible to out mocked object as this parameter, because I need to set up this mock further.

var randomObjectMock = new Mock<ISmth>(MockBehavior.Strict);
mock.Setup(x => x.DoSomething(out randomObjectMock);
ISmth randomObject;
var randomObjectMock = new Mock<ISmth>(MockBehavior.Strict);
mock.Setup(x => x.DoSomething(out randomObjectMock);`

Initialization randomObject is not an option.

Mock<ISmth > randomObject;
mock.Setup(x => x.DoSomething(out randomObjectMock.Object);

This also not an option.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I believe this should work:

var randomObjectMock = new Mock<ISmth>(MockBehavior.Strict);
var smth = randomObjectMock.Object;
mock.Setup(x => x.DoSomething(out smth));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading