// There are no unit tests for this file, as they would amount to a re-implementation of it. // It's simply too trivial to be worth testing with mocks. // However, it *is* tested via functional tests in the FunctionalTests class. /// <summary> /// Construct a ReportAnalyser that can read a report and count licenses. /// </summary> /// <param name="reportLoader">An IReportLoader to handle the file loading and parsing.</param> /// <param name="reportToModelConverter">An IReportToModelConverter to convert load results into model data.</param> /// <param name="installationCatalog">An IInstallationCatalog smart container that can perform efficient licesnse assessments.</param> /// <param name="licenseAssessor">An ILicenseAssessor to identify per-user license requirements.</param> public ReportAnalyser(IReportLoader reportLoader, IReportToModelConverter reportToModelConverter, IInstallationCatalog installationCatalog, ILicenseAssessor licenseAssessor) { _reportLoader = reportLoader; _reportToModelConverter = reportToModelConverter; _installationCatalog = installationCatalog; _licenseAssessor = licenseAssessor; }
/// <summary> /// Counts licenses that are tracked on a per-user basis. /// Filters the installations for each user, then assesses how many licenses are required for that installation set. /// The installs for all users are summed and returned. /// </summary> /// <param name="installationFilter">Filter used to isolate the installations to consider; applied to each user's installations prior to assessment.</param> /// <param name="licenseAssessor">Assessor used to count the licenses required for each user's filtered installations.</param> /// <returns>The sum of required licenses across all users.</returns> public int CountLicensesByUser(IInstallationFilter installationFilter, ILicenseAssessor licenseAssessor) { // Walk the dictionary, considering each user individually. var licensesRequiredTotal = 0; foreach (var userInstallations in _indexMap.Values) { var considerInstallations = userInstallations.Where(installationFilter.Filter); licensesRequiredTotal += licenseAssessor.AssessInstallationLicenses(considerInstallations); } return(licensesRequiredTotal); }