public async Task GetFundingStream_WhenFundingStreamFound_ShouldReturnOkResult()
        {
            // Arrange
            string fundingStreamId = "PSG";

            Models.Specs.FundingStream fundingStream = new Models.Specs.FundingStream
            {
                Id   = fundingStreamId,
                Name = "PE and Sport Grant",
                RequireFinancialEnvelopes = true
            };

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

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

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

            mockFundingService
            .GetFundingStreamById(Arg.Is(fundingStreamId))
            .Returns(new OkObjectResult(fundingStream));

            FundingStreamService fundingStreamService = new FundingStreamService(mockFundingService, mapper);

            // Act
            IActionResult result = await fundingStreamService.GetFundingStream(fundingStreamId);

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

            FundingStream actualFundingStream = okResult.Value
                                                .Should()
                                                .BeOfType <FundingStream>()
                                                .Subject;

            actualFundingStream.Id.Should().Be(fundingStreamId);
            actualFundingStream.Name.Should().Be(fundingStream.Name);
            actualFundingStream.RequireFinancialEnvelopes.Should().Be(fundingStream.RequireFinancialEnvelopes);
        }
        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");
        }
Ejemplo n.º 3
0
        public void Mapper_SpecFundingStreamToModelFundingStream_ShouldReturnCorrectFundingStream()
        {
            // Arrange
            Mapper.Reset();
            MapperConfigurationExpression mappings = new MapperConfigurationExpression();

            mappings.AddProfile <ExternalApiMappingProfile>();
            Mapper.Initialize(mappings);
            IMapper mapperUnderTest         = Mapper.Instance;
            string  allocationLineId        = "Id";
            string  allocationLineName      = "Name";
            string  allocationLineShortName = "short-name";

            Models.Specs.FundingStream fundingStream = new Models.Specs.FundingStream()
            {
                AllocationLines = new List <Models.Specs.AllocationLine>()
                {
                    new Models.Specs.AllocationLine()
                    {
                        Id                 = allocationLineId,
                        Name               = allocationLineName,
                        ShortName          = allocationLineShortName,
                        FundingRoute       = Models.Specs.FundingRoute.LA,
                        IsContractRequired = true
                    }
                },
                Name       = "Name",
                Id         = "id",
                ShortName  = "short-name",
                PeriodType = new Models.Specs.PeriodType
                {
                    Id         = "p1",
                    Name       = "period 1",
                    StartDay   = 1,
                    EndDay     = 31,
                    StartMonth = 8,
                    EndMonth   = 7
                }
            };

            // Act
            V1.Models.FundingStream mappedFundingStream = mapperUnderTest.Map <V1.Models.FundingStream>(fundingStream);

            // Assert
            mappedFundingStream.Should().NotBeNull();
            mappedFundingStream.Id.Should().Be(fundingStream.Id);
            mappedFundingStream.Name.Should().Be(fundingStream.Name);
            mappedFundingStream.ShortName.Should().Be(fundingStream.ShortName);
            mappedFundingStream.PeriodType.Id.Should().Be("p1");
            mappedFundingStream.PeriodType.Name.Should().Be("period 1");
            mappedFundingStream.PeriodType.StartDay.Should().Be(1);
            mappedFundingStream.PeriodType.StartMonth.Should().Be(8);
            mappedFundingStream.PeriodType.EndDay.Should().Be(31);
            mappedFundingStream.PeriodType.EndMonth.Should().Be(7);
            mappedFundingStream.AllocationLines.Should().Contain(
                a => a.Id == allocationLineId &&
                a.Name == allocationLineName && a.ShortName ==
                allocationLineShortName &&
                a.FundingRoute == "LA" &&
                a.ContractRequired == "Y")
            .Should().NotBeNull();
        }