Я новичок в Moq, так что, надеюсь, мне здесь чего-то не хватает. По какой-то причине я получаю TargetParameterCountException.
Вы видите, что я делаю не так? Любые вопросы? Пожалуйста спросите. :)
Вот мой код:
[Test]
public void HasStudentTest_SaveToRepository_Then_HasStudentReturnsTrue()
{
var fakeStudents = new List<Student>();
fakeStudents.Add(new Student("Jim"));
mockRepository.Setup(r => r.FindAll<Student>(It.IsAny<Predicate<Student>>()))
.Returns(fakeStudents.AsQueryable<Student>)
.Verifiable();
// in persistence.HasStudent(), repo.FindAll(predicate) is throwing
// 'TargetParameterCountException' ; not sure why
persistence.HasStudent("Jim");
mockRepository.VerifyAll();
}
Вот метод HasStudent от Persistence:
public bool HasStudent(string name)
{
// throwing the TargetParameterCountException
var query = Repository.FindAll<Student>(s => s.Name == name);
if (query.Count() > 1)
throw new InvalidOperationException("There should not be multiple Students with the same name.");
return query.Count() == 1;
}