Exemple #1
0
        public async Task GetPublishedProviderResultWithHistoryByAllocationResultId_GivenResultFoundButNoHistory_ResturnsNull()
        {
            //Arrange
            string allocationResultId = "12345";

            string query = $"select c from c where c.documentType = 'PublishedAllocationLineResultVersion' and c.deleted = false and c.content.entityId = '{allocationResultId}'";

            PublishedProviderResult publishedProviderResult = new PublishedProviderResult {
                ProviderId = "1111"
            };

            IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository();

            publishedProviderResultsRepository
            .GetPublishedProviderResultForIdInPublishedState(Arg.Is(allocationResultId))
            .Returns(publishedProviderResult);

            IVersionRepository <PublishedAllocationLineResultVersion> versionRepository = CreatePublishedProviderResultsVersionRepository();

            versionRepository
            .GetVersions(Arg.Is(query), Arg.Is("1111"))
            .Returns((IEnumerable <PublishedAllocationLineResultVersion>)null);

            PublishedResultsService service = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository, publishedProviderResultsVersionRepository: versionRepository);

            //Act
            PublishedProviderResultWithHistory result = await service.GetPublishedProviderResultWithHistoryByAllocationResultId(allocationResultId);

            //Assert
            result
            .Should()
            .BeNull();
        }
        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>();
        }
Exemple #3
0
        public async Task GetPublishedProviderResultWithHistoryByAllocationResultId_GivenResultAndHistory_ResturnsResult()
        {
            //Arrange
            string allocationResultId = "12345";

            PublishedProviderResult publishedProviderResult = new PublishedProviderResult
            {
                ProviderId          = "1111",
                FundingStreamResult = new PublishedFundingStreamResult
                {
                    AllocationLineResult = new PublishedAllocationLineResult {
                    }
                }
            };

            IEnumerable <PublishedAllocationLineResultVersion> history = new[]
            {
                new PublishedAllocationLineResultVersion(),
                new PublishedAllocationLineResultVersion(),
                new PublishedAllocationLineResultVersion()
            };

            IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository();

            publishedProviderResultsRepository
            .GetPublishedProviderResultForIdInPublishedState(Arg.Is(allocationResultId))
            .Returns(publishedProviderResult);

            IVersionRepository <PublishedAllocationLineResultVersion> versionRepository = CreatePublishedProviderResultsVersionRepository();

            versionRepository
            .GetVersions(Arg.Is(allocationResultId), Arg.Is("1111"))
            .Returns(history);

            PublishedResultsService service = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository, publishedProviderResultsVersionRepository: versionRepository);

            //Act
            PublishedProviderResultWithHistory result = await service.GetPublishedProviderResultWithHistoryByAllocationResultId(allocationResultId);

            //Assert
            result
            .Should()
            .NotBeNull();

            result
            .PublishedProviderResult
            .Should()
            .NotBeNull();

            result
            .History
            .Count()
            .Should()
            .Be(3);
        }
Exemple #4
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);
        }
Exemple #5
0
        public async Task GetPublishedProviderResultWithHistoryByAllocationResultId_GivenResultNotFound_ResturnsNull()
        {
            //Arrange
            string allocationResultId = "12345";

            IPublishedProviderResultsRepository publishedProviderResultsRepository = CreatePublishedProviderResultsRepository();

            publishedProviderResultsRepository
            .GetPublishedProviderResultForIdInPublishedState(Arg.Is(allocationResultId))
            .Returns((PublishedProviderResult)null);

            PublishedResultsService service = CreateResultsService(publishedProviderResultsRepository: publishedProviderResultsRepository);

            //Act
            PublishedProviderResultWithHistory result = await service.GetPublishedProviderResultWithHistoryByAllocationResultId(allocationResultId);

            //Assert
            result
            .Should()
            .BeNull();
        }
        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);
        }