小编Mur*_*hna的帖子

Moq 和 C#:回调无效。带参数的方法设置无法调用带参数的回调

实际的接口签名是这样的

Task<GeneralResponseType> UpdateAsync(ICustomerRequest<IEnumerable<CustomerPreference>> request, CancellationToken cancellationToken, ILoggingContext loggingContext = null);
Run Code Online (Sandbox Code Playgroud)

测试用例:

ICustomerRequest<IEnumerable<CustomerPreference>> t = null;
CancellationToken t1 = new CancellationToken();
LoggingContext t2 = null;
this.customerPreferenceRepositoryMock.Setup(x => x.UpdateAsync(
        It.IsAny<ICustomerRequest<IEnumerable<CustomerPreference>>>(),
        It.IsAny<CancellationToken>(),
        It.IsAny<LoggingContext>()))
    .Callback<ICustomerRequest<IEnumerable<CustomerPreference>>,CancellationToken, LoggingContext>((a, b, c) => { t = a ; t1 =b;t2= c; });
Run Code Online (Sandbox Code Playgroud)

设置在测试用例中抛出异常,如下所示

回调无效。设置带有参数的方法(ICustomerRequest 1,CancellationToken,ILoggingContext) cannot invoke callback with parameters (ICustomerRequest1、CancellationToken、LoggingContext)。

我做错了什么?

我已验证起订量:回调无效。带参数的方法设置无法调用带参数的回调

但我没有看到任何帮助。

c# unit-testing moq

4
推荐指数
1
解决办法
8697
查看次数

标签 统计

c# ×1

moq ×1

unit-testing ×1