If I do this:
var repository = new Mock<IRepository<Banner>>();
repository.Setup(x => x.Where(banner => banner.Is.AvailableForFrontend())).Returns(list);
"Where" is a method on my repository that takes a Func<T, ISpecification<T>
. AvailableForFrontend returns an implementation of ISpecification, and list is an IEnumberable of the generic type of the repository.
It compiles fine, but i get the following error when I run my tests.
---- System.NotSupportedException : Expression banner => Convert((banner.Is.AvailableForFrontend() & banner.Is.SmallMediaBanner())) is not supported.
If i use my other overload of Where on the repository that takes a ISpecification directly, theres no problem.
So my newbie mock / Moq question is: Can I stub a method call with a lamdba as parameter? Or should I go about this in another way?
have you tried the following syntax:
repository.Setup(x => x.Where(It.IsAny<Func<T, ISpecification<T>>()).Returns(list);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With