vendredi 26 août 2016

Use ItExpr.IsNull

I am trying to write a unit test where I need to set up a protected method. I am using Moq for this setup.

_innerHandler.Protected()
             .Setup<Task<HttpResponseMessage>>("SendAsync", It.IsAny<HttpRequestMessage>(), It.IsAny<CancellationToken>())
             .ReturnsAsync(responseMessage);

When this line executes, it throws the following exception:

System.ArgumentException : Use ItExpr.IsNull<TValue> rather than a null argument value, as it prevents proper method lookup.

When I change it to use ItExpr.IsNull<TValue>, it does allow the test to execute. However, it is of course missing the setup I wanted to configure.

What do I need to do in order to set up a protected method using It.IsAny<TValue>?

Aucun commentaire:

Enregistrer un commentaire