Example #1
0
        /// <summary>
        /// Validates the configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <returns></returns>
        public Domain.Entities.ValidationResult ValidateConfiguration(Configuration configuration)
        {
            ConfigurationValidator validator = new ConfigurationValidator();

            FluentValidation.Results.ValidationResult results = validator.Validate(configuration);
            return(GetValidationResultResponse(results));
        }
Example #2
0
        public void CheckDoesNothingWhenSettingAvailable()
        {
            var settings = Setting("IntegerListProperty", "1,2");

            using (var validator = new ConfigurationValidator(settings))
                validator.Check(() => IntegerListProperty);
        }
Example #3
0
        public void CheckDoesNothingWhenSettingAvailable()
        {
            var settings = Setting("EnumProperty", "A");

            using (var validator = new ConfigurationValidator(settings))
                validator.Check(() => EnumProperty);
        }
Example #4
0
        private bool IsCreatorConfigValid(DeploymentDefinition creatorConfig)
        {
            var  creatorConfigurationValidator = new ConfigurationValidator();
            bool isValidCreatorConfig          = creatorConfigurationValidator.Validate(creatorConfig);

            return(isValidCreatorConfig);
        }
Example #5
0
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        public TestRailResult()
        {
            // Do not delete - a parameterless constructor is required!

            this.configValidator        = new ConfigurationValidator();
            this.testRailTimeoutSeconds = 5;
        }
        public static List <DatabaseConfigElement> CreateValidatedDatabaseConfigCollection(DatabaseConfigCollection databases)
        {
            var validatedDatabaseConfigs = new List <DatabaseConfigElement>();

            for (int i = 0; i < databases.Count; i++)
            {
                var dbConfig = databases[i];

                var dbConfigValidationResult = ConfigurationValidator.IsDbConfigValid(dbConfig);

                if (!dbConfigValidationResult.IsValid)
                {
                    logger.Error($"The anonymization of the database with the following connection string was skipped: {dbConfig.ConnectionString}. " +
                                 $"Reason: {dbConfigValidationResult.ValidationMessage}");
                }
                else
                {
                    try
                    {
                        DbTypeInitializer.CreateDbTypes(dbConfig.ConnectionString);
                        validatedDatabaseConfigs.Add(databases[i]);
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex, $"The anonymization of the database with the following connection string was skipped: {dbConfig.ConnectionString}. " +
                                     $"Reason: {ex.Message}");
                    }
                }
            }

            return(validatedDatabaseConfigs);
        }
        public void CompatibleCandleWidthSame()
        {
            const string input = "Value: 5";
            var          obj   = Deserializer.Deserialize <CompatibleCandleWidthObject>(new StringReader(input));

            ConfigurationValidator.ValidateConstraintsRecursively(obj);
        }
        public IActionResult Configure(ConfigurationModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentMethods))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //validate configuration (custom validation)
            var validationResult = new ConfigurationValidator(_localizationService).Validate(model);

            if (!validationResult.IsValid)
            {
                return(Configure());
            }

            _iyzicoPaymentSettings.ApiKey    = model.ApiKey;
            _iyzicoPaymentSettings.SecretKey = model.SecretKey;
            _iyzicoPaymentSettings.BaseUrl   = model.BaseUrl;
            _iyzicoPaymentSettings.PaymentMethodDescription = model.PaymentMethodDescription;

            _settingService.SaveSetting(_iyzicoPaymentSettings);
            _notificationService.SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));
            return(View(@"~/Plugins/Payments.Iyzico/Views/Configure.cshtml", model));
        }
Example #9
0
        public void CanBeConstructedPrivateConstructor()
        {
            const string input = "Item: a_string";
            var          obj   = Deserializer.Deserialize <ConstructablePrivateConstructorObject>(new StringReader(input));

            Assert.Throws <InvalidConstraintException>(() => ConfigurationValidator.ValidateConstraintsRecursively(obj));
        }
