예제 #1
0
        public async Task OnGetAsync_WhenGettingProviderResultsIsSuccess_CalculationDetails_Populated()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            IMapper mapper = CreateMapper();

            ILogger logger = CreateLogger();

            IFeatureToggle featureToggle = Substitute.For <IFeatureToggle>();

            ProviderCalcsResultsPageModel provideCalcPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger, featureToggle);

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

            Provider provider = CreateProvider();

            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 provideCalcPageModel.OnGetAsync("2", "1617", "2");

            // Assert
            provideCalcPageModel.CalculationErrorCount.Equals(1);

            provideCalcPageModel.ViewModel.CalculationItems.Should().HaveSameCount(calResult);

            provideCalcPageModel.ViewModel.CalculationItems.First().CalculationType.Should().Be(Clients.SpecsClient.Models.CalculationSpecificationType.Number);

            provideCalcPageModel.ViewModel.CalculationItems.Last().CalculationType.Should().Be(Clients.SpecsClient.Models.CalculationSpecificationType.Funding);
        }
예제 #2
0
        public async Task OnGetAsync_ReturnsValidFundingPeriodAsync()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            IMapper mapper = CreateMapper();

            ILogger logger = CreateLogger();

            IFeatureToggle featureToggle = Substitute.For <IFeatureToggle>();

            ProviderCalcsResultsPageModel provideCalcPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger, featureToggle);

            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 provideCalcPageModel.OnGetAsync("2", "1617", "2");

            // Assert
            result.Should()
            .BeOfType <PageResult>()
            .Which.Should().NotBeNull("Action result was null");

            provideCalcPageModel.FundingPeriods.Should().NotBeNull();
        }
예제 #3
0
        public void OnGetAsync_WhenGettingProviderResponseIsNotSuccess_ThrowsException()
        {
            // Arrange
            IResultsApiClient resultsApiClient = CreateApiClient();

            ISpecsApiClient specsClient = CreateSpecsApiClient();

            IMapper mapper = CreateMapper();

            ILogger logger = CreateLogger();

            IFeatureToggle featureToggle = Substitute.For <IFeatureToggle>();

            ProviderCalcsResultsPageModel provideCalcPageModel = CreatePageModel(resultsApiClient, specsClient, mapper, logger, featureToggle);

            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 provideCalcPageModel.OnGetAsync("2", "1617", "2");

            // Assert
            test
            .Should()
            .ThrowExactly <System.InvalidOperationException>().WithMessage("Unable to retreive Provider information: Status Code = NotFound");
        }
예제 #4
0
        public async Task OnGetAsync_WhenGettingProviderResultsIsNotSuccess_AllocationDetails_NotPopulated()
        {
            // 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 = CreateProvider();

            IEnumerable <string> specSummary = GetSpecificationsWithResults();

            IList <CalculationResultItem> calResult = GetCalcResults();

            IList <AllocationLineResultItem> allocResult = GetAllocationResults();

            ProviderResults providerResults = null;

            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.NoContent, 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>()));

            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.ViewModel.AllocationLineItems.Should().HaveCount(0);
            providerAllocPageModel.ViewModel.CalculationItems.Should().HaveCount(0);
        }
예제 #5
0
        public async Task OnGetAsync_WhenGettingProviderResponseIsSuccess_PopulatesProviderDetails()
        {
            // 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 = CreateProvider();

            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
            providerAllocPageModel.ViewModel.Should().NotBeNull();
            providerAllocPageModel.ViewModel.Upin.Should().Be(234234);
            providerAllocPageModel.ViewModel.Ukprn.Should().Be(345345);
            providerAllocPageModel.ViewModel.Urn.Should().Be(2234);
            providerAllocPageModel.ViewModel.ProviderType.Should().Be("Academy");
        }
 public Task <IEnumerable <ProviderCalculationResult> > GetCalculationResultsBySpecificationAndProvider(string specificationId, string providerId)
 {
     return(Task.FromResult(
                new List <ProviderCalculationResult>
     {
         new ProviderCalculationResult
         {
             ProviderId = providerId,
             Results = ProviderResults.ContainsKey(providerId) ? ProviderResults[providerId] : Results
         }
     }.AsEnumerable()));
 }
예제 #7
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");
        }
예제 #8
0
        public void OnGetAsync_WhenGettingSpecificationSummaryIsNotSuccess_ThrowsError()
        {
            // 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 = CreateProvider();

            IList <string> specSummary = null;

            IList <CalculationResultItem> calResult = GetCalcResults();

            IList <AllocationLineResultItem> allocResult = GetAllocationResults();

            ProviderResults providerResults = null;

            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.NoContent, 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>();
        }