Exemple #1
0
        public async Task EditSpecification_GivenSetLatestProviderVersionChangesFromManualToUseLatest_InstructToQueueProviderSnapshotDataLoadJob()
        {
            //Arrange
            _specification.Current.CoreProviderVersionUpdates = CoreProviderVersionUpdates.Manual;
            SpecificationEditModel specificationEditModel = new SpecificationEditModel
            {
                FundingPeriodId            = "fp10",
                Name                       = "new spec name",
                ProviderVersionId          = _specification.Current.ProviderVersionId,
                AssignedTemplateIds        = new Dictionary <string, string>(),
                CoreProviderVersionUpdates = CoreProviderVersionUpdates.UseLatest
            };
            Reference user = new Reference();

            SpecificationVersion newSpecVersion = _specification.Current.DeepCopy(useCamelCase: false);

            newSpecVersion.Name             = specificationEditModel.Name;
            newSpecVersion.FundingPeriod.Id = specificationEditModel.FundingPeriodId;
            newSpecVersion.FundingStreams   = new[] { new Reference {
                                                          Id = "fs11"
                                                      } };
            newSpecVersion.FundingPeriod.Name = "p10";
            newSpecVersion.Author             = user;
            newSpecVersion.Description        = specificationEditModel.Description;

            string specFundingStreamId = _specification.Current.FundingStreams.FirstOrDefault().Id;

            AndGetFundingConfiguration(
                specFundingStreamId,
                specificationEditModel.FundingPeriodId);

            _providersApiClient.GetCurrentProviderMetadataForFundingStream(specFundingStreamId)
            .Returns(new ApiResponse <CurrentProviderVersionMetadata>(HttpStatusCode.NotFound, null));

            SpecificationsService service = CreateSpecificationsService(newSpecVersion);

            string correlationId = NewRandomString();

            //Act
            IActionResult result = await service.EditSpecification(SpecificationId, specificationEditModel, user, correlationId);

            result.Should()
            .BeOfType <InternalServerErrorResult>()
            .Which
            .Value
            .Should()
            .Be($"No current provider metadata returned for funding stream id '{specFundingStreamId}'.");
        }
Exemple #2
0
        public async Task EditSpecification_GivenChangesWithFDZProviderSourceAndProviderSnapshotIdNotSet_ReturnsPreconditionFailedResult()
        {
            //Arrange
            SpecificationEditModel specificationEditModel = new SpecificationEditModel
            {
                FundingPeriodId     = "fp10",
                Name                = "new spec name",
                ProviderVersionId   = _specification.Current.ProviderVersionId,
                Description         = "new spec description",
                AssignedTemplateIds = new Dictionary <string, string>()
            };

            Reference user = new Reference();

            SpecificationVersion newSpecVersion = _specification.Current.DeepCopy(useCamelCase: false);

            newSpecVersion.Name               = specificationEditModel.Name;
            newSpecVersion.FundingPeriod.Id   = specificationEditModel.FundingPeriodId;
            newSpecVersion.FundingPeriod.Name = "p10";
            newSpecVersion.Author             = user;
            newSpecVersion.Description        = specificationEditModel.Description;

            AndGetFundingConfiguration(
                _specification.Current.FundingStreams.FirstOrDefault().Id,
                specificationEditModel.FundingPeriodId,
                ProviderSource.FDZ);

            SpecificationsService service = CreateSpecificationsService(newSpecVersion);

            string correlationId = NewRandomString();

            SpecificationVersion previousSpecificationVersion = _specification.Current;

            //Act
            IActionResult actionResult =
                await service.EditSpecification(SpecificationId, specificationEditModel, user, correlationId);

            actionResult
            .Should()
            .BeOfType <PreconditionFailedResult>();
        }
