I am trying to setup a unit test for the following method I created:
---- Service Method ----
public async Task<List> GetEmployeesAsync()
{
return await _store.Query().ToListAsync());
}
-----
I setup the following using MOQ:
---- Unit Test ----
var store = new Mock<ICosmosStore>();
store.Setup(p => p.Query(null)).Returns(
new Employees[] {
new Employee() { Name = "Test Employee" }
}.AsQueryable());
var target = new EmployeeService(store.Object);
var result = await target.GetEmployeesAsync();
-------
I receive the following error when the ToListAsync() is called:
System.InvalidCastException : Unable to cast object of type 'System.Linq.EnumerableQuery1[Lcp.Domain.Entities.Employee]' to type 'Microsoft.Azure.Documents.Linq.IDocumentQuery1[Lcp.Domain.Entities.Employee]'.
I am trying to setup a unit test for the following method I created:
---- Service Method ---- public async Task<List> GetEmployeesAsync()
{
return await _store.Query().ToListAsync());
}
-----
I setup the following using MOQ:
---- Unit Test ---- var store = new Mock<ICosmosStore>();
store.Setup(p => p.Query(null)).Returns( new Employees[] { new Employee() { Name = "Test Employee" } }.AsQueryable());
var target = new EmployeeService(store.Object); var result = await target.GetEmployeesAsync(); -------
I receive the following error when the ToListAsync() is called:
System.InvalidCastException : Unable to cast object of type 'System.Linq.EnumerableQuery
1[Lcp.Domain.Entities.Employee]' to type 'Microsoft.Azure.Documents.Linq.IDocumentQuery
1[Lcp.Domain.Entities.Employee]'.How can I properly Moq this process?