我有一个带有 Add 方法的存储库,该方法以 IEnumerable 作为参数:
public void Add<T>(T item) where T : class, new(){}
在单元测试中,我想验证此方法是否使用包含与另一个 IEnumerable 完全相同数量的元素的 IEnumerable 调用
[Test]
public void InvoicesAreGeneratedForAllStudents()
{
var students = StudentStub.GetStudents();
session.Setup(x => x.All<Student>()).Returns(students.AsQueryable());
service.GenerateInvoices(Payments.Jaar, DateTime.Now);
session.Verify(x => x.Add(It.Is<IEnumerable<Invoice>>(
invoices => invoices.Count() == students.Count())));
}
单元测试结果:
Moq.MockException :
Expected invocation on the mock at least once, but was never performed:
x => x.Add<Invoice>(It.Is<IEnumerable`1>(i => i.Count<Invoice>() == 10))
No setups configured.
我究竟做错了什么?