Mahabubul Sony
Mahabubul Sony

Reputation: 11

The type arguments for method "" cannot be inferred from the usage. Try specifying the type arguments explicitly

I am doing XUnit test.

Actual method:

 public async Task<HttpRequestResponse<EcapNotificationServiceResponse>>
            NotifyToUsersAsync<T>(T notification, string messageKey, string responseKey, IEnumerable<string> userIds, bool success, string errorMessage)
{
    var notifierPayload = new
    {
        NotificationType = NotificationServiceType
        .UserSpecificReceiverType.ToString(),
        ResponseKey = responseKey,
        UserIds = userIds,

        DenormalizedPayload = JsonConvert.SerializeObject(new
        {
            MessageKey = messageKey,
            Result = notification,
            ErrorMessage = errorMessage,
            Success = success
        }),
        ResponseValue = JsonConvert.SerializeObject(
            new { Success = success }),
    };

    return await NotifyAsync(notifierPayload);
}

I am passing Test method

var response = await notificationService.NotifyToUsersAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<List<string>>(), It.IsAny<bool>(), It.IsAny<string>());

Error message shown this

The type arguments for method 'Infrastructure.Contract.INotificationServiceAdapter.NotifyToUsersAsync(T, string, string, System.Collections.Generic.IEnumerable, bool, string)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

Upvotes: 1

Views: 1151

Answers (1)

pakeha_by
pakeha_by

Reputation: 2244

You are passing It.IsAny<string>() as first argument, I assume you are testing case where typeof(T) == typeof(string)

var response = await notificationService.NotifyToUsersAsync<string>(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<List<string>>(), It.IsAny<bool>(), It.IsAny<string>());

Upvotes: 0

Related Questions