public void GenerateAllocations_GivenModelExecuteThrowsException_ThrowsException()
        {
            //Arrange
            BuildProject buildProject = CreateBuildProject();

            buildProject.Build.Assembly = MockData.GetMockAssembly();

            IEnumerable <ProviderSummary> providers = new[]
            {
                new ProviderSummary {
                    Id = ProviderId, Name = ProviderName
                }
            };

            IEnumerable <ProviderSourceDataset> datasets = new[]
            {
                new ProviderSourceDataset()
            };

            Func <string, string, Task <IEnumerable <ProviderSourceDataset> > > func = (s, p) =>
            {
                return(Task.FromResult(datasets));
            };

            IEnumerable <CalculationResult> calculationResults = new[]
            {
                new CalculationResult
                {
                    Calculation = new Reference {
                        Id = CalculationId
                    }
                }
            };

            IAllocationModel allocationModel = Substitute.For <IAllocationModel>();

            allocationModel
            .When(x => x.Execute(Arg.Any <List <ProviderSourceDataset> >(), Arg.Any <ProviderSummary>()))
            .Do(x => { throw new Exception(); });

            IAllocationFactory allocationFactory = Substitute.For <IAllocationFactory>();

            allocationFactory
            .CreateAllocationModel(Arg.Any <Assembly>())
            .Returns(allocationModel);

            ILogger logger = CreateLogger();

            CalculationEngine calculationEngine = CreateCalculationEngine(allocationFactory, logger: logger);

            //Act
            Func <Task> test = () => calculationEngine.GenerateAllocations(buildProject, providers, func);

            //Assert
            test
            .Should()
            .ThrowExactly <Exception>();
        }
        static IAllocationFactory CreateAllocationFactory(IAllocationModel allocationModel)
        {
            IAllocationFactory allocationFactory = Substitute.For <IAllocationFactory>();

            allocationFactory
            .CreateAllocationModel(Arg.Any <Assembly>())
            .Returns(allocationModel);

            return(allocationFactory);
        }
        async public Task GenerateAllocations_GivenBuildProject_Runs()
        {
            //Arrange
            BuildProject buildProject = CreateBuildProject();

            buildProject.Build.Assembly = MockData.GetMockAssembly();

            IEnumerable <ProviderSummary> providers = new[]
            {
                new ProviderSummary {
                    Id = ProviderId, Name = ProviderName
                }
            };

            IEnumerable <ProviderSourceDataset> datasets = new[]
            {
                new ProviderSourceDataset()
            };

            Func <string, string, Task <IEnumerable <ProviderSourceDataset> > > func = (s, p) =>
            {
                return(Task.FromResult(datasets));
            };

            IEnumerable <CalculationResult> calculationResults = new[]
            {
                new CalculationResult
                {
                    Calculation = new Reference {
                        Id = CalculationId
                    },
                }
            };

            IAllocationModel allocationModel = Substitute.For <IAllocationModel>();

            allocationModel
            .Execute(Arg.Any <List <ProviderSourceDataset> >(), Arg.Any <ProviderSummary>())
            .Returns(calculationResults);

            IAllocationFactory allocationFactory = Substitute.For <IAllocationFactory>();

            allocationFactory
            .CreateAllocationModel(Arg.Any <Assembly>())
            .Returns(allocationModel);

            ILogger logger = CreateLogger();

            ICalculationsRepository        calculationsRepository = CreateCalculationsRepository();
            List <CalculationSummaryModel> calculations           = new List <CalculationSummaryModel>()
            {
                new CalculationSummaryModel()
                {
                    Id = CalculationId,
                },
                new CalculationSummaryModel()
                {
                    Id = "calc2",
                },
                new CalculationSummaryModel()
                {
                    Id = "calc3",
                }
            };

            calculationsRepository
            .GetCalculationSummariesForSpecification(Arg.Any <string>())
            .Returns(calculations);

            CalculationEngine calculationEngine = CreateCalculationEngine(allocationFactory, calculationsRepository, logger: logger);

            //Act
            IEnumerable <ProviderResult> results = await calculationEngine.GenerateAllocations(buildProject, providers, func);

            //Assert
            results
            .Count()
            .Should()
            .Be(1);

            results
            .First()
            .CalculationResults
            .Count
            .Should()
            .Be(3);
        }
Пример #4
0
 public IAllocationModel GenerateAllocationModel(Assembly assembly)
 {
     return(_allocationFactory.CreateAllocationModel(assembly));
 }