public void GetAllocationByAllocationResultId_GivenResultFoundButNoHeaders_ReturnsBadRequest() { //Arrange string allocationResultId = "12345"; IHeaderDictionary headerDictionary = new HeaderDictionary(); HttpRequest request = Substitute.For <HttpRequest>(); request .Headers .Returns(headerDictionary); PublishedProviderResult publishedProviderResult = CreatePublishedProviderResult(); IPublishedResultsService resultsService = CreateResultsService(); resultsService .GetPublishedProviderResultByVersionId(Arg.Is(allocationResultId)) .Returns(publishedProviderResult); AllocationsService service = CreateService(resultsService); //Act IActionResult result = service.GetAllocationByAllocationResultId(allocationResultId, request); //Assert result .Should() .BeOfType <BadRequestResult>(); }
public void GetAllocationByAllocationResultId_GivenResultFound_ReturnsContentResult() { //Arrange string allocationResultId = "12345"; IHeaderDictionary headerDictionary = new HeaderDictionary(); headerDictionary.Add("Accept", new StringValues("application/json")); HttpRequest request = Substitute.For <HttpRequest>(); request .Headers .Returns(headerDictionary); PublishedProviderResult publishedProviderResult = CreatePublishedProviderResult(); publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.FeedIndexId = allocationResultId; IPublishedResultsService resultsService = CreateResultsService(); resultsService .GetPublishedProviderResultByVersionId(Arg.Is(allocationResultId)) .Returns(publishedProviderResult); AllocationsService service = CreateService(resultsService); //Act IActionResult result = service.GetAllocationByAllocationResultId(allocationResultId, request); //Assert result .Should() .BeOfType <ContentResult>(); ContentResult contentResult = result as ContentResult; AllocationModel allocationModel = JsonConvert.DeserializeObject <AllocationModel>(contentResult.Content); allocationModel .Should() .NotBeNull(); allocationModel.AllocationResultId.Should().Be(allocationResultId); allocationModel.AllocationStatus.Should().Be("Published"); allocationModel.AllocationAmount.Should().Be(50); allocationModel.FundingStream.Id.Should().Be("fs-1"); allocationModel.FundingStream.Name.Should().Be("funding stream 1"); allocationModel.Period.Id.Should().Be("Ay12345"); allocationModel.Provider.UkPrn.Should().Be("1111"); allocationModel.Provider.Upin.Should().Be("2222"); allocationModel.Provider.OpenDate.Should().NotBeNull(); allocationModel.AllocationLine.Id.Should().Be("AAAAA"); allocationModel.AllocationLine.Name.Should().Be("test allocation line 1"); allocationModel.ProfilePeriods.Should().HaveCount(1); AssertProviderVariationValuesNotSet(allocationModel.Provider.ProviderVariation); }
public void GetAllocationByAllocationResultId_GivenMajorMinorFeatureToggleOn_ReturnsMajorMinorVersions() { //Arrange string allocationResultId = "12345"; IHeaderDictionary headerDictionary = new HeaderDictionary { { "Accept", new StringValues("application/json") } }; HttpRequest request = Substitute.For <HttpRequest>(); request .Headers .Returns(headerDictionary); PublishedProviderResult publishedProviderResult = CreatePublishedProviderResult(); IPublishedResultsService resultsService = CreateResultsService(); resultsService .GetPublishedProviderResultByVersionId(Arg.Is(allocationResultId)) .Returns(publishedProviderResult); AllocationsService service = CreateService(resultsService); //Act IActionResult result = service.GetAllocationByAllocationResultId(allocationResultId, request); //Assert result .Should() .BeOfType <ContentResult>(); ContentResult contentResult = result as ContentResult; string id = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{publishedProviderResult.SpecificationId}{publishedProviderResult.ProviderId}{publishedProviderResult.FundingStreamResult.AllocationLineResult.AllocationLine.Id}")); AllocationModel allocationModel = JsonConvert.DeserializeObject <AllocationModel>(contentResult.Content); allocationModel .Should() .NotBeNull(); allocationModel.AllocationMajorVersion.Should().Be(1); allocationModel.AllocationMinorVersion.Should().Be(1); AssertProviderVariationValuesNotSet(allocationModel.Provider.ProviderVariation); }
public void GetAllocationByAllocationResultId_GivenNullResultFound_ReturnsNotFound() { //Arrange string allocationResultId = "12345"; HttpRequest request = Substitute.For <HttpRequest>(); IPublishedResultsService resultsService = CreateResultsService(); resultsService .GetPublishedProviderResultByAllocationResultId(Arg.Is(allocationResultId)) .Returns((PublishedProviderResult)null); AllocationsService service = CreateService(resultsService); //Act IActionResult result = service.GetAllocationByAllocationResultId(allocationResultId, request); //Assert result .Should() .BeOfType <NotFoundResult>(); }
public void GetAllocationByAllocationResultId_GivenResultHasVariation_ReturnsContentResult() { //Arrange string allocationResultId = "12345"; IHeaderDictionary headerDictionary = new HeaderDictionary(); headerDictionary.Add("Accept", new StringValues("application/json")); HttpRequest request = Substitute.For <HttpRequest>(); request .Headers .Returns(headerDictionary); PublishedProviderResult publishedProviderResult = CreatePublishedProviderResult(); publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.FeedIndexId = allocationResultId; publishedProviderResult.FundingStreamResult.AllocationLineResult.HasResultBeenVaried = true; publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.VariationReasons = new[] { VariationReason.LegalNameFieldUpdated, VariationReason.LACodeFieldUpdated }; publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.Successor = "provider3"; publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Predecessors = new[] { "provider1", "provider2" }; publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.ReasonEstablishmentOpened = "Fresh Start"; publishedProviderResult.FundingStreamResult.AllocationLineResult.Current.Provider.ReasonEstablishmentClosed = "Closure"; IPublishedResultsService resultsService = CreateResultsService(); resultsService .GetPublishedProviderResultByVersionId(Arg.Is(allocationResultId)) .Returns(publishedProviderResult); AllocationsService service = CreateService(resultsService); //Act IActionResult result = service.GetAllocationByAllocationResultId(allocationResultId, request); //Assert result .Should() .BeOfType <ContentResult>(); ContentResult contentResult = result as ContentResult; AllocationModel allocationModel = JsonConvert.DeserializeObject <AllocationModel>(contentResult.Content); allocationModel .Should() .NotBeNull(); allocationModel.AllocationResultId.Should().Be(allocationResultId); allocationModel.AllocationStatus.Should().Be("Published"); allocationModel.AllocationAmount.Should().Be(50); allocationModel.FundingStream.Id.Should().Be("fs-1"); allocationModel.FundingStream.Name.Should().Be("funding stream 1"); allocationModel.Period.Id.Should().Be("Ay12345"); allocationModel.Provider.UkPrn.Should().Be("1111"); allocationModel.Provider.Upin.Should().Be("2222"); allocationModel.Provider.OpenDate.Should().NotBeNull(); allocationModel.AllocationLine.Id.Should().Be("AAAAA"); allocationModel.AllocationLine.Name.Should().Be("test allocation line 1"); allocationModel.ProfilePeriods.Should().HaveCount(1); ProviderVariation providerVariationModel = allocationModel.Provider.ProviderVariation; providerVariationModel.Should().NotBeNull(); providerVariationModel.VariationReasons.Should().BeEquivalentTo("LegalNameFieldUpdated", "LACodeFieldUpdated"); providerVariationModel.Successors.First().Ukprn.Should().Be("provider3"); providerVariationModel.Predecessors.First().Ukprn.Should().Be("provider1"); providerVariationModel.Predecessors[1].Ukprn.Should().Be("provider2"); providerVariationModel.OpenReason.Should().Be("Fresh Start"); providerVariationModel.CloseReason.Should().Be("Closure"); }