public OnEditSpecificationEvent(
     ILogger logger,
     IScenariosService scenariosService,
     IMessengerService messengerService,
     IUserProfileProvider userProfileProvider, bool useAzureStorage = false)
     : base(logger, messengerService, FunctionName, $"{ServiceBusConstants.TopicNames.EditSpecification}/{ServiceBusConstants.TopicSubscribers.UpdateScenariosForEditSpecification}", useAzureStorage, userProfileProvider, scenariosService)
 {
 }
 public OnEditCalculationEvent(
     ILogger logger,
     IScenariosService scenariosService,
     IMessengerService messengerService,
     IUserProfileProvider userProfileProvider, bool useAzureStorage = false)
     : base(logger, messengerService, FunctionName, useAzureStorage, userProfileProvider, scenariosService)
 {
 }
        public static void SetupTests(TestContext tc)
        {
            SetupTests("scenarios");

            _logger = CreateLogger();
            _datasetDefinitionFieldChangesProcessor = CreateDatasetDefinitionFieldChangesProcessor();
            _scenariosService    = CreateScenariosService();
            _userProfileProvider = CreateUserProfileProvider();
        }
Example #4
0
        public ScenariosController(
            IScenariosService scenarioService,
            IScenariosSearchService scenariosSearchService)
        {
            Guard.ArgumentNotNull(scenarioService, nameof(scenarioService));
            Guard.ArgumentNotNull(scenariosSearchService, nameof(scenariosSearchService));

            _scenarioService        = scenarioService;
            _scenariosSearchService = scenariosSearchService;
        }
Example #5
0
        public OnDeleteTests(
            ILogger logger,
            IScenariosService scenariosService,
            IMessengerService messengerService,
            IUserProfileProvider userProfileProvider, bool useAzureStorage = false)
            : base(logger, messengerService, FunctionName, QueueName, useAzureStorage, userProfileProvider, scenariosService)
        {
            Guard.ArgumentNotNull(scenariosService, nameof(scenariosService));

            _scenariosService = scenariosService;
        }
Example #6
0
        public OnEditCaluclationEvent(
            ILogger logger,
            ICorrelationIdProvider correlationIdProvider,
            IScenariosService scenariosService)
        {
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(correlationIdProvider, nameof(correlationIdProvider));
            Guard.ArgumentNotNull(scenariosService, nameof(scenariosService));

            _logger = logger;
            _correlationIdProvider = correlationIdProvider;
            _scenariosService      = scenariosService;
        }
Example #7
0
 private static DatasetDefinitionFieldChangesProcessor CreateProcessor(
     IFeatureToggle featureToggle         = null,
     IDatasetRepository datasetRepository = null,
     ILogger logger = null,
     IScenariosService scenariosService = null)
 {
     return(new DatasetDefinitionFieldChangesProcessor(
                featureToggle ?? CreateFeatureToggle(),
                logger ?? CreateLogger(),
                datasetRepository ?? CreateDatasetRepository(),
                ScenariosResilienceTestHelper.GenerateTestPolicies(),
                scenariosService ?? CreateScenariosService()));
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IScenariosService scenariosService)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            scenariosService.GenerateData();
        }
        public DatasetDefinitionFieldChangesProcessor(
            IFeatureToggle featureToggle,
            ILogger logger,
            IDatasetRepository datasetRepository,
            IScenariosResiliencePolicies scenariosResiliencePolicies,
            IScenariosService scenariosService)
        {
            Guard.ArgumentNotNull(featureToggle, nameof(featureToggle));
            Guard.ArgumentNotNull(datasetRepository, nameof(datasetRepository));
            Guard.ArgumentNotNull(scenariosResiliencePolicies, nameof(scenariosResiliencePolicies));
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(scenariosService, nameof(scenariosService));

            _featureToggle           = featureToggle;
            _logger                  = logger;
            _datasetRepository       = datasetRepository;
            _datasetRepositoryPolicy = scenariosResiliencePolicies.DatasetRepository;
            _scenariosService        = scenariosService;
        }
