private static void AssertConfirmPublishApproveModel(IActionResult actionResult, int expectedNumProviders, int expectedNumAuthorities, int expectedNumProviderTypes, string expectedFundingPeriod, int expectedNumFundingStreams, decimal expectedTotalApproved) { OkObjectResult okResult = actionResult .Should() .BeOfType <OkObjectResult>() .Subject; ConfirmPublishApproveModel x = okResult.Value.Should().BeAssignableTo <ConfirmPublishApproveModel>().Subject; x.NumberOfProviders.Should().Be(expectedNumProviders, nameof(x.NumberOfProviders)); x.LocalAuthorities.Should().HaveCount(expectedNumAuthorities, nameof(x.LocalAuthorities)); x.ProviderTypes.Should().HaveCount(expectedNumProviderTypes, nameof(x.ProviderTypes)); x.FundingPeriod.Should().Be(expectedFundingPeriod, nameof(x.FundingPeriod)); x.FundingStreams.Should().HaveCount(expectedNumFundingStreams, nameof(x.FundingStreams)); x.TotalFundingApproved.Should().Be(expectedTotalApproved, nameof(x.TotalFundingApproved)); }
public async Task GetConfirmationDetailsForApprovePublishProviderResults_GivenPublishedResultsReturnsMultiple_ReturnsOkAndAllocationLinesCoalesced() { // Arrange IEnumerable <UpdatePublishedAllocationLineResultStatusProviderModel> Providers = new[] { new UpdatePublishedAllocationLineResultStatusProviderModel { ProviderId = "1" }, new UpdatePublishedAllocationLineResultStatusProviderModel { ProviderId = "2" } }; IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues> { { "specificationId", new StringValues(specificationId) }, }); UpdatePublishedAllocationLineResultStatusModel model = new UpdatePublishedAllocationLineResultStatusModel { Status = AllocationLineStatus.Held, Providers = Providers }; IEnumerable <PublishedProviderResult> publishedProviderResults = new List <PublishedProviderResult> { new PublishedProviderResult { FundingPeriod = new Models.Specs.Period { Name = "Period1" }, FundingStreamResult = new PublishedFundingStreamResult { FundingStream = new PublishedFundingStreamDefinition { Name = "Stream1" }, AllocationLineResult = new PublishedAllocationLineResult { AllocationLine = new PublishedAllocationLineDefinition { Name = "AllocLine1" }, Current = new PublishedAllocationLineResultVersion { Value = 12, Provider = new ProviderSummary { Id = "1", Authority = "B Auth", ProviderType = "B PType" } } } } }, new PublishedProviderResult { FundingPeriod = new Models.Specs.Period { Name = "Period1" }, FundingStreamResult = new PublishedFundingStreamResult { FundingStream = new PublishedFundingStreamDefinition { Name = "Stream1" }, AllocationLineResult = new PublishedAllocationLineResult { AllocationLine = new PublishedAllocationLineDefinition { Name = "AllocLine1" }, Current = new PublishedAllocationLineResultVersion { Value = 15, Provider = new ProviderSummary { Id = "2", Authority = "A Auth", ProviderType = "A PType" } } } } } }; string json = JsonConvert.SerializeObject(model); byte[] byteArray = Encoding.UTF8.GetBytes(json); MemoryStream stream = new MemoryStream(byteArray); HttpRequest request = Substitute.For <HttpRequest>(); request .Query .Returns(queryStringValues); request .Body .Returns(stream); IPublishedProviderResultsRepository resultsProviderRepository = CreatePublishedProviderResultsRepository(); resultsProviderRepository .GetPublishedProviderResultsForSpecificationAndStatus(Arg.Is(specificationId), Arg.Any <UpdatePublishedAllocationLineResultStatusModel>()) .Returns(publishedProviderResults); PublishedResultsService resultsService = CreateResultsService(publishedProviderResultsRepository: resultsProviderRepository); // Act IActionResult actionResult = await resultsService.GetConfirmationDetailsForApprovePublishProviderResults(request); // Assert OkObjectResult okResult = actionResult.Should().BeOfType <OkObjectResult>().Subject; ConfirmPublishApproveModel confDetalis = okResult.Value.Should().BeAssignableTo <ConfirmPublishApproveModel>().Subject; confDetalis.FundingStreams.Should().HaveCount(1, "Funding Stream"); confDetalis.FundingStreams.First().AllocationLines.Should().HaveCount(1, "Allocation Lines"); }
public async Task GetConfirmationDetailsForApprovePublishProviderResults_GivenNoPublishedResultsReturns_ReturnsZeroResults() { //arrange IEnumerable <UpdatePublishedAllocationLineResultStatusProviderModel> Providers = new[] { new UpdatePublishedAllocationLineResultStatusProviderModel { ProviderId = "1234" } }; IQueryCollection queryStringValues = new QueryCollection(new Dictionary <string, StringValues> { { "specificationId", new StringValues(specificationId) }, }); UpdatePublishedAllocationLineResultStatusModel model = new UpdatePublishedAllocationLineResultStatusModel { Providers = Providers }; string json = JsonConvert.SerializeObject(model); byte[] byteArray = Encoding.UTF8.GetBytes(json); MemoryStream stream = new MemoryStream(byteArray); HttpRequest request = Substitute.For <HttpRequest>(); request .Query .Returns(queryStringValues); request .Body .Returns(stream); IPublishedProviderResultsRepository resultsProviderRepository = CreatePublishedProviderResultsRepository(); resultsProviderRepository .GetPublishedProviderResultsForSpecificationId(Arg.Is(specificationId)) .Returns(Enumerable.Empty <PublishedProviderResult>()); PublishedResultsService resultsService = CreateResultsService(publishedProviderResultsRepository: resultsProviderRepository); //Act IActionResult actionResult = await resultsService.GetConfirmationDetailsForApprovePublishProviderResults(request); //Arrange OkObjectResult okResult = actionResult .Should() .BeOfType <OkObjectResult>() .Subject; ConfirmPublishApproveModel x = okResult.Value.Should().BeAssignableTo <ConfirmPublishApproveModel>().Subject; x.NumberOfProviders.Should().Be(0, nameof(x.NumberOfProviders)); x.LocalAuthorities.Should().HaveCount(0, nameof(x.LocalAuthorities)); x.ProviderTypes.Should().HaveCount(0, nameof(x.ProviderTypes)); x.FundingPeriod.Should().BeNullOrEmpty("FundingPeriod should be blank"); x.FundingStreams.Should().BeEmpty(nameof(x.FundingStreams)); x.TotalFundingApproved.Should().Be(0, "TotalFundingApproved should be zero as there are no results"); }