Elfocrash / Cosmonaut

🌐 A supercharged Azure CosmosDB .NET SDK with ORM support
https://cosmonaut.readthedocs.io
MIT License
342 stars 44 forks source link

Failing on unit tests when calling ToListAsync() #128

Open ssraman1977 opened 4 years ago

ssraman1977 commented 4 years ago

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?