コード例 #1
0
        public async Task GetFundingStreams_GivenNullOrEmptyFundingStreamsReturned_LogsAndReturnsOKWithEmptyList()
        {
            // Arrange
            ILogger logger = CreateLogger();

            IEnumerable <FundingStream> fundingStreams = null;

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetFundingStreams()
            .Returns(fundingStreams);

            IFundingService fundingService = CreateService(logger: logger, specificationsRepository: specificationsRepository);

            // Act
            IActionResult result = await fundingService.GetFundingStreams();

            // Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();

            OkObjectResult objectResult = result as OkObjectResult;

            IEnumerable <FundingStream> values = objectResult.Value as IEnumerable <FundingStream>;

            values
            .Should()
            .NotBeNull();

            logger
            .Received(1)
            .Error(Arg.Is("No funding streams were returned"));
        }
コード例 #2
0
        public async Task <IActionResult> GetFundingStreams()
        {
            IActionResult result = await _fundingService.GetFundingStreams();

            if (result is OkObjectResult okObjectResult)
            {
                IEnumerable <CalculateFunding.Models.Specs.FundingStream> fundingStream = (IEnumerable <CalculateFunding.Models.Specs.FundingStream>)okObjectResult.Value;
                if (fundingStream.IsNullOrEmpty())
                {
                    return(new OkResult());
                }
                else
                {
                    List <V2.Models.FundingStream> mappedFundingStreams = _mapper.Map <List <V2.Models.FundingStream> >(fundingStream);
                    return(new OkObjectResult(mappedFundingStreams));
                }
            }
            return(result);
        }
コード例 #3
0
        public async Task GetFundingStreams_WhenfundingStreamIsEmpty_ShouldReturnInternalServerErrorMessage()
        {
            // Arrange
            IMapper mapper = Substitute.For <IMapper>();

            OkObjectResult specServiceOkObjectResult = new OkObjectResult(new List <Models.Specs.FundingStream>());

            IFundingService mockFundingService = Substitute.For <IFundingService>();

            mockFundingService.GetFundingStreams().Returns(specServiceOkObjectResult);

            FundingStreamService fundingStreamService = new FundingStreamService(mockFundingService, mapper);

            // Act
            IActionResult result = await fundingStreamService.GetFundingStreams();

            // Assert
            result
            .Should().BeOfType <OkResult>();
        }
コード例 #4
0
        public async Task GetFundingStreams_GivenFundingStreamsReturned_ReturnsOKWithResults()
        {
            // Arrange
            ILogger logger = CreateLogger();

            IEnumerable <FundingStream> fundingStreams = new[]
            {
                new FundingStream(),
                new FundingStream()
            };

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetFundingStreams()
            .Returns(fundingStreams);

            IFundingService fundingService = CreateService(logger: logger, specificationsRepository: specificationsRepository);

            // Act
            IActionResult result = await fundingService.GetFundingStreams();

            // Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();

            OkObjectResult objectResult = result as OkObjectResult;

            IEnumerable <FundingStream> values = objectResult.Value as IEnumerable <FundingStream>;

            values
            .Count()
            .Should()
            .Be(2);
        }
コード例 #5
0
        public async Task GetFundingStreams_WhenServiceReturnsOkResult_ShouldReturnOkResultWithFundingStreams()
        {
            Models.Specs.FundingStream fundingStream = new Models.Specs.FundingStream()
            {
                AllocationLines = new List <Models.Specs.AllocationLine>()
                {
                    new Models.Specs.AllocationLine()
                    {
                        Id                 = "id",
                        Name               = "name",
                        ShortName          = "short-name",
                        FundingRoute       = Models.Specs.FundingRoute.LA,
                        IsContractRequired = true
                    }
                },
                Name      = "name",
                Id        = "id",
                ShortName = "short-name",
                RequireFinancialEnvelopes = true,
                PeriodType = new Models.Specs.PeriodType
                {
                    Id         = "p1",
                    Name       = "period 1",
                    StartDay   = 1,
                    EndDay     = 31,
                    StartMonth = 8,
                    EndMonth   = 7
                }
            };

            Mapper.Reset();
            MapperConfigurationExpression mappings = new MapperConfigurationExpression();

            mappings.AddProfile <ExternalApiMappingProfile>();
            Mapper.Initialize(mappings);
            IMapper mapper = Mapper.Instance;

            OkObjectResult specServiceOkObjectResult = new OkObjectResult(new[]
            {
                fundingStream
            });

            IFundingService mockFundingService = Substitute.For <IFundingService>();

            mockFundingService.GetFundingStreams().Returns(specServiceOkObjectResult);

            FundingStreamService fundingStreamService = new FundingStreamService(mockFundingService, mapper);

            // Act
            IActionResult result = await fundingStreamService.GetFundingStreams();

            // Assert
            result
            .Should().NotBeNull()
            .And
            .Subject.Should().BeOfType <OkObjectResult>();

            OkObjectResult okObjectResult = result as OkObjectResult;

            IEnumerable <FundingStream> fundingStreamResults = okObjectResult.Value as IEnumerable <FundingStream>;

            fundingStreamResults.Count().Should().Be(1);

            fundingStreamResults.First().Name.Should().Be("name");
            fundingStreamResults.First().Id.Should().Be("id");
            fundingStreamResults.First().ShortName.Should().Be("short-name");
            fundingStreamResults.First().RequireFinancialEnvelopes.Should().BeTrue();
            fundingStreamResults.First().PeriodType.Id.Should().Be("p1");
            fundingStreamResults.First().PeriodType.Name.Should().Be("period 1");
            fundingStreamResults.First().PeriodType.StartDay.Should().Be(1);
            fundingStreamResults.First().PeriodType.StartMonth.Should().Be(8);
            fundingStreamResults.First().PeriodType.EndDay.Should().Be(31);
            fundingStreamResults.First().PeriodType.EndMonth.Should().Be(7);
            fundingStreamResults.First().AllocationLines.First().Id.Should().Be("id");
            fundingStreamResults.First().AllocationLines.First().Name.Should().Be("name");
            fundingStreamResults.First().AllocationLines.First().ShortName.Should().Be("short-name");
            fundingStreamResults.First().AllocationLines.First().FundingRoute.Should().Be("LA");
            fundingStreamResults.First().AllocationLines.First().ContractRequired.Should().Be("Y");
        }
コード例 #6
0
 public async Task <IActionResult> RunFundingStreams()
 {
     return(await _fundingService.GetFundingStreams());
 }