我有这个测试来验证我是否在我的参考中调用了 Query()。
[TestFixture]
public class When_retrieving_an_application_license
{
[Test]
public void available_licenses_should_be_counted()
{
// Arrange
var sut = new LicenseManager();
var mockILicenseRepository = new Mock<ILicenseRepository>();
sut.LicenseRepository = mockILicenseRepository.Object;
// Act
sut.GetLicenseCount(Guid.NewGuid(), Guid.NewGuid());
// Assert
mockIApplicationLicenseRepository.Verify(x => x.Query());
}
}
但是,GetLicenseCount(Guid.NewGuid(), Guid.NewGuid()) 函数如下所示:
public int GetLicenseCount(Guid cId, Guid appId)
=> LicenseRepository.Query()
.Count(al => al.CId == cId && al.AppId == appId
&& al.UserId == null
&& al.Expiry > DateTime.UtcNow);
Query() 在 repo 中返回 all 以计算哪些 UserId 为 null。 即使它只验证 linq 的 query() 部分,是否可以说测试是可以的?计数呢?