Search code examples
c#nunitmoq

How to mock which is returning list of integers on some where condition?


I blocked in below step

var ids = _repository.GetIQueryable<Customers>().Where(lrt => lrt.IsActive == true &&
                       lrt.NextRoleId == defaultRoleSetting.RoleId &&
                       lrt.NextUserId == null).Select(x => x.MasterId).Distinct().Take(100).ToHashSet();

I tried this but I don't find the right Returns syntax

_mockRepository.Setup(s => s.GetIQueryable<Customers>()).Returns<List<int>>(ids =>
{
  return ????;
});

Solution

  • by below code my issue solved thanks every one.

    var fakeCustomers = FakeCustomers();
    _repository.Setup(s => s.GetIQueryable<Customers()).Returns(fakeCustomers.AsQueryable());
        
        private List<Customers> FakeCustomers()
                {
                    string fakeData = @"[{
          'Id': '118',
          'CreatedBy':'00000000-0000-0000-0000-000000000000',
          'SId':'4',
          'UserId':'00000000-0000-0000-0000-000000000000',
          'NId':'7'
        }]";
                    return JsonConvert.DeserializeObject<List<Customers>>(fakeData);
                }