public async Task GetAllocationAndHistoryByAllocationResultId_GivenResultFoundButNoHeaders_ReturnsBadRequest()
        {
            //Arrange
            string allocationResultId = "12345";

            IHeaderDictionary headerDictionary = new HeaderDictionary();

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

            request
            .Headers
            .Returns(headerDictionary);

            PublishedProviderResultWithHistory publishedProviderResult = CreatePublishedProviderResultWithHistory();

            IPublishedResultsService resultsService = CreateResultsService();

            resultsService
            .GetPublishedProviderResultWithHistoryByAllocationResultId(Arg.Is(allocationResultId))
            .Returns(publishedProviderResult);

            AllocationsService service = CreateService(resultsService);

            //Act
            IActionResult result = await service.GetAllocationAndHistoryByAllocationResultId(allocationResultId, request);

            //Assert
            result
            .Should()
            .BeOfType <BadRequestResult>();
        }
        public async Task GetAllocationAndHistoryByAllocationResultId_GivenNullResultFound_ReturnsNotFound()
        {
            //Arrange
            string allocationResultId = "12345";

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

            IPublishedResultsService resultsService = CreateResultsService();

            resultsService
            .GetPublishedProviderResultWithHistoryByAllocationResultId(Arg.Is(allocationResultId))
            .Returns((PublishedProviderResultWithHistory)null);

            AllocationsService service = CreateService(resultsService);

            //Act
            IActionResult result = await service.GetAllocationAndHistoryByAllocationResultId(allocationResultId, request);

            //Assert
            result
            .Should()
            .BeOfType <NotFoundResult>();
        }
        public async Task GetAllocationAndHistoryByAllocationResultId_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);

            PublishedProviderResultWithHistory publishedProviderResult = CreatePublishedProviderResultWithHistory();

            foreach (PublishedAllocationLineResultVersion historyItem in publishedProviderResult.History)
            {
                historyItem.Major = 1;
                historyItem.Minor = 0;
            }

            IPublishedResultsService resultsService = CreateResultsService();

            resultsService
            .GetPublishedProviderResultWithHistoryByAllocationResultId(Arg.Is(allocationResultId))
            .Returns(publishedProviderResult);

            AllocationsService service = CreateService(resultsService);

            //Act
            IActionResult result = await service.GetAllocationAndHistoryByAllocationResultId(allocationResultId, request);

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

            ContentResult contentResult = result as ContentResult;

            AllocationWithHistoryModel allocationModel = JsonConvert.DeserializeObject <AllocationWithHistoryModel>(contentResult.Content);

            string id = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{publishedProviderResult.PublishedProviderResult.SpecificationId}{publishedProviderResult.PublishedProviderResult.ProviderId}{publishedProviderResult.PublishedProviderResult.FundingStreamResult.AllocationLineResult.AllocationLine.Id}"));

            allocationModel
            .Should()
            .NotBeNull();

            allocationModel.AllocationResultId.Should().Be(id);
            allocationModel.AllocationVersionNumber.Should().Be(1);
            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.Length.Should().Be(1);
            allocationModel.History.Length.Should().Be(2);
            allocationModel.History[0].AllocationVersionNumber.Should().Be(2);
            allocationModel.History[0].AllocationAmount.Should().Be(40);
            allocationModel.History[0].Status.Should().Be("Approved");
            allocationModel.History[0].AllocationVersion.Should().Be(1.0M);
            allocationModel.History[1].AllocationVersionNumber.Should().Be(1);
            allocationModel.History[1].AllocationAmount.Should().Be(50);
            allocationModel.History[1].Status.Should().Be("Held");
            allocationModel.History[1].AllocationVersion.Should().Be(1.0M);
        }