I’m trying to mock method using Moq that takes FilterExpression as an input parameter and I have no luck so far. When I run it is always returns null. If I pass NULL
instead of FilterExpression it works.
Here is my code:
Repository
public interface ITestRepository
{
string Test(int id, FilterExpression fe);
}
public class TestRepository : ITestRepository
{
public stringTest(int id, FilterExpression fe)
{
throw new NotImplementedException();
}
}
Unit Test
var testMock = new Mock<ITestRepository>();
var fe = new FilterExpression();
var result = “Hello World”;
var id = 1;
//DOESN’T WORK
testMock.Setup(r => r.Test(id, filterExpression)).Returns(result);
//WORKS
testMock.Setup(r => r.Test(id, null)).Returns(result);
//Test
[TestMethod]
public void test()
{
var fe = new FilterExpression();
var id = 1;
_testRepository.Test(id, fe);
_testRepository.Test(id, null);
}
Aucun commentaire:
Enregistrer un commentaire