I'm trying to verify that Delete
on my DomainContext
has been called with an expression containing a specific value. So, simple contrived example - real code:
DomainContext.Delete<Entity>(x => x.Id == id);
Test code:
DomainContext = new Mock<DomainContext>();
DomainContext.Setup(x => x
.Delete<Entity>(
It.Is<System.Linq.Expressions.Expression<Func<Entity, bool>>>
(predicate => predicate == x => x.Id == id)
).Verifiable();
// act
DomainContext.Verify();
Obviously won't work because it's trying to compare two predicates by reference - and it may not even be evaluating the id
variable on one or both sides!
Is there some way I can write a predicate (something like It.HasProperty
?!) to replace predicate == x => x.Id == id
to check that there is a call to check the predicate was called with Id == the ID I'm expecting
?