Mocking out parameters with JustMock

631 views Asked by At

I am writing unit tests and I need to mock the out parameter of the one of the target method dependencies with the following signature:

bool TryProcessRequest(out string)

I am using JustMock and I have tried to use DoInstead arrangement clause, but it seems that it is not so obvious.

Please advise me how to achieve this, many thanks in advance.

1

There are 1 answers

0
smolchanovsky On BEST ANSWER

This option will probably suit you:

var mock = Mock.Create<IYourInterface>(); 
string expectedResult = "result"; 
Mock.Arrange(() => mock.TryProcessRequest(out expectedResult)).Returns(true); 

string actualResult; 
bool isCallSuccessful = mock.TryProcessRequest(out actualResult);

So for this you need to create a local variable with the desired value and use that in the out position.