Ejemplo n.º 1
0
        public async Task GetFundingStreamById_StringParam_GivenFundingStreamnWasFound_ReturnsSuccess()
        {
            // Arrange
            ILogger logger = CreateLogger();

            FundingStream fundingStream = new FundingStream
            {
                Id = FundingStreamId
            };

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetFundingStreamById(Arg.Is(FundingStreamId))
            .Returns(fundingStream);

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

            // Act
            IActionResult result = await fundingService.GetFundingStreamById(FundingStreamId);

            // Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();
        }
Ejemplo n.º 2
0
        public async Task GetFundingStreamById_StringParam_GivenFundingStreamnWasNotFound_ReturnsNotFound()
        {
            // Arrange
            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetFundingStreamById(Arg.Is(FundingStreamId))
            .Returns((FundingStream)null);

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

            // Act
            IActionResult result = await fundingService.GetFundingStreamById(FundingStreamId);

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

            logger
            .Received(1)
            .Error(Arg.Is($"No funding stream was found for funding stream id : {FundingStreamId}"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> GetFundingStream(string fundingStreamId)
        {
            IActionResult result = await _fundingService.GetFundingStreamById(fundingStreamId);

            if (result is OkObjectResult okObjectResult)
            {
                V2.Models.FundingStream mappedFundingStream = _mapper.Map <V2.Models.FundingStream>(okObjectResult.Value);
                return(new OkObjectResult(mappedFundingStream));
            }
            else
            {
                return(result);
            }
        }
        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);
        }
Ejemplo n.º 5
0
        public async Task GetFundingStreamById_GivenFundingStreamIdDoesNotExist_ReturnsBadRequest()
        {
            // Arrange
            HttpRequest request = Substitute.For <HttpRequest>();

            ILogger logger = CreateLogger();

            IFundingService fundingService = CreateService(logger: logger);

            // Act
            IActionResult result = await fundingService.GetFundingStreamById(request);

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

            logger
            .Received(1)
            .Error(Arg.Is("No funding stream Id was provided to GetFundingStreamById"));
        }
        public async Task GetFundingStream_WhenFundingStreamNotFound_ShouldReturnNotFoundResult()
        {
            // Arrange
            string fundingStreamId = "unknown";

            IMapper mapper = Substitute.For <IMapper>();

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

            mockFundingService
            .GetFundingStreamById(Arg.Is(fundingStreamId))
            .Returns(new NotFoundResult());

            FundingStreamService fundingStreamService = new FundingStreamService(mockFundingService, mapper);

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

            // Assert
            result
            .Should()
            .BeOfType <NotFoundResult>();
        }
Ejemplo n.º 7
0
        public async Task GetFundingStreamById_GivenFundingStreamnWasFound_ReturnsSuccess()
        {
            // Arrange
            IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues>
            {
                { "fundingStreamId", new StringValues(FundingStreamId) }
            });

            HttpRequest request = Substitute.For <HttpRequest>();

            request
            .Query
            .Returns(queryStringValues);

            ILogger logger = CreateLogger();

            FundingStream fundingStream = new FundingStream
            {
                Id = FundingStreamId
            };

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetFundingStreamById(Arg.Is(FundingStreamId))
            .Returns(fundingStream);

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

            // Act
            IActionResult result = await fundingService.GetFundingStreamById(request);

            // Assert
            result
            .Should()
            .BeOfType <OkObjectResult>();
        }
Ejemplo n.º 8
0
        public async Task GetFundingStreamById_GivenFundingStreamnWasNotFound_ReturnsNotFound()
        {
            // Arrange
            IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues>
            {
                { "fundingStreamId", new StringValues(FundingStreamId) }
            });

            HttpRequest request = Substitute.For <HttpRequest>();

            request
            .Query
            .Returns(queryStringValues);

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetFundingStreamById(Arg.Is(FundingStreamId))
            .Returns((FundingStream)null);

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

            // Act
            IActionResult result = await fundingService.GetFundingStreamById(request);

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

            logger
            .Received(1)
            .Error(Arg.Is($"No funding stream was found for funding stream id : {FundingStreamId}"));
        }
 public async Task <IActionResult> RunGetFundingStreamById()
 {
     return(await _fundingService.GetFundingStreamById(ControllerContext.HttpContext.Request));
 }