예제 #1
0
        public async Task CheckChooseForFundingStatus_GivenNoSpecSummariesFoundForFundingPeriodId_ReturnsCanChoose()
        {
            //Arrange
            SpecificationSummary specificationSummary = new SpecificationSummary
            {
                FundingPeriod = new Reference
                {
                    Id = fundingPeriodId
                }
            };

            ISpecificationService specificationService = CreateSpecificationService();

            specificationService
            .GetSpecificationSummaryById(Arg.Is(specificationId))
            .Returns(specificationSummary);

            specificationService
            .GetSpecificationsSelectedForFundingByPeriod(Arg.Is(fundingPeriodId))
            .Returns((IEnumerable <SpecificationSummary>)null);

            SpecificationFundingStatusService specificationFundingStatusService = CreateSpecificationFundingStatusService(specificationService: specificationService);

            //Act
            SpecificationFundingStatus status = await specificationFundingStatusService.CheckChooseForFundingStatus(specificationId);

            //Assert
            status
            .Should()
            .Be(SpecificationFundingStatus.CanChoose);
        }
예제 #2
0
        public async Task <SpecificationFundingStatus> CheckChooseForFundingStatus(SpecificationSummary specificationSummary)
        {
            Guard.ArgumentNotNull(specificationSummary, nameof(specificationSummary));

            if (specificationSummary.IsSelectedForFunding)
            {
                return(SpecificationFundingStatus.AlreadyChosen);
            }

            string fundingPeriodConfigId = specificationSummary.FundingPeriod.Id;

            IEnumerable <SpecificationSummary> specificationSummaries = await _specificationService.GetSpecificationsSelectedForFundingByPeriod(fundingPeriodConfigId);

            if (specificationSummaries.IsNullOrEmpty())
            {
                return(SpecificationFundingStatus.CanChoose);
            }

            HashSet <string> chosenFundingStreams = new HashSet <string>(specificationSummaries.SelectMany(m => m.FundingStreams.Select(fs => fs.Id)));

            IEnumerable <string> fundingStreamIds = specificationSummary.FundingStreams.Select(m => m.Id);

            if (chosenFundingStreams.Intersect(fundingStreamIds).Any())
            {
                return(SpecificationFundingStatus.SharesAlreadyChosenFundingStream);
            }
            else
            {
                return(SpecificationFundingStatus.CanChoose);
            }
        }
예제 #3
0
        public async Task CheckChooseForFundingStatus_GivenSpecWIthMultipleFundingStreamsAndSpecsReturnedForFundingPeriodWithSameFundingStream_ReturnsSharesAlreadyChoseFundingStream()
        {
            //Arrange
            SpecificationSummary specificationSummary = new SpecificationSummary
            {
                FundingPeriod = new Reference
                {
                    Id = fundingPeriodId
                },
                FundingStreams = new[]
                {
                    new Reference("fs-2", "fs2"),
                    new Reference("fs-4", "fs4")
                }
            };

            IEnumerable <SpecificationSummary> specificationSummaries = new[]
            {
                new SpecificationSummary
                {
                    FundingStreams = new[]
                    {
                        new Reference("fs-1", "fs1"),
                        new Reference("fs-5", "fs5"),
                    }
                },
                new SpecificationSummary
                {
                    FundingStreams = new[]
                    {
                        new Reference("fs-3", "fs3"),
                        new Reference("fs-4", "fs4"),
                    }
                }
            };

            ISpecificationService specificationService = CreateSpecificationService();

            specificationService
            .GetSpecificationSummaryById(Arg.Is(specificationId))
            .Returns(specificationSummary);

            specificationService
            .GetSpecificationsSelectedForFundingByPeriod(Arg.Is(fundingPeriodId))
            .Returns(specificationSummaries);

            SpecificationFundingStatusService specificationFundingStatusService = CreateSpecificationFundingStatusService(specificationService: specificationService);

            //Act
            SpecificationFundingStatus status = await specificationFundingStatusService.CheckChooseForFundingStatus(specificationId);

            //Assert
            status
            .Should()
            .Be(SpecificationFundingStatus.SharesAlreadyChosenFundingStream);
        }