Vote count:
0
I'm using mongo driver, and trying to fake results of any to test whether Insert or Update was called based on results.
Here's piece of code I think relevant:
_context = _collection.AsQueryable();
if (_context.Any(s => s.Id == id))
{
...
after that I'm calling either _collection.Update() or _collection.Insert().
Here's what I tried so far with the unit test:
var collectionMock = new Mock<MongoCollection<Storage>>();
var queriableMock = new Mock<IQueryable<Storage>>();
queriableMock.Setup(q => Enumerable.Any(q)).Returns(() => false);
...
collectionMock.Setup(c => c.AsQueryable()).Returns(() => queriableMock.Object);
collectionMock.Setup(c => c.Save(It.IsAny<Storage>()));
I'm getting exception
"Expression references a method that does not belong to the mocked object: q => q.Any()"
asked 33 secs ago
Aucun commentaire:
Enregistrer un commentaire