Esempio n. 1
0
        public async Task GetFundingConfigurationsByFundingStreamId_GivenFundingConfigurationsInCache_ReturnsFromCache()
        {
            // Arrange
            List <FundingConfiguration> fundingConfigs = new List <FundingConfiguration>
            {
                new FundingConfiguration()
            };

            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider
            .GetAsync <List <FundingConfiguration> >(Arg.Is(fundingConfigurationsCacheKey))
            .Returns(fundingConfigs);

            FundingConfigurationService fundingConfigurationsService = CreateFundingConfigurationService(cacheProvider: cacheProvider);

            // Act
            IActionResult result = await fundingConfigurationsService.GetFundingConfigurationsByFundingStreamId(fundingStreamId);

            // Assert
            result
            .Should()
            .BeOfType <OkObjectResult>()
            .Which
            .Value
            .Should()
            .Be(fundingConfigs);
        }
Esempio n. 2
0
        public async Task GetFundingConfigurationsByFundingStreamId_GivenFundingConfigurationsNotInCacheAndNotInDatabase_ReturnsNotFound()
        {
            // Arrange
            List <FundingConfiguration> fundingConfigs = null;

            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider
            .GetAsync <List <FundingConfiguration> >(Arg.Is(fundingConfigurationsCacheKey))
            .Returns(fundingConfigs);

            IPolicyRepository policyRepository = CreatePolicyRepository();

            policyRepository
            .GetFundingConfigurationsByFundingStreamId(Arg.Is(fundingStreamId))
            .Returns(fundingConfigs);

            FundingConfigurationService fundingConfigurationsService =
                CreateFundingConfigurationService(cacheProvider: cacheProvider, policyRepository: policyRepository);

            // Act
            IActionResult result = await fundingConfigurationsService.GetFundingConfigurationsByFundingStreamId(fundingStreamId);

            // Assert
            result
            .Should()
            .BeOfType <NotFoundResult>();
        }
Esempio n. 3
0
        public async Task GetFundingConfigurationsByFundingStreamId_GivenEmptyFundingStreamId_ReturnsBadRequestRequest()
        {
            // Arrange
            string fundingStreamId = string.Empty;

            ILogger logger = CreateLogger();

            FundingConfigurationService fundingConfigurationsService = CreateFundingConfigurationService(logger: logger);

            // Act
            IActionResult result = await fundingConfigurationsService.GetFundingConfigurationsByFundingStreamId(fundingStreamId);

            // Assert
            result
            .Should()
            .BeOfType <BadRequestObjectResult>()
            .Which
            .Value
            .Should()
            .Be("Null or empty funding stream Id provided");

            logger
            .Received(1)
            .Error(Arg.Is("No funding stream Id was provided to GetFundingConfigurationsByFundingStreamId"));
        }
Esempio n. 4
0
        public async Task GetFundingConfigurationsByFundingStreamId_GivenFundingConfigurationsNotInCacheBuInDatabase_ReturnsOKSetsInCache()
        {
            // Arrange
            List <FundingConfiguration> fundingConfigs = new List <FundingConfiguration>
            {
                new FundingConfiguration()
            };

            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider
            .GetAsync <List <FundingConfiguration> >(Arg.Is(fundingConfigurationsCacheKey))
            .Returns((List <FundingConfiguration>)null);

            IPolicyRepository policyRepository = CreatePolicyRepository();

            policyRepository
            .GetFundingConfigurationsByFundingStreamId(Arg.Is(fundingStreamId))
            .Returns(fundingConfigs);

            FundingConfigurationService fundingConfigurationsService =
                CreateFundingConfigurationService(cacheProvider: cacheProvider, policyRepository: policyRepository);

            // Act
            IActionResult result = await fundingConfigurationsService.GetFundingConfigurationsByFundingStreamId(fundingStreamId);

            // Assert
            result
            .Should()
            .BeOfType <OkObjectResult>()
            .Which
            .Value
            .Should()
            .Be(fundingConfigs);

            await
            cacheProvider
            .Received(1)
            .SetAsync(Arg.Is(fundingConfigurationsCacheKey), Arg.Any <List <FundingConfiguration> >());
        }