I've got a method that converts a List to a DbSet which I use when mocking the data my database context should return. For example:
MockedDatabaseContext.Setup(u => u.SomeTable).Returns(GetDbSet(ListOfItems));
However the method I'm trying to write a unit test for uses the ToListAsync method at one point to convert from IQueryable to a List.
Is there a way using the Moq framework to make a setup on the ToListAsync method call?
I've tried this:
dbSet.Setup(d => d.ToListAsync(CancellationToken.None)).Returns((Task<List<T>>) Task.CompletedTask);
But this throws a 'ThrowIfSetupExpressionInvolvesUnsupportedMember' exception on the line above.