Je suis nouveau à Moq, donc j'espère qu'il me manque quelque chose ici. Pour une raison quelconque, j'obtiens une exception TargetParameterCountException.Utilisation de Moq: objet mock jetant 'TargetParameterCountException'
Pouvez-vous voir ce que je fais mal? Des questions? S'il vous plaît demander. :)
Voici mon code:
[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();
}
Voici la méthode HasStudent de persistance:
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;
}
Qu'est-ce qui se passe si vous Substitue It.IsAny pour It.IsAny
@Kirschstein: qui ne compilera pas –