Moq & C#: Invalid callback. Setup on method with parameters cannot invoke callback with parameters

Viewed 6381

The actual interface signature goes like this

Task<GeneralResponseType> UpdateAsync(ICustomerRequest<IEnumerable<CustomerPreference>> request, CancellationToken cancellationToken, ILoggingContext loggingContext = null);

Testcase:

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; });

The setup is throwing an exception in the testcase,as below

Invalid callback. Setup on method with parameters (ICustomerRequest1,CancellationToken,ILoggingContext) cannot invoke callback with parameters (ICustomerRequest1,CancellationToken,LoggingContext).

What is wrong I am doing?

I have verified Moq: Invalid callback. Setup on method with parameters cannot invoke callback with parameters

But I didn't see any help.

1 Answers
Related