Exemple #3
0
        public async Task EditSpecification_GivenChangesAndNoCurrentProviderVersionMetatdataForFundingStream_ReturnServerError()
        {
            //Arrange
            bool withRunCalculationEngineAfterCoreProviderUpdate = true;

            _specification.Current.CoreProviderVersionUpdates = CoreProviderVersionUpdates.Manual;
            SpecificationEditModel specificationEditModel = new SpecificationEditModel
            {
                FundingPeriodId            = "fp10",
                Name                       = "new spec name",
                ProviderVersionId          = _specification.Current.ProviderVersionId,
                AssignedTemplateIds        = new Dictionary <string, string>(),
                CoreProviderVersionUpdates = CoreProviderVersionUpdates.UseLatest
            };
            Reference user = new Reference();

            SpecificationVersion newSpecVersion = _specification.Current.DeepCopy(useCamelCase: false);

            newSpecVersion.Name             = specificationEditModel.Name;
            newSpecVersion.FundingPeriod.Id = specificationEditModel.FundingPeriodId;
            newSpecVersion.FundingStreams   = new[] { new Reference {
                                                          Id = "fs11"
                                                      } };
            newSpecVersion.FundingPeriod.Name = "p10";
            newSpecVersion.Author             = user;
            newSpecVersion.Description        = specificationEditModel.Description;

            string specFundingStreamId = _specification.Current.FundingStreams.FirstOrDefault().Id;
            int    providerSnapshotId  = NewRandomInt();

            CurrentProviderVersionMetadata currentProviderVersionMetadata = new CurrentProviderVersionMetadata
            {
                FundingStreamId    = specFundingStreamId,
                ProviderSnapshotId = providerSnapshotId
            };

            AndGetFundingConfiguration(
                specFundingStreamId,
                specificationEditModel.FundingPeriodId,
                withRunCalculationEngineAfterCoreProviderUpdate: withRunCalculationEngineAfterCoreProviderUpdate);

            _providersApiClient.GetCurrentProviderMetadataForFundingStream(specFundingStreamId)
            .Returns(new ApiResponse <CurrentProviderVersionMetadata>(HttpStatusCode.OK, currentProviderVersionMetadata));

            SpecificationsService service = CreateSpecificationsService(newSpecVersion);

            string correlationId = NewRandomString();

            SpecificationVersion previousSpecificationVersion = _specification.Current;

            //Act
            await service.EditSpecification(SpecificationId, specificationEditModel, user, correlationId);

            await _specificationIndexer
            .Received(1)
            .Index(Arg.Is <Specification>(_ => ReferenceEquals(_.Current, newSpecVersion)));

            await
            _cacheProvider
            .Received(1)
            .RemoveAsync <SpecificationSummary>(Arg.Is($"{CacheKeys.SpecificationSummaryById}{_specification.Id}"));

            await
            _messengerService
            .Received(1)
            .SendToTopic(Arg.Is(ServiceBusConstants.TopicNames.EditSpecification),
                         Arg.Is <SpecificationVersionComparisonModel>(
                             m => m.Id == SpecificationId &&
                             m.Current.Name == "new spec name" &&
                             m.Previous.Name == "Spec name"
                             ), Arg.Any <IDictionary <string, string> >(), Arg.Is(true));

            await
            _versionRepository
            .Received(1)
            .SaveVersion(Arg.Is(newSpecVersion));

            await _templateVersionChangedHandler
            .Received(1)
            .HandleTemplateVersionChanged(Arg.Is(previousSpecificationVersion),
                                          Arg.Any <SpecificationVersion>(),
                                          Arg.Is(specificationEditModel.AssignedTemplateIds),
                                          Arg.Is(user),
                                          Arg.Is(correlationId));

            await _editSpecificationJobActions
            .Received(1)
            .Run(Arg.Is <SpecificationVersion>(
                     m => !string.IsNullOrWhiteSpace(m.EntityId) &&
                     m.Name == specificationEditModel.Name),
                 Arg.Any <Reference>(),
                 Arg.Any <string>(),
                 true,
                 withRunCalculationEngineAfterCoreProviderUpdate);
        }
