public async Task GetSpecificationByName_GivenSpecificationWasNotFound_ReturnsNotFoundt()
        {
            //Arrange
            IEnumerable <Specification> specs = Enumerable.Empty <Specification>();

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >())
            .Returns(specs);

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationByName(SpecificationName);

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

            logger
            .Received(1)
            .Information(Arg.Is($"Specification was not found for name: {SpecificationName}"));
        }
Exemplo n.º 2
0
        public async Task GetSpecificationsSelectedForFundingByPeriod_GivenSpecificationWasNotFound_ReturnsNotFound()
        {
            //Arrange
            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >())
            .Returns((Enumerable.Empty <Specification>()));

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationsSelectedForFundingByPeriod(FundingPeriodId);

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

            logger
            .Received(1)
            .Information(Arg.Is($"Specification was not found for funding period: {FundingPeriodId}"));
        }
Exemplo n.º 3
0
        public async Task GetSpecificationsSelectedForFundingByPeriod_GivenSpecificationWasFound_ReturnsSpecification()
        {
            //Arrange

            SpecificationVersion sv1 = new SpecificationVersion {
                SpecificationId = "spec1", FundingPeriod = new Reference {
                    Id = "18/19", Name = "18/19"
                }
            };
            SpecificationVersion sv2 = new SpecificationVersion {
                SpecificationId = "spec2", FundingPeriod = new Reference {
                    Id = "17/18", Name = "17/18"
                }
            };

            Specification spec1 = new Specification {
                Id = "spec1", IsSelectedForFunding = true, Current = sv1
            };
            Specification spec2 = new Specification {
                Id = "spec2", IsSelectedForFunding = true, Current = sv2
            };

            IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues>
            {
                { "fundingPeriodId", new StringValues(FundingPeriodId) }
            });

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

            request
            .Query
            .Returns(queryStringValues);

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <Specification, bool> > >())
            .Returns(new[] { spec1 });

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationsSelectedForFundingByPeriod(request);

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

            OkObjectResult okObjectResult = result as OkObjectResult;

            IEnumerable <SpecificationSummary> summaries = okObjectResult.Value as IEnumerable <SpecificationSummary>;

            summaries
            .Count()
            .Should()
            .Be(1);
        }
        public async Task GetSpecificationByFundingPeriodId_GivenNoSpecificationsReturned_ReturnsSuccess()
        {
            //Arrange
            IEnumerable <Specification> specs = Enumerable.Empty <Specification>();

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >())
            .Returns(specs);

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationsByFundingPeriodId(FundingPeriodId);

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

            IEnumerable <SpecificationSummary> objContent = (IEnumerable <SpecificationSummary>)((OkObjectResult)result).Value;

            objContent
            .Count()
            .Should()
            .Be(0);
        }
Exemplo n.º 5
0
        public async Task GetSpecificationsWithProviderVersionUpdatesAsUseLatest_GivenSpecificationWasNotFound_ReturnsNotFound()
        {
            //Arrange
            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >())
            .Returns((Enumerable.Empty <Specification>()));

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationsWithProviderVersionUpdatesAsUseLatest();

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

            logger
            .Received(1)
            .Information(Arg.Is($"Specifications was not found with CoreProviderVersionUpdates as UseLatest"));
        }
Exemplo n.º 6
0
        public async Task GetSpecificationsSelectedForFundingByPeriod_GivenSpecificationWasNotFound_ReturnsNotFound()
        {
            //Arrange
            SpecificationVersion sv1 = new SpecificationVersion {
                SpecificationId = "spec1", FundingPeriod = new Reference {
                    Id = "18/19", Name = "18/19"
                }
            };
            SpecificationVersion sv2 = new SpecificationVersion {
                SpecificationId = "spec2", FundingPeriod = new Reference {
                    Id = "17/18", Name = "17/18"
                }
            };

            Specification spec1 = new Specification {
                Id = "spec1", IsSelectedForFunding = true, Current = sv1
            };
            Specification spec2 = new Specification {
                Id = "spec2", IsSelectedForFunding = true, Current = sv2
            };

            IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues>
            {
                { "fundingPeriodId", new StringValues(FundingPeriodId) }
            });

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

            request
            .Query
            .Returns(queryStringValues);

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <Specification, bool> > >())
            .Returns((Enumerable.Empty <Specification>()));

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationsSelectedForFundingByPeriod(request);

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

            logger
            .Received(1)
            .Information(Arg.Is($"Specification was not found for funding period: {FundingPeriodId}"));
        }
Exemplo n.º 7
0
        public async Task GetSpecificationByFundingPeriodId_GivenSpecificationsReturned_ReturnsSuccess()
        {
            //Arrange
            IEnumerable <Specification> specs = new[]
            {
                new Specification(),
                new Specification()
            };

            IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues>
            {
                { "fundingPeriodId", new StringValues(FundingPeriodId) }
            });

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

            request
            .Query
            .Returns(queryStringValues);

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <Specification, bool> > >())
            .Returns(specs);

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationsByFundingPeriodId(request);

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

            IEnumerable <SpecificationSummary> objContent = (IEnumerable <SpecificationSummary>)((OkObjectResult)result).Value;

            objContent
            .Count()
            .Should()
            .Be(2);

            logger
            .Received(1)
            .Information(Arg.Is($"Found {specs.Count()} specifications for academic year with id {FundingPeriodId}"));
        }
