I have a service class like this:
public class CategoryService: ICategoryService
{
private myContext _context;
public CategoryService(myContext context)
{
_context = context;
}
public async Task<List<CategoryDTO>> GetCategories()
{
return (await _context.Categories.ToListAsync()).Select(c => new CategoryDTO
{
CategoryId = c.CategoryId,
CategoryName = c.CategoryName
}).ToList();
}
}
My context looks like this:
public DbSet<Category> Categories {get;set;}
My unit test for GetCategories() is:
[Fact]
public void TestGetCategories()
{
//Arrange
Mock <myContext> moq = new Mock <myContext>();
var moqSet = new Mock<DbSet<Category>>();
moq.Setup(m => m.Categories).Returns(moqSet.Object);
CategoryService service = new CategoryService(moq.Object);
//Act
var result = service.GetCategories();
//Assert
Assert.NotNull(result);
}
But I am getting error for my unit test. It says:
System.NotSupportedException : Unsupported expression: m => m.Categories
Can someone help me to fix the Setup part?