lundi 2 mai 2016

Unit testing LINQ which returns an integer

I have this test which verifies if I call the Query() in my reference.

[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());
    }
}

However, the GetLicenseCount(Guid.NewGuid(), Guid.NewGuid()) function looks like this:

 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() returns all in the repo to count which UserId's are in null. Is it enough to say that the test is OK even if it only verifies the query() part of the linq? How about the count?

Aucun commentaire:

Enregistrer un commentaire