Example #10
0
            public void Scope_expression_must_not_be_whitespace(string filterType)
            {
                // ARRANGE
                var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();

                config.Filter.Include = new[]
                {
                    new ChangeLogConfiguration.FilterExpressionConfiguration()
                    {
                        Scope = filterType
                    }
                };
                config.Filter.Exclude = new[]
                {
                    new ChangeLogConfiguration.FilterExpressionConfiguration()
                    {
                        Scope = filterType
                    }
                };
                var sut = new ConfigurationValidator();

                // ACT
                var result = sut.Validate(config);

                // ASSERT
                Assert.False(result.IsValid);
                Assert.Collection(result.Errors,
                                  error => Assert.Contains("'Filter Scope Expression'", error.ErrorMessage),
                                  error => Assert.Contains("'Filter Scope Expression'", error.ErrorMessage)
                                  );
            }
Example #11
0
            public void Scope_expression_can_be_null_or_empty(string filterType)
            {
                // ARRANGE
                var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();

                config.Filter.Include = new[]
                {
                    new ChangeLogConfiguration.FilterExpressionConfiguration()
                    {
                        Scope = filterType
                    }
                };
                config.Filter.Exclude = new[]
                {
                    new ChangeLogConfiguration.FilterExpressionConfiguration()
                    {
                        Scope = filterType
                    }
                };

                var sut = new ConfigurationValidator();

                // ACT
                var result = sut.Validate(config);

                // ASSERT
                Assert.True(result.IsValid);
                Assert.Empty(result.Errors);
            }
Example #12
0
        public static List <TableConfigElement> CreateValidatedTableConfigCollection(DatabaseConfigElement dbConfig)
        {
            var validatedTableConfigs = new List <TableConfigElement>();

            var dbConfigValidationResult = ConfigurationValidator.IsDbConfigValid(dbConfig);

            if (!dbConfigValidationResult.IsValid)
            {
                logger.Error($"The anonymization of the database with the following connection string was skipped: {dbConfig.ConnectionString}. " +
                             $"Reason: {dbConfigValidationResult.ValidationMessage}");
                return(validatedTableConfigs);
            }


            for (int i = 0; i < dbConfig.Tables.Count; i++)
            {
                var tableConfig = dbConfig.Tables[i];

                var tableConfigValidationResult = ConfigurationValidator.IsTableConfigValid(dbConfig, tableConfig);
                if (!tableConfigValidationResult.IsValid)
                {
                    logger.Error($"The anonymization of the table {tableConfigValidationResult.TableNameWithSchema} " +
                                 $"with the following connection string was skipped: {tableConfigValidationResult.ConnectionString}. " +
                                 $"Reason: {tableConfigValidationResult.ValidationMessage}");
                }
                else
                {
                    validatedTableConfigs.Add(tableConfig);
                }
            }

            return(validatedTableConfigs);
        }
Example #13
0
        public void CanBeConstructedHappyFlow()
        {
            const string input = "Item: a_string ";
            var          obj   = Deserializer.Deserialize <ConstructableHappyFlowObject>(new StringReader(input));

            ConfigurationValidator.ValidateConstraintsRecursively(obj);
        }
Example #14
0
            public void Types_must_be_unique(string entryType)
            {
                // ARRANGE
                var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();

                config.EntryTypes = new Dictionary <string, ChangeLogConfiguration.EntryTypeConfiguration>()
                {
                    { entryType.ToLower(), new ChangeLogConfiguration.EntryTypeConfiguration()
                      {
                          DisplayName = "Display Name"
                      } },
                    { entryType.ToUpper(), new ChangeLogConfiguration.EntryTypeConfiguration()
                      {
                          DisplayName = "Display Name"
                      } }
                };

                var sut = new ConfigurationValidator();

                // ACT
                var result = sut.Validate(config);

                // ASSERT
                Assert.False(result.IsValid);
                var error = Assert.Single(result.Errors);

                Assert.Contains("'Entry Type' must be unique", error.ErrorMessage);
            }
