Exemplo n.º 1
0
        public void count_licenses_by_user__filters_each_installation__if_value_set_enumerated()
        {
            var setA = new HashSet <Installation> {
                _installA
            };
            var setB = new HashSet <Installation> {
                _installB
            };
            var setC = new HashSet <Installation> {
                _installC
            };
            var userSets = new[] { setA, setB, setC };

            var filter   = A.Fake <IInstallationFilter>();
            var assessor = A.Fake <ILicenseAssessor>();
            var mapIndex = A.Fake <IInstallationIndexMap>();
            var catalog  = new InstallationCatalog(mapIndex);

            A.CallTo(() => mapIndex.Values).Returns(userSets);

            // This is required so the enumeration IS evaluated, otherwise it will be lazily ignored, and filters won't be called.
            // Tests for the assessor should show that it WILL be evaluated in a functioning system.
            A.CallTo(() => assessor.AssessInstallationLicenses(A <IEnumerable <Installation> > ._))
            .Invokes(callObject => (callObject.Arguments[0] as IEnumerable <Installation>)?.ToList());

            catalog.CountLicensesByUser(filter, assessor);

            A.CallTo(() => filter.Filter(_installA)).MustHaveHappenedOnceExactly();
            A.CallTo(() => filter.Filter(_installB)).MustHaveHappenedOnceExactly();
            A.CallTo(() => filter.Filter(_installC)).MustHaveHappenedOnceExactly();
        }
Exemplo n.º 2
0
        public void count_licenses_by_user__calls_assessor__and__sums__assessor_results()
        {
            const int expectedResult = 3; // Should match number of sets returned by mapIndex.Value

            var setA = new HashSet <Installation> {
                _installA
            };
            var setB = new HashSet <Installation> {
                _installB
            };
            var setC = new HashSet <Installation> {
                _installC
            };
            var userSets = new[] { setA, setB, setC };

            var filter   = A.Fake <IInstallationFilter>();
            var assessor = A.Fake <ILicenseAssessor>();
            var mapIndex = A.Fake <IInstallationIndexMap>();
            var catalog  = new InstallationCatalog(mapIndex);

            A.CallTo(() => mapIndex.Values).Returns(userSets);
            A.CallTo(() => assessor.AssessInstallationLicenses(A <IEnumerable <Installation> > ._)).Returns(1);

            var result = catalog.CountLicensesByUser(filter, assessor);

            Assert.That(result, Is.EqualTo(expectedResult));
        }
Exemplo n.º 3
0
        public void count_licenses_by_user__retrieves__index_map_value()
        {
            var filter   = A.Fake <IInstallationFilter>();
            var assessor = A.Fake <ILicenseAssessor>();
            var mapIndex = A.Fake <IInstallationIndexMap>();
            var catalog  = new InstallationCatalog(mapIndex);

            // No point testing the result here, it's simply a consequence of default FakeItEasy mock behaviours.
            catalog.CountLicensesByUser(filter, assessor);

            A.CallTo(() => mapIndex.Values).MustHaveHappened();
        }