Exemple #4
0
        public async Task EditSpecification_GivenChangesWithFDZProviderSource_UpdatesSearchAndSendsMessage()
        {
            //Arrange
            SpecificationEditModel specificationEditModel = new SpecificationEditModel
            {
                FundingPeriodId     = "fp10",
                Name                = "new spec name",
                ProviderVersionId   = _specification.Current.ProviderVersionId,
                Description         = "new spec description",
                AssignedTemplateIds = new Dictionary <string, string>(),
                ProviderSnapshotId  = 1
            };

            Reference user = new Reference();

            SpecificationVersion newSpecVersion = _specification.Current.DeepCopy(useCamelCase: false);

            newSpecVersion.Name               = specificationEditModel.Name;
            newSpecVersion.FundingPeriod.Id   = specificationEditModel.FundingPeriodId;
            newSpecVersion.FundingPeriod.Name = "p10";
            newSpecVersion.Author             = user;
            newSpecVersion.Description        = specificationEditModel.Description;
            newSpecVersion.ProviderSnapshotId = 1;
            newSpecVersion.ProviderSource     = Models.Providers.ProviderSource.FDZ;

            AndGetFundingConfiguration(
                _specification.Current.FundingStreams.FirstOrDefault().Id,
                specificationEditModel.FundingPeriodId,
                ProviderSource.FDZ);

            SpecificationsService service = CreateSpecificationsService(newSpecVersion);

            string correlationId = NewRandomString();

            SpecificationVersion previousSpecificationVersion = _specification.Current;

            //Act
            await service.EditSpecification(SpecificationId, specificationEditModel, user, correlationId);

            await _specificationIndexer
            .Received(1)
            .Index(Arg.Is <Specification>(_ => ReferenceEquals(_.Current, newSpecVersion)));

            await
            _cacheProvider
            .Received(1)
            .RemoveAsync <SpecificationSummary>(Arg.Is($"{CacheKeys.SpecificationSummaryById}{_specification.Id}"));

            await
            _messengerService
            .Received(1)
            .SendToTopic(Arg.Is(ServiceBusConstants.TopicNames.EditSpecification),
                         Arg.Is <SpecificationVersionComparisonModel>(
                             m => m.Id == SpecificationId &&
                             m.Current.Name == "new spec name" &&
                             m.Previous.Name == "Spec name"
                             ), Arg.Any <IDictionary <string, string> >(), Arg.Is(true));

            await
            _versionRepository
            .Received(1)
            .SaveVersion(Arg.Is(newSpecVersion));

            await _templateVersionChangedHandler
            .Received(1)
            .HandleTemplateVersionChanged(Arg.Is(previousSpecificationVersion),
                                          Arg.Is <SpecificationVersion>(_ => newSpecVersion.AsJson(true) == _.AsJson(true)),
                                          Arg.Is(specificationEditModel.AssignedTemplateIds),
                                          Arg.Is(user),
                                          Arg.Is(correlationId));
        }
        public static IEnumerable <Calcs.Calculation> GenerateCalculations(this Policy policy, SpecificationVersion specification, List <Reference> parentPolicySpecifications = null)
        {
            var policies = (parentPolicySpecifications ?? new List <Reference>()).Concat(new[] { policy.GetReference() }).ToList();

            if (policy.Calculations != null)
            {
                foreach (var calculationSpecification in policy.Calculations)
                {
                    yield return(new Calcs.Calculation
                    {
                        Id = Reference.NewId(),
                        Name = calculationSpecification.Name,
                        CalculationSpecification = calculationSpecification,
                        AllocationLine = calculationSpecification.AllocationLine,
                        Policies = policies
                    });
                }
            }
            if (policy.SubPolicies != null)
            {
                foreach (var subPolicy in policy.SubPolicies)
                {
                    foreach (var calculationSpecification in subPolicy.GenerateCalculations(specification, policies))
                    {
                        yield return(calculationSpecification);
                    }
                }
            }
        }