Example #10
0
        public DatasetDefinitionFieldChangesProcessor(
            IFeatureToggle featureToggle,
            ILogger logger,
            IDatasetsApiClient datasetsApiClient,
            IScenariosResiliencePolicies scenariosResiliencePolicies,
            IScenariosService scenariosService,
            IMapper mapper)
        {
            Guard.ArgumentNotNull(featureToggle, nameof(featureToggle));
            Guard.ArgumentNotNull(datasetsApiClient, nameof(datasetsApiClient));
            Guard.ArgumentNotNull(scenariosResiliencePolicies?.DatasetsApiClient, nameof(scenariosResiliencePolicies.DatasetsApiClient));
            Guard.ArgumentNotNull(logger, nameof(logger));
            Guard.ArgumentNotNull(scenariosService, nameof(scenariosService));
            Guard.ArgumentNotNull(mapper, nameof(mapper));

            _featureToggle           = featureToggle;
            _logger                  = logger;
            _datasetsApiClient       = datasetsApiClient;
            _datasetsApiClientPolicy = scenariosResiliencePolicies.DatasetsApiClient;
            _scenariosService        = scenariosService;
            _mapper                  = mapper;
        }
 public ScenariosController(IScenariosService scenariosService)
 {
     this.scenariosService = scenariosService;
 }
Example #12
0
 public ScenarioViewModel(IScenariosService scenariosService, PluginRunner runner)
     : base(runner)
 {
     this.scenariosService = scenariosService;
 }
Example #13
0
        public async Task ProcessChanges_GivenChangeModelWithMultipleFieldNameChanges_CallsResetCalculationForFieldDefinitionChanges()
        {
            //Arrange
            string definitionId    = "df-id-1";
            string specificationId = "spec-1";

            DatasetDefinitionChanges datasetDefinitionChanges = new DatasetDefinitionChanges
            {
                Id = definitionId,
            };

            FieldDefinitionChanges fieldDefinitionChanges1 = new FieldDefinitionChanges
            {
                FieldDefinition = new FieldDefinition
                {
                    Id = "field1"
                },
                ExistingFieldDefinition = new FieldDefinition {
                    Name = "test field 1"
                }
            };

            FieldDefinitionChanges fieldDefinitionChanges2 = new FieldDefinitionChanges
            {
                FieldDefinition = new FieldDefinition
                {
                    Id = "field2"
                },
                ExistingFieldDefinition = new FieldDefinition {
                    Name = "test field 2"
                }
            };

            fieldDefinitionChanges1.ChangeTypes.Add(FieldDefinitionChangeType.FieldName);
            fieldDefinitionChanges2.ChangeTypes.Add(FieldDefinitionChangeType.FieldName);

            TableDefinitionChanges tableDefinitionChanges = new TableDefinitionChanges();

            tableDefinitionChanges.FieldChanges.AddRange(new[] { fieldDefinitionChanges1, fieldDefinitionChanges2 });

            datasetDefinitionChanges.TableDefinitionChanges.Add(tableDefinitionChanges);

            string json = JsonConvert.SerializeObject(datasetDefinitionChanges);

            Message message = new Message(Encoding.UTF8.GetBytes(json));

            ILogger logger = CreateLogger();

            IEnumerable <string> relationshipSpecificationIds = new[] { specificationId };

            IEnumerable <DatasetSpecificationRelationshipViewModel> relationshipViewModels = new[]
            {
                new DatasetSpecificationRelationshipViewModel()
            };

            IDatasetRepository datasetRepository = CreateDatasetRepository();

            datasetRepository
            .GetRelationshipSpecificationIdsByDatasetDefinitionId(Arg.Is(definitionId))
            .Returns(relationshipSpecificationIds);
            datasetRepository
            .GetCurrentRelationshipsBySpecificationIdAndDatasetDefinitionId(Arg.Is(specificationId), Arg.Is(definitionId))
            .Returns(relationshipViewModels);

            IScenariosService scenariosService = CreateScenariosService();

            DatasetDefinitionFieldChangesProcessor processor = CreateProcessor(
                logger: logger,
                datasetRepository: datasetRepository,
                scenariosService: scenariosService);

            //Act
            await processor.ProcessChanges(message);

            //Assert
            await
            scenariosService
            .Received(1)
            .ResetScenarioForFieldDefinitionChanges(Arg.Is(relationshipViewModels), Arg.Is(specificationId),
                                                    Arg.Is <IEnumerable <string> >(
                                                        m =>
                                                        m.Count() == 2 &&
                                                        m.ElementAt(0) == "test field 1" &&
                                                        m.ElementAt(1) == "test field 2"));
        }
        public async Task ProcessChanges_GivenChangeModelWithFieldChanges_CallsResetCalculationForFieldDefinitionChanges(FieldDefinitionChangeType fieldDefinitionChangeType)
        {
            //Arrange
            string definitionId    = "df-id-1";
            string specificationId = "spec-1";

            DatasetDefinitionChanges datasetDefinitionChanges = new DatasetDefinitionChanges
            {
                Id = definitionId,
            };

            FieldDefinitionChanges fieldDefinitionChanges = new FieldDefinitionChanges
            {
                FieldDefinition = new FieldDefinition
                {
                    Id = "field1"
                },
                ExistingFieldDefinition = new FieldDefinition {
                    Name = "test field 1"
                }
            };

            fieldDefinitionChanges.ChangeTypes.Add(fieldDefinitionChangeType);

            TableDefinitionChanges tableDefinitionChanges = new TableDefinitionChanges();

            tableDefinitionChanges.FieldChanges.Add(fieldDefinitionChanges);

            datasetDefinitionChanges.TableDefinitionChanges.Add(tableDefinitionChanges);

            string json = JsonConvert.SerializeObject(datasetDefinitionChanges);

            Message message = new Message(Encoding.UTF8.GetBytes(json));

            ILogger logger = CreateLogger();

            IEnumerable <string> relationshipSpecificationIds = new[] { specificationId };

            IEnumerable <Common.ApiClient.DataSets.Models.DatasetSpecificationRelationshipViewModel> relationshipViewModels = new[]
            {
                new Common.ApiClient.DataSets.Models.DatasetSpecificationRelationshipViewModel()
                {
                    Id = "rel-1"
                }
            };

            IDatasetsApiClient datasetRepository = CreateDatasetRepository();

            datasetRepository
            .GetSpecificationIdsForRelationshipDefinitionId(Arg.Is(definitionId))
            .Returns(new ApiResponse <IEnumerable <string> >(HttpStatusCode.OK, relationshipSpecificationIds));
            datasetRepository
            .GetCurrentRelationshipsBySpecificationIdAndDatasetDefinitionId(Arg.Is(specificationId), Arg.Is(definitionId))
            .Returns(new ApiResponse <IEnumerable <Common.ApiClient.DataSets.Models.DatasetSpecificationRelationshipViewModel> >(HttpStatusCode.OK, relationshipViewModels));

            IScenariosService scenariosService = CreateScenariosService();
            IMapper           mapper           = CreateMapper();

            DatasetDefinitionFieldChangesProcessor processor = CreateProcessor(
                logger: logger,
                datasetRepository: datasetRepository,
                scenariosService: scenariosService,
                mapper: mapper);

            //Act
            await processor.Process(message);

            //Assert
            await
            scenariosService
            .Received(1)
            .ResetScenarioForFieldDefinitionChanges(Arg.Is <IEnumerable <Models.Datasets.ViewModels.DatasetSpecificationRelationshipViewModel> >(_ => _.First().Id == relationshipViewModels.First().Id),
                                                    Arg.Is(specificationId), Arg.Is <IEnumerable <string> >(m => m.First() == "test field 1"));
        }