I'm trying to setup Moq in a dotnetcore project. I have a generic repository that is called from one of my controllers. I would like to test this an is using moq to setup the call. But I get an error.
The generic repository call that is initiated so T
is Room
is:
public T GetSingle(Expression<Func<T, bool>> predicate, params
Expression<Func<T, object>>[] includeProperties)
The call from the RoomController
looks like:
var room = _roomRepository.GetSingle(r => r.Id == id, ro => ro.Image);
The mocking part looks like:
roomRepositoryMock.Setup(c => c.GetSingle(It.IsAny<Expression<Func<Room, bool>>>(), It.IsAny<Expression<Func<Room, object>>>()))
.Returns<Room>(null);
But I keep getting errors:
RoomControllerTest.cs(62,55): error CS1503: Argument 1: cannot convert from 'method group' to 'Expression<Func<Room, bool>>'
RoomControllerTest.cs(62,70): error CS1503: Argument 2: cannot convert from 'System.Linq.Expressions.Expression<System.Func<viten_i_senter_backend.Models.Room, object>>' to 'System.Linq.Expressions.Expression<System.Func<viten_i_senter_backend.Models.Room, object>>'
Other posts suggested to add ()
after It.IsAny<Expression<Func<Room, bool>>>
, but this did not help.
Any ideas?
params
takes an array so change the second expectation to expect any array of expressions It.IsAny<Expression<Func<Room, object>>[]>()
roomRepositoryMock
.Setup(c => c.GetSingle(It.IsAny<Expression<Func<Room, bool>>>(), It.IsAny<Expression<Func<Room, object>>[]>()))
.Returns<Room>(null);
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