예제 #1
0
        async public Task SaveFundingConfiguration_GivenValidConfigurationButFailedToSaveToDatabase_ReturnsStatusCode(string fundingStreamId, string fundingPeriodId)
        {
            //Arrange
            FundingStream fundingStream = new FundingStream
            {
                Id = fundingStreamId
            };

            FundingPeriod fundingPeriod = new FundingPeriod
            {
                Id = fundingPeriodId
            };

            ILogger logger = CreateLogger();

            HttpStatusCode statusCode = HttpStatusCode.BadRequest;

            IPolicyRepository policyRepository = CreatePolicyRepository();

            policyRepository
            .GetFundingStreamById(Arg.Is(fundingStreamId))
            .Returns(fundingStream);

            policyRepository
            .GetFundingPeriodById(Arg.Is(fundingPeriodId))
            .Returns(fundingPeriod);

            policyRepository
            .SaveFundingConfiguration(Arg.Is <FundingConfiguration>(x => x.FundingStreamId == fundingStreamId && x.FundingPeriodId == fundingPeriodId))
            .Returns(statusCode);

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

            FundingConfigurationViewModel fundingConfigurationViewModel = CreateConfigurationModel();

            //Act
            IActionResult result = await fundingConfigurationsService.SaveFundingConfiguration("Action", "Controller", fundingConfigurationViewModel, fundingStreamId, fundingPeriodId);

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

            InternalServerErrorResult statusCodeResult = (InternalServerErrorResult)result;

            statusCodeResult
            .StatusCode
            .Should()
            .Be(500);

            logger
            .Received(1)
            .Error(Arg.Is($"Failed to save configuration file for funding stream id: {fundingStreamId} and period id: {fundingPeriodId} to cosmos db with status 400"));
        }
예제 #2
0
        async public Task SaveFundingConfiguration_GivenValidConfiguration_ReturnsStatusCode(
            string fundingStreamId, string fundingPeriodId)
        {
            FundingStream fundingStream = NewFundingStream(_ => _.WithId(fundingStreamId));
            FundingPeriod fundingPeriod = NewFundingPeriod(_ => _.WithId(fundingPeriodId));

            ILogger logger = CreateLogger();

            HttpStatusCode statusCode = HttpStatusCode.OK;

            ICacheProvider cacheProvider = CreateCacheProvider();

            cacheProvider
            .RemoveAsync <List <FundingConfiguration> >($"{CacheKeys.FundingConfig}{fundingStreamId}")
            .Returns(Task.CompletedTask);

            cacheProvider
            .SetAsync(
                $"{CacheKeys.FundingConfig}{fundingStreamId}-{fundingPeriodId}",
                Arg.Is <FundingConfiguration>(_ => _.FundingStreamId == fundingStreamId && _.FundingPeriodId == fundingPeriodId))
            .Returns(Task.CompletedTask);

            IPolicyRepository policyRepository = CreatePolicyRepository();

            policyRepository
            .GetFundingStreamById(Arg.Is(fundingStreamId))
            .Returns(fundingStream);

            policyRepository
            .GetFundingPeriodById(Arg.Is(fundingPeriodId))
            .Returns(fundingPeriod);

            policyRepository
            .SaveFundingConfiguration(Arg.Is <FundingConfiguration>(x => x.FundingStreamId == fundingStreamId && x.FundingPeriodId == fundingPeriodId))
            .Returns(statusCode);

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

            FundingConfigurationViewModel fundingConfigurationViewModel = CreateConfigurationModel();

            //Act
            IActionResult result = await fundingConfigurationsService.SaveFundingConfiguration("Action", "Controller", fundingConfigurationViewModel, fundingStreamId, fundingPeriodId);

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

            await cacheProvider
            .Received(1)
            .SetAsync(
                $"{CacheKeys.FundingConfig}{fundingStreamId}-{fundingPeriodId}",
                Arg.Is <FundingConfiguration>(_ => _.FundingStreamId == fundingStreamId && _.FundingPeriodId == fundingPeriodId));

            await cacheProvider
            .Received(1)
            .RemoveAsync <List <FundingConfiguration> >($"{CacheKeys.FundingConfig}{fundingStreamId}");
        }