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>();
        }
Example #2
0
        public async Task GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId_CallsCorrectly(
            string providerId,
            string specificationId,
            string fundingStreamId)
        {
            IResultsService       resultsService       = Substitute.For <IResultsService>();
            IResultsSearchService resultsSearchService = Substitute.For <IResultsSearchService>();
            ICalculationProviderResultsSearchService calculationProviderResultsSearchService = Substitute.For <ICalculationProviderResultsSearchService>();
            IPublishedResultsService publishedResultsService = Substitute.For <IPublishedResultsService>();
            IProviderCalculationResultsSearchService providerCalculationsResultsSearchService = Substitute.For <IProviderCalculationResultsSearchService>();
            IFeatureToggle featureToggle = Substitute.For <IFeatureToggle>();
            IProviderCalculationResultsReIndexerService providerCalculationResultsReIndexerService = Substitute.For <IProviderCalculationResultsReIndexerService>();

            ResultsController controller = new ResultsController(
                resultsService,
                resultsSearchService,
                calculationProviderResultsSearchService,
                publishedResultsService,
                providerCalculationsResultsSearchService,
                featureToggle,
                providerCalculationResultsReIndexerService);

            await controller.GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId(providerId, specificationId, fundingStreamId);

            await publishedResultsService
            .Received(1)
            .GetPublishedProviderProfileForProviderIdAndSpecificationIdAndFundingStreamId(providerId, specificationId, fundingStreamId);

            //Moq has a .VerifyNoOtherCalls method which would be really useful here to confirm the others weren't called.
        }
Example #3
0
        public ResultsController(
            IResultsService resultsService,
            IResultsSearchService resultsSearchService,
            ICalculationProviderResultsSearchService calculationProviderResultsSearchService,
            IPublishedResultsService publishedResultsService,
            IProviderCalculationResultsSearchService providerCalculationResultsSearchService,
            IFeatureToggle featureToggle,
            IProviderCalculationResultsReIndexerService providerCalculationResultsReIndexerService)
        {
            Guard.ArgumentNotNull(resultsSearchService, nameof(resultsSearchService));
            Guard.ArgumentNotNull(resultsService, nameof(resultsService));
            Guard.ArgumentNotNull(calculationProviderResultsSearchService, nameof(calculationProviderResultsSearchService));
            Guard.ArgumentNotNull(publishedResultsService, nameof(publishedResultsService));
            Guard.ArgumentNotNull(providerCalculationResultsSearchService, nameof(providerCalculationResultsSearchService));
            Guard.ArgumentNotNull(featureToggle, nameof(featureToggle));
            Guard.ArgumentNotNull(providerCalculationResultsReIndexerService, nameof(providerCalculationResultsReIndexerService));

            _resultsSearchService = resultsSearchService;
            _calculationProviderResultsSearchService = calculationProviderResultsSearchService;
            _publishedResultsService = publishedResultsService;
            _resultsService          = resultsService;
            _providerCalculationResultsSearchService = providerCalculationResultsSearchService;
            _featureToggle = featureToggle;
            _providerCalculationResultsReIndexerService = providerCalculationResultsReIndexerService;
        }
Example #4
0
        public AllocationsService(IPublishedResultsService publishedResultsService, IFeatureToggle featureToggle)
        {
            Guard.ArgumentNotNull(publishedResultsService, nameof(publishedResultsService));
            Guard.ArgumentNotNull(featureToggle, nameof(featureToggle));

            _publishedResultsService = publishedResultsService;
            _featureToggle           = featureToggle;
        }
Example #5
0
        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);
        }
Example #6
0
        public OnFetchProviderProfileEvent(
            ILogger logger,
            IPublishedResultsService resultsService,
            ICorrelationIdProvider correlationIdProvider)
        {
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(resultsService, nameof(resultsService));
            Guard.ArgumentNotNull(correlationIdProvider, nameof(correlationIdProvider));

            _logger = logger;
            _correlationIdProvider = correlationIdProvider;
            _resultsService        = resultsService;
        }
Example #7
0
        public OnCreateInstructAllocationLineResultStatusUpdates(
            ILogger logger,
            IPublishedResultsService resultsService,
            ICorrelationIdProvider correlationIdProvider)
        {
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(resultsService, nameof(resultsService));
            Guard.ArgumentNotNull(correlationIdProvider, nameof(correlationIdProvider));

            _logger = logger;
            _correlationIdProvider = correlationIdProvider;
            _resultsService        = resultsService;
        }
Example #8
0
        public OnMigrateFeedIndexIdEvent(
            ILogger logger,
            IPublishedResultsService resultsService,
            ICorrelationIdProvider correlationIdProvider)
        {
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(resultsService, nameof(resultsService));
            Guard.ArgumentNotNull(correlationIdProvider, nameof(correlationIdProvider));

            _logger = logger;
            _correlationIdProvider = correlationIdProvider;
            _resultsService        = resultsService;
        }
        public OnReIndexAllocationNotificationFeeds(
            ILogger logger,
            IPublishedResultsService resultsService,
            ICorrelationIdProvider correlationIdProvider)
        {
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(resultsService, nameof(resultsService));
            Guard.ArgumentNotNull(correlationIdProvider, nameof(correlationIdProvider));

            _logger = logger;
            _correlationIdProvider = correlationIdProvider;
            _resultsService        = resultsService;
        }
Example #10
0
        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>();
        }
 private static AllocationsService CreateService(IPublishedResultsService resultsService = null)
 {
     return(new AllocationsService(resultsService ?? CreateResultsService()));
 }
        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);
        }
Example #14
0
 private static AllocationsService CreateService(IPublishedResultsService resultsService = null, IFeatureToggle featureToggle = null)
 {
     return(new AllocationsService(resultsService ?? CreateResultsService(), featureToggle ?? CreateFeatureToggle()));
 }
Example #15
0
        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");
        }