Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Mock repository with a GetAllIncluding statement #5035


User avatar
0
carelearning created

Hello,

What is the best way to mock this linq statement:

var results =  _groupRepository
                .GetAllIncluding(x => x.OrganizationUnit)
                .Where(x => x.Id != id)
                .ToList();

We have tried something like:

_groupRepository.Setup(x => x.GetAllIncluding(It.IsAny<Expression<Func<Group, object>>>)
                                  .Where(It.IsAny<Expression<Func<Group, bool>>>))
                                 .Returns(groups.AsQueryable);

This will not compiled due to " Error CS1503: Argument 1: cannot convert from 'method group' to 'Expression<Func<Group, object>>' " Is this possible?

Thanks.


3 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    You are missing parentheses:

    _groupRepository.Setup(x => x.GetAllIncluding(It.IsAny<Expression<Func<Group, object>>>())
                                 .Where(It.IsAny<Expression<Func<Group, bool>>>()))
                    .Returns(groups.AsQueryable);
    
  • User Avatar
    0
    carelearning created

    Thank you @aaron for catching our silly mistake.

  • User Avatar
    0
    alper created
    Support Team

    thanks for the feedback