public void ConfigFieldsMissingButValidationSkipped() { try { Dictionary <string, string> overrides = new Dictionary <string, string> { { "SkipConfigValidation", "Yes" } }; Config.AddGeneralTestSettingValues(overrides); ConfigValidation configValidation = new ConfigValidation() { RequiredFields = new List <string> { "Invalid_Config_Field_For_Validation" } }; Config.Validate(ConfigSection.WebServiceMaqs, configValidation); } finally { Dictionary <string, string> overrides = new Dictionary <string, string> { { "SkipConfigValidation", "No" } }; Config.AddGeneralTestSettingValues(overrides); } }
private ConfigValidation ValidateConfig(Config config, string value) { var validation = new ConfigValidation() { Error = string.Empty, Valid = true }; // With the exception of "int" and "string" config types, all other types have // values that are selected and not entered. "int" is the only one we need to verify switch (config.Type) { case "bool[]": case "bool": case "string[]": case "string": break; case "int": int intOut; if (!int.TryParse(value, out intOut)) { validation.Error = string.Format("{0} » {1} requires a valid number.", config.Group, config.Name); validation.FieldError = "Enter a valid number."; validation.Valid = false; } break; } return(validation); }
public void ConfigNoRequiredFields() { ConfigValidation configValidation = new ConfigValidation() { RequiredFields = new List <string>() }; Config.Validate(ConfigSection.MagenicMaqs, configValidation); }
/// <summary> /// Ensure required fields are in the config /// </summary> private static void CheckConfig() { var validator = new ConfigValidation() { RequiredFields = new List <string>() { "WebSiteBase" } }; Config.Validate(ConfigSection.SeleniumMaqs, validator); }
public void ConfigFieldsMissing() { ConfigValidation configValidation = new ConfigValidation() { RequiredFields = new List <string> { "Invalid_Config_Field_For_Validation" } }; Config.Validate(ConfigSection.WebServiceMaqs, configValidation); }
/// <summary> /// Logic to check for required values in app.config /// </summary> private static void CheckConfig() { var validator = new ConfigValidation() { RequiredFields = new System.Collections.Generic.List <string>() { "WebServiceTimeout", "WebServiceUri" } }; Config.Validate(ConfigSection.WebServiceMaqs, validator); }
/// <summary> /// Ensure required fields are in the config /// </summary> private static void CheckConfig() { var validator = new ConfigValidation() { RequiredOneOfFields = new List <string>() { "App", "BrowserName" } }; Config.Validate(ConfigSection.AppiumMaqs, validator); }
/// <summary> /// Ensure required fields are in the config /// </summary> private static void CheckConfig() { var validator = new ConfigValidation() { RequiredFields = new List <string>() { "DataBaseConnectionString", "DataBaseProviderType" } }; Config.Validate(ConfigSection.DatabaseMaqs, validator); }
/// <summary> /// Ensure required fields are in the config /// </summary> private static void CheckConfig() { var validator = new ConfigValidation() { RequiredFields = new List <string>() { "MongoConnectionString", "MongoDatabase", "MongoCollection" } }; Config.Validate(ConfigSection.MongoMaqs, validator); }
/// <summary> /// Ensure required fields are in the config /// </summary> private static void CheckConfig() { var validator = new ConfigValidation() { RequiredFields = new List <string>() { "EmailHost", "EmailUserName", "EmailPassword" } }; Config.Validate(ConfigSection.EmailMaqs, validator); }
/// <summary> /// Ensure required fields are in the config /// </summary> private static void CheckConfig() { var validator = new ConfigValidation() { RequiredFields = new List <string>() { "PlatformName", "PlatformVersion", "DeviceName" } }; Config.Validate(ConfigSection.AppiumMaqs, validator); }
protected override void Setup(FeatureConfigurationContext context) { var settings = context.Settings; settings.EnableFeature <StorageType.Subscriptions>(); var connectionBuilder = settings.GetConnectionBuilder(); var tablePrefix = settings.GetTablePrefix(); var sqlVariant = settings.GetSqlVariant(); var schema = settings.GetSchema(); var cacheFor = SubscriptionSettings.GetCacheFor(settings); var persister = new SubscriptionPersister(connectionBuilder, tablePrefix, sqlVariant, schema, cacheFor); ConfigValidation.ValidateTableSettings(sqlVariant, tablePrefix, schema); context.Container.RegisterSingleton(typeof(ISubscriptionStorage), persister); }
protected override void Setup(FeatureConfigurationContext context) { var settings = context.Settings; settings.EnableFeature <StorageType.Timeouts>(); var sqlVariant = settings.GetSqlVariant(); var connectionBuilder = settings.GetConnectionBuilder(); var tablePrefix = settings.GetTablePrefix(); var schema = settings.GetSchema(); var timeoutsCleanupExecutionInterval = context.Settings.GetOrDefault <TimeSpan?>("SqlPersistence.Timeout.CleanupExecutionInterval") ?? TimeSpan.FromMinutes(2); ConfigValidation.ValidateTableSettings(sqlVariant, tablePrefix, schema); var persister = new TimeoutPersister(connectionBuilder, tablePrefix, sqlVariant, schema, timeoutsCleanupExecutionInterval); context.Container.RegisterSingleton(typeof(IPersistTimeouts), persister); context.Container.RegisterSingleton(typeof(IQueryTimeouts), persister); }
public async Task Install(string identity) { var connectionBuilder = settings.GetConnectionBuilder(); var sqlVariant = settings.GetSqlVariant(); var schema = settings.GetSchema(); var scriptDirectory = ScriptLocation.FindScriptDirectory(sqlVariant); var tablePrefix = settings.GetTablePrefix(); ConfigValidation.ValidateTableSettings(sqlVariant, tablePrefix, schema); using (var connection = await connectionBuilder.OpenConnection().ConfigureAwait(false)) using (var transaction = connection.BeginTransaction()) { await InstallOutbox(scriptDirectory, connection, transaction, tablePrefix, schema, sqlVariant).ConfigureAwait(false); await InstallSagas(scriptDirectory, connection, transaction, tablePrefix, schema, sqlVariant).ConfigureAwait(false); await InstallSubscriptions(scriptDirectory, connection, transaction, tablePrefix, schema, sqlVariant).ConfigureAwait(false); await InstallTimeouts(scriptDirectory, connection, transaction, tablePrefix, schema, sqlVariant).ConfigureAwait(false); transaction.Commit(); } }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "message")] HttpRequestMessage req, TraceWriter log) { log.Info("C# HTTP trigger function processed a request."); // validate the required environment variables var envVariables = Environment.GetEnvironmentVariables(); ValidationResult envVarValidationResult = new ConfigValidation().Validate(envVariables); var envVarValidationResponse = new ValidationResponse("Validation failure", envVarValidationResult.Errors.ToDictionary(x => x.PropertyName, x => x.ErrorMessage)); // return a 400 with the validation errors if (!envVarValidationResult.IsValid) { return(req.CreateResponse(HttpStatusCode.BadRequest, envVarValidationResponse)); } // read variables from app settings EventTopic = Environment.GetEnvironmentVariable("EventTopic", EnvironmentVariableTarget.Process); EventTopicUrl = Environment.GetEnvironmentVariable("EventTopicUrl", EnvironmentVariableTarget.Process); EventTopicSasKey = Environment.GetEnvironmentVariable("EventTopicSasKey", EnvironmentVariableTarget.Process); // parse query parameters log.Info("Parsing query parameters"); string name = req.GetQueryNameValuePairs() .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0) .Value; string email = req.GetQueryNameValuePairs() .FirstOrDefault(q => string.Compare(q.Key, "email", true) == 0) .Value; string message = req.GetQueryNameValuePairs() .FirstOrDefault(q => string.Compare(q.Key, "message", true) == 0) .Value; // parse request body parameters log.Info("Parsing request body parameters"); dynamic data = await req.Content.ReadAsAsync <object>(); name = name ?? data.name; email = email ?? data.email; message = message ?? data.message; // construct message object var messageRequest = new Message(name, email, message); // validation ValidationResult results = new MessageValidation().Validate(messageRequest); // create a custom validation response using key value pairs var validationResponse = new ValidationResponse("Validation failure", results.Errors.ToDictionary(x => x.PropertyName, x => x.ErrorMessage)); // return a 400 with the validation errors if (!results.IsValid) { return(req.CreateResponse(HttpStatusCode.BadRequest, validationResponse)); } // send event to event grid var events = new List <Event <Message> >(); var eventMessage = new Event <Message> { Id = Guid.NewGuid().ToString(), Topic = EventTopic, Subject = "/azContactForm/", EventType = "AzContactForm.NewMessage", EventTime = DateTimeOffset.Now.ToString("o"), Data = messageRequest }; events.Add(eventMessage); HttpClient httpClient = new HttpClient { BaseAddress = new Uri(EventTopicUrl) }; var json = JsonConvert.SerializeObject(events); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, ""); request.Headers.Add("aeg-sas-key", EventTopicSasKey); request.Content = new StringContent(json, Encoding.UTF8, "application/json"); await httpClient.SendAsync(request) .ContinueWith(responseTask => { Console.WriteLine("Response: {0}", responseTask.Result); log.Info("Sent Event to Event Grid"); }); // return a 200 response message return(req.CreateResponse(HttpStatusCode.OK, "Your message has been sent. Thank you.")); }
private ConfigValidation ValidateConfig(Config config, string value) { var validation = new ConfigValidation() { Error = string.Empty, Valid = true }; // With the exception of "int" and "string" config types, all other types have // values that are selected and not entered. "int" is the only one we need to verify switch (config.Type) { case "bool[]": case "bool": case "string[]": case "string": break; case "int": int intOut; if (!int.TryParse(value, out intOut)) { validation.Error = string.Format("{0} » {1} requires a valid number.", config.Group, config.Name); validation.FieldError = "Enter a valid number."; validation.Valid = false; } break; } return validation; }
public ValidationResult ValidateAllProjects(XElement xmlRuleConfigs, params string[] projectFilePaths) { var errors = new List <string>(); ConfigValidation.ValidateConfigSectionForAllowedElements(xmlRuleConfigs, errors, Id, NuspecTagName, PackageProjectException.ExceptionTagName); if (errors.Any()) { return(new ValidationResult(Id, true, true, errors.ToArray())); } var config = RuleConfiguration.Parse(xmlRuleConfigs); if (!config.IsEnabled) { return(new ValidationResult(Id, false, false, new string[0])); } var projectAndPackages = GetProjectToPackagesMap(projectFilePaths.Where(File.Exists)); foreach (var nuspecTag in config.Specs) { var exceptions = config.Exceptions.Concat(nuspecTag.Exceptions).ToArray(); var packageFiles = projectAndPackages .Select(kv => kv.Value.WithoutExceptions(exceptions, kv.Key)) .ToList(); var packageToVersions = GetPackageToAllowedVersion(packageFiles); foreach (var specPathesPattern in nuspecTag.Pathes) { var resolvedNuspecPathes = GetNuspecFiles(specPathesPattern); if (ReferenceEquals(resolvedNuspecPathes, null)) { errors.Add($"Unable to find nuspec files by using pattern {specPathesPattern}"); continue; } foreach (var nuspecFilePath in resolvedNuspecPathes) { var nuspecFile = NuspecFileData.ReadFile(nuspecFilePath); foreach (var dependency in nuspecFile.Dependencies) { var packageId = dependency.PackageId; if (!packageToVersions.ContainsKey(packageId)) { continue; } var allowedVersions = packageToVersions[packageId]; var version = dependency.PackageVersion; if (allowedVersions.Contains(version)) { continue; } errors.Add($"There is inconsistent between Nuspec file {nuspecFilePath} and solution. Nuspec has dependency '{packageId}' with version '{version}'. Solution has the same packages, but with versions: {string.Join(" ,", allowedVersions)}"); } } } } return(new ValidationResult(Id, true, false, errors.ToArray())); }