Example #15
0
            public void Custom_directory_must_exist_when_it_is_not_null_or_empty(ChangeLogConfiguration.TemplateName template)
            {
                // ARRANGE
                var config = ChangeLogConfigurationLoader.GetDefaultConfiguration();

                var customDirectoryProperty = config.Template.GetType().GetProperty(template.ToString());
                var templateSettings        = (ChangeLogConfiguration.TemplateSettings)customDirectoryProperty !.GetValue(config.Template) !;

                templateSettings.CustomDirectory = "/Some-Directory";

                var sut = new ConfigurationValidator();

                // ACT
                var result = sut.Validate(config);

                // ASSERT
                Assert.False(result.IsValid);
                Assert.Collection(result.Errors,
                                  error =>
                {
                    Assert.Contains("'Template Custom Directory'", error.ErrorMessage);
                    Assert.Contains("'/Some-Directory'", error.ErrorMessage);
                }
                                  );
            }
Example #16
0
        public void TestConstantsValidation()
        {
            var validator = new ConfigurationValidator <TestClass, TestClassMapConstants>();

            validator.Validate();
            Assert.True(validator.Errors.Count == 1);
        }
Example #17
0
        public void CheckDoesNothingWhenSettingWithPrefixAvailable()
        {
            var settings = Setting("UK-EnumProperty", "B");

            using (var validator = new ConfigurationValidator(settings))
                validator.Check("UK-", () => EnumProperty);
        }
        public DestinationAeTitleControllerTest()
        {
            _serviceProvider        = new Mock <IServiceProvider>();
            _logger                 = new Mock <ILogger <DestinationAeTitleController> >();
            _validationLogger       = new Mock <ILogger <ConfigurationValidator> >();
            _kubernetesClient       = new Mock <IKubernetesWrapper>();
            _configurationValidator = new ConfigurationValidator(_validationLogger.Object);
            _configuration          = Options.Create(new DicomAdapterConfiguration());
            _controller             = new DestinationAeTitleController(_serviceProvider.Object, _logger.Object, _kubernetesClient.Object, _configurationValidator, _configuration);
            _problemDetailsFactory  = new Mock <ProblemDetailsFactory>();
            _problemDetailsFactory.Setup(_ => _.CreateProblemDetails(
                                             It.IsAny <HttpContext>(),
                                             It.IsAny <int?>(),
                                             It.IsAny <string>(),
                                             It.IsAny <string>(),
                                             It.IsAny <string>(),
                                             It.IsAny <string>())
                                         )
            .Returns((HttpContext httpContext, int?statusCode, string title, string type, string detail, string instance) =>
            {
                return(new ProblemDetails
                {
                    Status = statusCode,
                    Title = title,
                    Type = type,
                    Detail = detail,
                    Instance = instance
                });
            });

            _controller = new DestinationAeTitleController(_serviceProvider.Object, _logger.Object, _kubernetesClient.Object, _configurationValidator, _configuration)
            {
                ProblemDetailsFactory = _problemDetailsFactory.Object
            };
        }
Example #19
0
        public void AllValid()
        {
            var config = MockValidConfiguration();
            var valid  = new ConfigurationValidator(logger.Object).Validate("", config);

            Assert.True(valid == ValidateOptionsResult.Success);
        }
Example #20
0
        public void CheckDoesNothingWhenSettingWithPrefixAvailable()
        {
            var setting = Setting("UK-BooleanProperty", "false");

            using (var validator = new ConfigurationValidator(setting))
                validator.Check("UK-", () => BooleanProperty);
        }
Example #21
0
        public void TestIndexOutOfRangeValidation()
        {
            var classMap  = new TestClassMapIndexOutOfRange();
            var validator = new ConfigurationValidator <TestClass, TestClassMapIndexOutOfRange>();

            validator.Validate();
            Assert.True(validator.Errors.Count == 2);
        }
Example #22
0
        internal AlgorithmConfiguration ParseAlgorithmConfiguration(string source)
        {
            var config = new DeserializerBuilder().Build()
                         .Deserialize <TemplateAlgorithmConfiguration>(new StringReader(source));

            ConfigurationValidator.ValidateConstraintsRecursively(AlgorithmConfiguration);
            return(config);
        }
        public void CompatibleCandleWidthNotDivisible()
        {
            const string input = "Value: 7";
            var          obj   = Deserializer.Deserialize <CompatibleCandleWidthObject>(new StringReader(input));

            Assert.Throws <InvalidConfigurationException>(
                () => ConfigurationValidator.ValidateConstraintsRecursively(obj));
        }
