public async Task GetFundingStreams_GivenNullOrEmptyFundingStreamsReturned_LogsAndReturnsOKWithEmptyList()
        {
            // Arrange
            ILogger logger = CreateLogger();

            IEnumerable <FundingStream> fundingStreams = null;

            IPolicyRepository policyRepository = CreatePolicyRepository();

            policyRepository
            .GetFundingStreams()
            .Returns(fundingStreams);

            FundingStreamService fundingStreamsService = CreateFundingStreamService(logger: logger, policyRepository: policyRepository);

            // Act
            IActionResult result = await fundingStreamsService.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"));
        }
        public async Task GetFundingStreams_GivenFundingStreamsAlreadyInCache_ReturnsOKWithResultsFromCachel()
        {
            // Arrange
            ILogger logger = CreateLogger();

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

            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider
            .GetAsync <FundingStream[]>(Arg.Is(CacheKeys.AllFundingStreams))
            .Returns(fundingStreams.ToArray());

            IPolicyRepository policyRepository = CreatePolicyRepository();

            FundingStreamService fundingStreamsService = CreateFundingStreamService(logger, cacheProvider, policyRepository);

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

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

            OkObjectResult objectResult = result as OkObjectResult;

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

            values
            .Should()
            .HaveCount(2);

            await
            policyRepository
            .DidNotReceive()
            .GetFundingStreams();
        }
        public async Task GetFundingStreams_GivenFundingStreamsReturned_ReturnsOKWithResults()
        {
            // Arrange
            ILogger logger = CreateLogger();

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

            IPolicyRepository policyRepository = CreatePolicyRepository();

            policyRepository
            .GetFundingStreams()
            .Returns(fundingStreams);

            ICacheProvider cacheProvider = CreateCacheProvider();

            FundingStreamService fundingStreamsService = CreateFundingStreamService(logger, cacheProvider, policyRepository);

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

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

            OkObjectResult objectResult = result as OkObjectResult;

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

            values
            .Should()
            .HaveCount(2);

            await
            cacheProvider
            .Received(1)
            .SetAsync <FundingStream[]>(Arg.Is(CacheKeys.AllFundingStreams), Arg.Is <FundingStream[]>(m => m.SequenceEqual(fundingStreams)));
        }
Exemple #4
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>();
        }
        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");
        }
Exemple #6
0
 private async Task <IActionResult> WhenGetFundingStreams()
 {
     return(await _fundingStreamService.GetFundingStreams());
 }