Getting The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider' when initializing Test

68 Views Asked by At

This is my TestInitialize

[TestInitialize]
public void SetUp()
{
  _emailSenderService = new Mock<IEmailSenderService>();
  _personRepository = new Mock<IPersonRepository>();
  _configurationService = new Mock<IConfigurationService>();
  _contactService = new Mock<IContactService>();
  _mapper = new Mock<IMapper>();
  _subscriptionService = new Mock<ISubscriptionsService>();
  _notificationRepository = new Mock<INotificationRepository>();
  _dbcontext = new Mock<MyAdaptiveCloudContext>();

  var data = new List<Notification>();

  _notificationRepository.Setup(x => x.GetNotificationsByOrgId(It.IsAny<int>())).Returns(data.AsQueryable());

  _notificationsService = new NotificationsService(_dbcontext.Object, _emailSenderService.Object, _personRepository.Object, _notificationRepository.Object, _mapper.Object, _configurationService.Object,
                _subscriptionService.Object, _contactService.Object);
}

And then I try to use it like this

[TestMethod]
public async Task GetNotifications_Test_SortOrderAsc()
{
  var today = DateTime.Today;
  var organizationId = 1;
  var request = new NotificationsListRequest
  {
    CurrentPage = 1,
    FromDate = today.AddDays(-1),
    OrderBy = "location",
    OrderDir = "asc",
    PageSize = 10,
    SearchTerm = "",
    ToDate = DateTime.Now,
  };

  var notifications = await _notificationsService.GetNotifications(organizationId, request);
            var notificationsList = notifications.Item1;

  Assert.AreEqual(notificationsList[0].NotificationId, 1);
  Assert.AreEqual(notificationsList[1].NotificationId, 4);
  Assert.AreEqual(notificationsList[2].NotificationId, 2);
  Assert.AreEqual(notificationsList[3].NotificationId, 3);
}

And I get an error when trying to do await _notificationsService.GetNotifications like this

System.InvalidOperationException: The provider for the source 'IQueryable' doesn't implement 'IAsyncQueryProvider'. Only providers that implement 'IAsyncQueryProvider' can be used for Entity Framework asynchronous operations.

What am I doing wrong?

0

There are 0 best solutions below