正如评论中提到的Callback
使用的参数与方法定义不匹配。尽管Setup
uses It.IsAny<LoggingContext>
方法定义使用ILoggingContext
范围
Change t2
to
ILoggingContext t2 = null;
并更新Callback
to
.Callback<ICustomerRequest<IEnumerable<CustomerPreference>>,CancellationToken, ILoggingContext>((a, b, c) => {
t = a;
t1 = b;
t2 = c;
});
or
.Callback((ICustomerRequest<IEnumerable<CustomerPreference>> a,
CancellationToken b,
ILoggingContext c) => {
t = a;
t1 = b;
t2 = c;
});
无论哪种方式都会起作用。
我还建议Setup
返回一个已完成的Task
以便允许测试按预期异步进行。
this.customerPreferenceRepositoryMock
.Setup(x => x.UpdateAsync(
It.IsAny<ICustomerRequest<IEnumerable<CustomerPreference>>>(),
It.IsAny<CancellationToken>(),
It.IsAny<LoggingContext>()))
.Callback((ICustomerRequest<IEnumerable<CustomerPreference>> a,
CancellationToken b,
ILoggingContext c) => {
t = a;
t1 = b;
t2 = c;
//Use the input to create a response
//and pass it to the `ReturnsAsync` method
})
.ReturnsAsync(new GeneralResponseType()); //Or some pre initialized derivative.
查看最小起订量快速开始更好地了解如何使用该框架。