简体   繁体   中英

Mocking out parameters with JustMock

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM