예제 #1
0
        AllocationWithHistoryModel CreateAllocationWithHistoryModel(PublishedProviderResultWithHistory publishedProviderResultWithHistory)
        {
            AllocationWithHistoryModel allocationModel = new AllocationWithHistoryModel(CreateAllocation(publishedProviderResultWithHistory.PublishedProviderResult))
            {
                History = new Collection <AllocationHistoryModel>(publishedProviderResultWithHistory.History?.Select(m =>
                                                                                                                     new AllocationHistoryModel
                {
                    AllocationAmount        = m.Value,
                    AllocationVersionNumber = m.Version,
                    Status  = m.Status.ToString(),
                    Date    = m.Date,
                    Author  = m.Author.Name,
                    Comment = m.Comment,
                    AllocationMajorVersion = m.Major,
                    AllocationMinorVersion = m.Minor,
                }
                                                                                                                     ).OrderByDescending(m => m.Date).ToArraySafe())
            };

            return(allocationModel);
        }
        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);
        }
        public object GetExamples()
        {
            AllocationWithHistoryModel allocation = JsonConvert.DeserializeObject<AllocationWithHistoryModel>(Properties.Resources.V1_Sample_Allocation_With_History);

            return allocation;
        }