Skip to content
This repository has been archived by the owner on Jul 12, 2020. It is now read-only.

Failing on unit tests when calling ToListAsync() #128

Open
ssraman1977 opened this issue Mar 24, 2020 · 0 comments
Open

Failing on unit tests when calling ToListAsync() #128

ssraman1977 opened this issue Mar 24, 2020 · 0 comments

Comments

@ssraman1977
Copy link

ssraman1977 commented Mar 24, 2020

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]'.

How can I properly Moq this process?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant