Пример #1
0
        public void EditSpecification_GivenProviderVersionChangesAndRegenerateScopedProvidersFails_ExceptionThrown()
        {
            //Arrange
            var existingFundingStreams = _specification.Current.FundingStreams;
            SpecificationEditModel specificationEditModel = new SpecificationEditModel
            {
                FundingPeriodId = "fp10",
                Name            = "new spec name"
            };

            PolicyModels.FundingStream fundingStream = new PolicyModels.FundingStream
            {
                Id = existingFundingStreams.First().Id
            };
            Models.Specs.SpecificationVersion newSpecVersion = _specification.Current.Clone() as Models.Specs.SpecificationVersion;
            newSpecVersion.Name             = specificationEditModel.Name;
            newSpecVersion.FundingPeriod.Id = specificationEditModel.FundingPeriodId;
            newSpecVersion.FundingStreams   = new[] { new Reference {
                                                          Id = "fs11"
                                                      } };
            newSpecVersion.ProviderVersionId = "Provider version 2";

            _providersApiClient.RegenerateProviderSummariesForSpecification(_specification.Id, true)
            .Returns(new ApiResponse <bool>(HttpStatusCode.BadRequest));

            var service = CreateSpecificationsService(newSpecVersion);

            //Act
            Func <Task> invocation = async() => await service.EditSpecification(SpecificationId, specificationEditModel, null, null);

            //Arrange
            invocation.Should()
            .Throw <RetriableException>()
            .WithMessage($"Unable to re-generate scoped providers while editing specification '{_specification.Id}' with status code: {HttpStatusCode.BadRequest}");
        }
Пример #2
0
        private SpecificationsService CreateSpecificationsService(Models.Specs.SpecificationVersion newSpecVersion)
        {
            _specificationsRepository
            .GetSpecificationById(Arg.Is(SpecificationId))
            .Returns(_specification);
            _policiesApiClient
            .GetFundingPeriodById(Arg.Is(_fundingPeriod.Id))
            .Returns(_fundingPeriodResponse);
            _specificationsRepository
            .UpdateSpecification(Arg.Any <Specification>())
            .Returns(HttpStatusCode.OK);
            _versionRepository
            .CreateVersion(Arg.Any <Models.Specs.SpecificationVersion>(), Arg.Any <Models.Specs.SpecificationVersion>())
            .Returns(newSpecVersion);
            SpecificationsService service = CreateService(
                mapper: _mapper,
                logs: _logger,
                specificationsRepository: _specificationsRepository,
                policiesApiClient: _policiesApiClient,
                searchRepository: _searchRepository,
                cacheProvider: _cacheProvider,
                messengerService: _messengerService,
                specificationVersionRepository: _versionRepository,
                providersApiClient: _providersApiClient,
                queueEditSpecificationJobActions: _editSpecificationJobActions);

            return(service);
        }
Пример #3
0
        public async Task EditSpecification_GivenChangesAndSpecContainsCalculations_UpdatesSearchAndSendsMessage()
        {
            //Arrange
            SpecificationEditModel specificationEditModel = new SpecificationEditModel
            {
                FundingPeriodId   = "fp10",
                Name              = "new spec name",
                ProviderVersionId = _specification.Current.ProviderVersionId
            };

            Models.Specs.SpecificationVersion newSpecVersion = _specification.Current.Clone() as Models.Specs.SpecificationVersion;
            newSpecVersion.Name             = specificationEditModel.Name;
            newSpecVersion.FundingPeriod.Id = specificationEditModel.FundingPeriodId;
            newSpecVersion.FundingStreams   = new[] { new Reference {
                                                          Id = "fs11"
                                                      } };
            _versionRepository
            .CreateVersion(Arg.Any <Models.Specs.SpecificationVersion>(), Arg.Any <Models.Specs.SpecificationVersion>())
            .Returns(newSpecVersion);

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

            var service = CreateSpecificationsService(newSpecVersion);

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

            //Assert
            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));
        }
Пример #4
0
        public async Task EditSpecification_GivenProviderVersionChanges_CallsRegenerateScopedProviders()
        {
            //Arrange
            SpecificationEditModel specificationEditModel = new SpecificationEditModel
            {
                FundingPeriodId = "fp10",
                Name            = "new spec name"
            };

            Models.Specs.SpecificationVersion newSpecVersion = _specification.Current.Clone() as Models.Specs.SpecificationVersion;
            newSpecVersion.Name             = specificationEditModel.Name;
            newSpecVersion.FundingPeriod.Id = specificationEditModel.FundingPeriodId;
            newSpecVersion.FundingStreams   = new[] { new Reference {
                                                          Id = "fs11"
                                                      } };
            newSpecVersion.ProviderVersionId = "Provider version 2";

            _providersApiClient.RegenerateProviderSummariesForSpecification(_specification.Id, true)
            .Returns(new ApiResponse <bool>(HttpStatusCode.OK, true));

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

            SpecificationsService service = CreateSpecificationsService(newSpecVersion);

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

            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));
        }