Search code examples
c#mockingjustmock

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.


Solution

  • 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.