我想模仿这个方法:
public HttpClient CreateHttpClientForJwt(Func<HttpResponseMessage, bool> isUnauthenticated, int timeoutSeconds)
{
var client = Mvx.Resolve<IPlatformOperationProvider>().CreateHttpClient(timeoutSeconds);
return new HttpClient(new AuthenticatedHttpMessageHandler(this, client, AuthenticationUtils.AddJwtToRequest, isUnauthenticated,_loggingService));
}
我的尝试:
authenticatedRequestServiceMock.Setup(sm => sm.CreateHttpClientForJwt(It.IsAny<Expression<Func<HttpResponseMessage, bool>>>, 5)).Returns(stubHttpClient.Object);
我在编译之前在IsAny
Visual studio上收到此错误:
期望使用
的方法'bool IsAny(HttpResponseMessage)'
我做错了什么?
答案 0 :(得分:1)
删除
中的表达式authenticatedRequestServiceMock
.Setup(sm => sm.CreateHttpClientForJwt(It.IsAny<Expression<Func<HttpResponseMessage, bool>>>, 5))
.Returns(stubHttpClient.Object);
并将It.IsAny
更新为
authenticatedRequestServiceMock
.Setup(sm => sm.CreateHttpClientForJwt(It.IsAny<Func<HttpResponseMessage, bool>>(), 5))
.Returns(stubHttpClient.Object);
It.IsAny<TValue>()
是一种方法,但您将其称为属性。您还将该方法描述为期望Func
,但使用Expression<Func<>>