Example #24
0
        public void TestDuplicateReadPropertiesValidation()
        {
            var classMap  = new TestClassMapDuplicateReadProperties();
            var validator = new ConfigurationValidator <TestClass, TestClassMapDuplicateReadProperties>();

            validator.Validate();
            Assert.True(validator.HasErrors);
        }
Example #25
0
        public void TestLongHeadersValidation()
        {
            var classMap  = new TestClassMapLongHeaders();
            var validator = new ConfigurationValidator <TestClass, TestClassMapLongHeaders>();

            validator.Validate();
            Assert.True(validator.Errors.Count == 1);
        }
Example #26
0
 public DestinationAeTitleController(
     IHttpContextAccessor httpContextAccessor,
     ILogger <DestinationAeTitleController> logger,
     IKubernetesWrapper kubernetesClient,
     ConfigurationValidator configurationValidator,
     IOptions <DicomAdapterConfiguration> dicomAdapterConfiguration)
     : base(httpContextAccessor, logger, kubernetesClient, CustomResourceDefinition.DestinationAeTitleCrd, configurationValidator, dicomAdapterConfiguration)
 {
 }
Example #27
0
        private static void Validate(ValidationConfiguration configuration)
        {
            var optionsAccessor = new Mock <IOptionsSnapshot <ValidationConfiguration> >();

            optionsAccessor.SetupGet(cfg => cfg.Value).Returns(configuration);
            var validator = new ConfigurationValidator(optionsAccessor.Object);

            validator.Validate();
        }
 public DestinationAeTitleController(
     IServiceProvider serviceProvider,
     ILogger <DestinationAeTitleController> logger,
     IKubernetesWrapper kubernetesClient,
     ConfigurationValidator configurationValidator,
     IOptions <DicomAdapterConfiguration> dicomAdapterConfiguration)
     : base(serviceProvider, logger, kubernetesClient, CustomResourceDefinition.DestinationAeTitleCrd, configurationValidator, dicomAdapterConfiguration)
 {
 }
Example #29
0
        public void CheckThrowsExceptionWhenSettingMissing()
        {
            var exception = Assert.Throws <ConfigurationException>(() =>
            {
                using (var validator = new ConfigurationValidator(NoSettings))
                    validator.Check(() => BooleanProperty);
            });

            Assert.AreEqual("The BooleanProperty setting is missing", exception.Message);
        }
Example #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BaseProviderTests"/> class.
        /// </summary>
        /// <param name="outputHelper">Used to create output.</param>
        public BaseProviderTests(ITestOutputHelper outputHelper)
            : base(outputHelper)
        {
            var serviceProvider = ServiceProviderSingleton.Instance.ServiceProvider;

            ExchangeFactoryService = serviceProvider.GetService <ExchangeFactoryService>();
            AlgorithmConfiguration = new DeserializerBuilder().Build()
                                     .Deserialize <TemplateAlgorithmConfiguration>(new StringReader(AlgorithmSettingsSource));
            ConfigurationValidator.ValidateConstraintsRecursively(AlgorithmConfiguration);
        }
            /// <summary>
            /// Adds a validator.
            /// </summary>
            /// <param name="validator">The validator delegate to add.</param>
            /// <param name="payloadElementTypes">The payload element types to add the validator for.</param>
            public void Add(ConfigurationValidator validator, params ODataPayloadElementType[] payloadElementTypes)
            {
                foreach (var payloadElementType in payloadElementTypes)
                {
                    List<ConfigurationValidator> validators;
                    if (!this.map.TryGetValue(payloadElementType, out validators))
                    {
                        validators = new List<ConfigurationValidator>();
                        this.map[payloadElementType] = validators;
                    }

                    validators.Add(validator);
                }
            }