public void GivenBcrOptions_ThenWeShouldGetBcrRunner()
        {
            var factory = new ReportRunnerFactory();

            var options = new BcrOptions();

            Assert.That(factory.Create(options), Is.TypeOf(typeof(BcrReportRunner)));
        }
        public void GivenBcrOptions_ThenTheFileShouldBeInTheOutputDirectory()
        {
            var outputPath = @"C:\some\path\to\dir";
            var options    = new BcrOptions(null, null, null, null, null, outputPath, false);
            var provider   = new PathProvider(options);

            var actualPath = provider.NewPath();

            Assert.That(Path.GetDirectoryName(actualPath), Is.EqualTo(outputPath));
        }
        public void GivenNullOrEmptyBcrOptions_TheTheFileShouldBeInTheCurrentDirectory(string outputDir)
        {
            var options  = new BcrOptions(null, null, null, null, null, outputDir, false);
            var provider = new PathProvider(options);

            var actualPath   = provider.NewPath();
            var expectedPath = Directory.GetCurrentDirectory();

            Assert.That(Path.GetDirectoryName(actualPath), Is.EqualTo(expectedPath));
        }
Exemplo n.º 4
0
        public static IEnumerable <string> ValueOf(this BcrOptions options, Criteria criteria)
        {
            switch (criteria)
            {
            case Criteria.Tier1: return(options.Tier1);

            case Criteria.Tier2: return(options.Tier2);

            case Criteria.Tier3: return(options.Tier3);

            case Criteria.Tier4: return(options.Tier4);

            case Criteria.CostCentre: return(options.CostCentre);

            default: throw new NotSupportedException(criteria.ToString());
            }
        }
        public static bool Matches(this CostCentre costCentre, BcrOptions options)
        {
            if (!HasOption(options.Tier1) &&
                !HasOption(options.Tier2) &&
                !HasOption(options.Tier3) &&
                !HasOption(options.Tier4) &&
                !HasOption(options.CostCentre))
            {
                return(true);
            }

            var matchesTier1      = HasOption(options.Tier1) && Matches(options.Tier1, costCentre.Tier1);
            var matchesTier2      = HasOption(options.Tier2) && Matches(options.Tier2, costCentre.Tier2);
            var matchesTier3      = HasOption(options.Tier3) && Matches(options.Tier3, costCentre.Tier3);
            var matchesTier4      = HasOption(options.Tier4) && Matches(options.Tier4, costCentre.Tier4);
            var matchesCostCentre = HasOption(options.CostCentre) && Matches(options.CostCentre, costCentre.Code);

            return(matchesTier1 || matchesTier2 || matchesTier3 || matchesTier4 || matchesCostCentre);
        }
Exemplo n.º 6
0
        public BcrReader(
            ILogging log,
            BcrOptions options,
            IFile <Bcr> bcrFile,
            IFile <SerializableCostCentreList> costCentreFile,
            IUnit4EngineFactory factory,
            ICostCentresProvider provider)
        {
            _log         = log;
            _bcrFile     = bcrFile;
            _factory     = factory;
            _updateCache = options.UpdateCache;

            var costCentreList =
                new Cache <SerializableCostCentreList>(
                    () => provider.GetCostCentres(),
                    costCentreFile);

            _hierarchy = new CostCentreHierarchy(costCentreList, options);
        }
        public static BcrReportRunner Create(BcrOptions options, ProgramConfig config)
        {
            var assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            var log     = new Logging();
            var factory = new Unit4EngineFactory(config);
            var reader  =
                new BcrReader(
                    log,
                    options,
                    new JsonFile <Bcr>(Path.Combine(assemblyDirectory, "cache", "bcr.json")),
                    new JsonFile <SerializableCostCentreList>(
                        Path.Combine(
                            assemblyDirectory,
                            "cache",
                            "costCentres.json")),
                    factory,
                    new CostCentresProvider(factory));
            var filter       = new BcrFilter(options);
            var writer       = new Excel();
            var pathProvider = new PathProvider(options);

            return(new BcrReportRunner(log, reader, filter, writer, pathProvider));
        }
        public void GivenCostCentreOption_ThenOnlyTheTier3ForThatCostCentreShouldBeIncluded(BcrOptions options)
        {
            var costCentres = new[]
            {
                new CostCentre()
                {
                    Tier1 = "A1", Tier2 = "A2", Tier3 = "A3", Tier4 = "A4", Code = "A5"
                },
                new CostCentre()
                {
                    Tier1 = "B1", Tier2 = "B2", Tier3 = "B3", Tier4 = "B4", Code = "B5"
                }
            };

            var hierarchy = new CostCentreHierarchy(new DummyCostCentres(costCentres), options);

            var filteredList = hierarchy.GetHierarchyByTier3();

            Assert.That(filteredList.Select(x => x.Key), Is.EquivalentTo(new[] { "A3" }));
        }
Exemplo n.º 9
0
 public PathProvider(BcrOptions options)
 {
     _outputDir = string.IsNullOrEmpty(options.OutputDirectory)
         ? Directory.GetCurrentDirectory()
         : options.OutputDirectory;
 }
Exemplo n.º 10
0
 public BcrFilter(BcrOptions options)
 {
     _options = options;
 }
 public CostCentreHierarchy(ICache <SerializableCostCentreList> costCentres, BcrOptions options)
 {
     _costCentres = costCentres;
     _options     = options;
 }