Example #1
0
        public async Task OnGetAsync_ReturnsValidAcademicYearAsync()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            IMapper mapper = CreateMapper();

            ILogger logger = CreateLogger();

            ProviderAllocationLinePageModel providerAllocPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger);

            Provider provider = CreateProvider();

            IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") };

            IEnumerable <string> specSummary = GetSpecificationsWithResults();

            IList <CalculationResultItem> calResult = GetCalcResults();

            IList <AllocationLineResultItem> allocResult = GetAllocationResults();

            ProviderResults providerResults = new ProviderResults()
            {
                AllocationResults  = allocResult,
                CalculationResults = calResult
            };

            resultsApiClient.GetProviderByProviderId(Arg.Any <string>())
            .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider));

            specsClient.GetFundingPeriods()
            .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods));

            resultsApiClient.GetProviderResults(Arg.Is("2"), Arg.Is("2"))
            .Returns(new ApiResponse <ProviderResults>(HttpStatusCode.OK, providerResults));

            resultsApiClient.GetSpecificationIdsForProvider("2")
            .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary));

            specsClient
            .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >())
            .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>()));

            // Act
            IActionResult result = await providerAllocPageModel.OnGetAsync("2", "1617", "2");

            // Assert
            PageResult pageResult = result as PageResult;

            pageResult.Should().NotBeNull();

            providerAllocPageModel.FundingPeriods.Should().NotBeNull();
        }
Example #2
0
        public void OnGetAsync_WhenGettingProviderResponseIsNotSuccess_ThrowsException()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            IMapper mapper = CreateMapper();

            ILogger logger = CreateLogger();

            ProviderAllocationLinePageModel providerAllocPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger);

            IEnumerable <Reference> fundingPeriods = new[] { new Reference("1617", "2016-2017"), new Reference("1718", "2017-2018"), new Reference("1819", "2018-2019") };

            Provider provider = null;

            IEnumerable <string> specSummary = GetSpecificationsWithResults();

            IList <CalculationResultItem> calResult = GetCalcResults();

            IList <AllocationLineResultItem> allocResult = GetAllocationResults();

            ProviderResults providerResults = new ProviderResults()
            {
                AllocationResults  = allocResult,
                CalculationResults = calResult
            };

            resultsApiClient.GetProviderByProviderId(Arg.Any <string>())
            .Returns(new ApiResponse <Provider>(HttpStatusCode.NotFound, provider));

            specsClient.GetFundingPeriods()
            .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.OK, fundingPeriods));

            resultsApiClient.GetProviderResults(Arg.Is("2"), Arg.Is("2"))
            .Returns(new ApiResponse <ProviderResults>(HttpStatusCode.OK, providerResults));

            resultsApiClient.GetSpecificationIdsForProvider("2")
            .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary));

            specsClient
            .GetSpecificationSummaries(Arg.Any <IEnumerable <string> >())
            .Returns(new ApiResponse <IEnumerable <Clients.SpecsClient.Models.SpecificationSummary> >(HttpStatusCode.OK, new List <Clients.SpecsClient.Models.SpecificationSummary>()));

            // Act
            Func <Task> test = async() => await providerAllocPageModel.OnGetAsync("2", "1617", "2");

            // Assert
            test
            .Should()
            .ThrowExactly <System.InvalidOperationException>().WithMessage("Unable to retreive Provider information: Status Code = NotFound");
        }
Example #3
0
        public void OnGetAsync_ReturnsErrorWhenFundingPeriodResponseIsNull()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            IMapper mapper = CreateMapper();

            ILogger logger = CreateLogger();

            ProviderAllocationLinePageModel providerAllocPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger);

            Provider provider = CreateProvider();

            IEnumerable <Reference> academicYears = null;

            IEnumerable <string> specSummary = GetSpecificationsWithResults();

            IList <CalculationResultItem> calResult = GetCalcResults();

            IList <AllocationLineResultItem> allocResult = GetAllocationResults();

            resultsApiClient.GetProviderByProviderId(Arg.Any <string>())
            .Returns(new ApiResponse <Provider>(HttpStatusCode.OK, provider));

            ProviderResults providerResults = new ProviderResults()
            {
                AllocationResults  = allocResult,
                CalculationResults = calResult
            };

            NSubstitute.Core.ConfiguredCall fundingPeriods = specsClient.GetFundingPeriods()
                                                             .Returns(new ApiResponse <IEnumerable <Reference> >(HttpStatusCode.NotFound, academicYears));

            resultsApiClient.GetProviderResults(Arg.Is("2"), Arg.Is("2"))
            .Returns(new ApiResponse <ProviderResults>(HttpStatusCode.OK, providerResults));

            resultsApiClient.GetSpecificationIdsForProvider("2")
            .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, specSummary));


            // Act

            Func <Task> test = async() => await providerAllocPageModel.OnGetAsync("2", "1617", "2");

            // Assert
            test
            .Should()
            .ThrowExactly <System.InvalidOperationException>().WithMessage("Unable to retreive Periods: Status Code = NotFound");
        }
Example #4
0
        public void OnGetAsync_GivenNullProviderReturnsArgumentNullExceptionThrown()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            IMapper mapper = CreateMapper();

            ILogger logger = Substitute.For <ILogger>();

            ProviderAllocationLinePageModel providerAllocPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger);

            // Act - Assert
            Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await providerAllocPageModel.OnGetAsync(null, string.Empty, string.Empty));
        }