Type arguments cannot be inferred from the usage - Rhino error in unit testing C#

1.1k Views Asked by At

Having gone through the net forums, still unable to rectify this error in my unit testing for the below line.

SetupResult.For
    (strategyFactory.RuleByMailRoomProcess(null, out isMailRoomRequired, out currentAndMailRoom))
        .IgnoreArguments()
        .Return(currentAndMailRoom, isMailRoomRequired, currentAndMailRoom);

Initially, it worked fine, but the line was like below:

SetupResult.For(strategyFactory.RuleByMailRoomProcess(null))
    .IgnoreArguments()
    .Return(currentAndMailRoom, isMailRoomRequired, currentAndMailRoom);

I had to add two out parameters and I did. But it throws the error as below:

Error 166 The type arguments for method 'Rhino.Mocks.SetupResult.For(T)' cannot be inferred from the usage. Try specifying the type arguments explicitly. C:\Me\ControllerBaseTests.cs 473 13 UnitTests

Could someone help me please, I am new to this.

1

There are 1 best solutions below

3
Amir Abiri On

If you just want to make it compile, simply add the type explicitly:

SetupResult.For<ResultType>(strategyFactory.RuleByMailRoomProcess(null, out isMailRoomRequired, out currentAndMailRoom))
    .IgnoreArguments()
    .Return(currentAndMailRoom, isMailRoomRequired, currentAndMailRoom);

If you want it to be inferred successfully, you have to investigate why the inference fails. Most likely RuleByMailRoomProcess is overloaded and can return multiple types.