Exemplo n.º 8
0
        public async Task ReturnsDistinctFundingPeriods_GivenFundingStreamIdForAnSpecWithFundingPeriodAndMatchingIdAndPeriod()
        {
            specificationsRepository.GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >())
            .Returns(new[]
            {
                _specWithFundingPeriodAndFundingStream,
            });
            SpecificationsService service = CreateService(
                specificationsRepository: specificationsRepository,
                policiesApiClient: policiesApiClient,
                mapper: mapper);

            OkObjectResult fundingPeriodsResult =
                await service.GetFundingPeriodsByFundingStreamIdsForSelectedSpecifications(FundingStreamIdForExpectedFundingPeriod) as OkObjectResult;

            await specificationsRepository
            .Received(1)
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >());

            IEnumerable <Reference> fundingPeriod = fundingPeriodsResult.Value as IEnumerable <Reference>;

            fundingPeriod.Count().Should().Be(1);
            fundingPeriod.First().Id.Should().Be(ExpectedFundingPeriodId);
        }
Exemplo n.º 9
0
        public async Task ReturnsOkObjectResultWithNoFundingStreamIds_GivenNoSpecificationWithSelectedForFunding()
        {
            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository.GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >())
            .Returns(new[] { _specNotSelectedForFunding });
            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository);

            OkObjectResult fundingStreamIdResult =
                await service.GetFundingStreamIdsForSelectedFundingSpecifications() as OkObjectResult;

            IEnumerable <string> fundingStreamIds = fundingStreamIdResult.Value as IEnumerable <string>;

            fundingStreamIdResult.Should().BeOfType <OkObjectResult>();
            fundingStreamIds.Count().Should().Be(0);
        }
        public async Task GetSpecificationByName_GivenSpecificationReturned_ReturnsSuccess()
        {
            //Arrange
            IEnumerable <Specification> specs = new[]
            {
                new Specification()
            };

            IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues>
            {
                { "specificationName", new StringValues(SpecificationName) }
            });

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

            request
            .Query
            .Returns(queryStringValues);

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <Specification, bool> > >())
            .Returns(specs);

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationByName(request);

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

            Specification objContent = (Specification)((OkObjectResult)result).Value;

            objContent
            .Should()
            .NotBeNull();

            logger
            .Received(1)
            .Information(Arg.Is($"Specification found for name: {SpecificationName}"));
        }
Exemplo n.º 11
0
        public async Task ReturnsDistinctFundingStreamIds_GivenValidSelectedSpecWithFundingStreams()
        {
            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository.GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >())
            .Returns(new[] { _specSelectedForFunding, _specNotSelectedForFunding });
            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository);

            OkObjectResult fundingStreamIdResult =
                await service.GetFundingStreamIdsForSelectedFundingSpecifications() as OkObjectResult;

            IEnumerable <string> fundingStreamIds = fundingStreamIdResult.Value as IEnumerable <string>;

            fundingStreamIds.Count().Should().Be(2);
            fundingStreamIds.First().Should().Be("PSG");
            fundingStreamIds.Skip(1).First().Should().Be("PSG2");
        }
Exemplo n.º 12
0
        public async Task GetSpecificationsSelectedForFundingByPeriod_GivenSpecificationWasFound_ReturnsSpecification()
        {
            //Arrange

            SpecificationVersion sv1 = new SpecificationVersion {
                SpecificationId = "spec1", FundingPeriod = new Reference {
                    Id = "18/19", Name = "18/19"
                }
            };

            Specification spec1 = new Specification {
                Id = "spec1", IsSelectedForFunding = true, Current = sv1
            };

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >())
            .Returns(new[] { spec1 });

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationsSelectedForFundingByPeriod(FundingPeriodId);

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

            OkObjectResult okObjectResult = result as OkObjectResult;

            IEnumerable <SpecificationSummary> summaries = okObjectResult.Value as IEnumerable <SpecificationSummary>;

            summaries
            .Count()
            .Should()
            .Be(1);
        }
        public async Task GetSpecificationByFundingPeriodId_GivenSpecificationsReturned_ReturnsSuccess()
        {
            //Arrange
            IEnumerable <Specification> specs = new[]
            {
                new Specification(),
                new Specification()
            };

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >())
            .Returns(specs);

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationsByFundingPeriodId(FundingPeriodId);

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

            IEnumerable <SpecificationSummary> objContent = (IEnumerable <SpecificationSummary>)((OkObjectResult)result).Value;

            objContent
            .Count()
            .Should()
            .Be(2);

            logger
            .Received(1)
            .Information(Arg.Is($"Found {specs.Count()} specifications for academic year with id {FundingPeriodId}"));
        }
        public async Task GetSpecificationByName_GivenSpecificationReturned_ReturnsSuccess()
        {
            //Arrange
            IEnumerable <Specification> specs = new[]
            {
                new Specification()
            };

            ILogger logger = CreateLogger();

            ISpecificationsRepository specificationsRepository = CreateSpecificationsRepository();

            specificationsRepository
            .GetSpecificationsByQuery(Arg.Any <Expression <Func <DocumentEntity <Specification>, bool> > >())
            .Returns(specs);

            SpecificationsService service = CreateService(specificationsRepository: specificationsRepository, logs: logger);

            //Act
            IActionResult result = await service.GetSpecificationByName(SpecificationName);

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

            Specification objContent = (Specification)((OkObjectResult)result).Value;

            objContent
            .Should()
            .NotBeNull();

            logger
            .Received(1)
            .Information(Arg.Is($"Specification found for name: {SpecificationName}"));
        }