Moq - Linq expression in repository - Specify expression in setup

后端 未结 2 2036
梦谈多话
梦谈多话 2021-02-14 13:16

I have a method on my interface that looks like:

T GetSingle(Expression> criteria);

I\'m trying to mock the setup som

2条回答
  •  遥遥无期
    2021-02-14 13:56

    I managed to get this to work:

    Expression> expr = user => user.EmailAddress == "a@b.com";
    
    _mockUserRepository.Setup(c => c.GetSingle(It.Is>>(criteria => criteria == expr)))
        .Returns(new User { EmailAddress = "a@b.com" });
    
    User result = _mockUserRepository.Object.GetSingle(expr);
    

提交回复
热议问题