I am trying to be a good TDD citizen when developing an application. I am using Moq, and I ran into the problem of a small repository.
My repository has a search method:
public IEnumerable<T> Find(Expression<Func<T, bool>> where)
{
return _objectSet.Where(where);
}
Then I try to customize the repository layout:
mock.Setup(m => m.Find(c => c.ConferenceID == conferenceID))
.Returns(ConferenceTestObjectContainer.CreateConferences().Where(c => c.ConferenceID == conferenceID).ToList());
The test will work if I test the layout directly in the test, but if I paste the layout into my production code (on an ASP.NET page in this case) and check the page method, it does not work,
Justin Eatelge solves the problem in his post here . The problem is that the comparison between the call and the setup cannot handle expressions so well.
The problem I ran into is related to its comparison function:
public static Expression<Func<T,bool>> AreEqual<T>(Expression<Func<T,bool>> expr)
{
return Match<Expression<Func<T, bool>>>
.Create(t => t.ToString() == expr.ToString());
}
This causes a compiler error:
"Moq.Match.Create(System.Predicate)" . .
, "", , . - , , .
.