public void AddValidation_DoesNotTrounceExistingAttributes() { // Arrange var attribute = new RemoteAttribute("Action", "Controller", "AnotherArea") { HttpMethod = "PUT", }; var context = GetValidationContextWithArea(currentArea: "Test"); context.Attributes.Add("data-val", "original"); context.Attributes.Add("data-val-remote", "original"); context.Attributes.Add("data-val-remote-additionalfields", "original"); context.Attributes.Add("data-val-remote-type", "original"); context.Attributes.Add("data-val-remote-url", "original"); // Act attribute.AddValidation(context); // Assert Assert.Collection( context.Attributes, kvp => { Assert.Equal("data-val", kvp.Key); Assert.Equal("original", kvp.Value); }, kvp => { Assert.Equal("data-val-remote", kvp.Key); Assert.Equal("original", kvp.Value); }, kvp => { Assert.Equal("data-val-remote-additionalfields", kvp.Key); Assert.Equal("original", kvp.Value); }, kvp => { Assert.Equal("data-val-remote-type", kvp.Key); Assert.Equal("original", kvp.Value); }, kvp => { Assert.Equal("data-val-remote-url", kvp.Key); Assert.Equal("original", kvp.Value); }); }
public void CreateValidationMetadata(ValidationMetadataProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Key.ContainerType != null && !context.Key.ContainerType.IsValueType) { var viewConfig = ServiceLocator.GetViewConfigure(context.Key.ContainerType); if (viewConfig != null && context.Key.Name.IsNotNullAndWhiteSpace()) { var descriptor = viewConfig.GetViewPortDescriptor(context.Key.Name); if (descriptor != null) { descriptor.Validator.Each(v => { v.DisplayName = descriptor.DisplayName; if (v is RangeValidator) { RangeValidator valid = (RangeValidator)v; RangeAttribute range = new RangeAttribute(valid.Min, valid.Max); range.ErrorMessage = valid.ErrorMessage; context.ValidationMetadata.ValidatorMetadata.Add(range); } else if (v is RegularValidator) { RegularValidator valid = (RegularValidator)v; RegularExpressionAttribute regular = new RegularExpressionAttribute(valid.Expression); regular.ErrorMessage = valid.ErrorMessage; context.ValidationMetadata.ValidatorMetadata.Add(regular); } else if (v is RemoteValidator) { RemoteValidator valid = (RemoteValidator)v; RemoteAttribute remote = new RemoteAttribute(valid.Action, valid.Controller, valid.Area); remote.ErrorMessage = valid.ErrorMessage; context.ValidationMetadata.ValidatorMetadata.Add(remote); } else if (v is RequiredValidator) { RequiredValidator valid = (RequiredValidator)v; RequiredAttribute required = new RequiredAttribute(); required.ErrorMessage = valid.ErrorMessage; context.ValidationMetadata.ValidatorMetadata.Add(required); } else if (v is StringLengthValidator) { StringLengthValidator valid = (StringLengthValidator)v; StringLengthAttribute stringLength = new StringLengthAttribute(valid.Max); stringLength.ErrorMessage = valid.ErrorMessage; context.ValidationMetadata.ValidatorMetadata.Add(stringLength); } }); } } } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { //ConfigurationRoot configurationRoot = new ConfigurationRoot(null); //ConfigurationSection configurationSection = new ConfigurationSection(configurationRoot, ""); //JsonSerializerSettings serializerSettings = new JsonSerializerSettings(); //JsonResult jr = new JsonResult("", serializerSettings); //jr.SerializerSettings = serializerSettings; log.LogInformation($"C# HTTP trigger function processed a request.{Environment.SpecialFolder.ProgramFiles}"); DefaultHttpRequest defaultHttpRequest = new DefaultHttpRequest(new DefaultHttpContext()); log.LogInformation($"C# HTTP trigger function accessing defaultHttpRequest method: {defaultHttpRequest.Method}"); RemoteAttribute remoteAttribute = new RemoteAttribute("sdfsdf"); var castRemoteAttribute = remoteAttribute as ValidationAttribute; var castRemoteAttribute2 = remoteAttribute as IClientModelValidator; var queryParamsDictionary = new Dictionary <string, StringValues>() { { "key1", "val1" }, { "key2", "val" } }; IHostingEnvironment he = null; //StaticFileMiddleware sf = new StaticFileMiddleware(null, he, null, null); QueryCollection qc = new QueryCollection(queryParamsDictionary); log.LogInformation($"C# HTTP trigger function accessing qc:{qc.Count}"); //HtmlHelper hh = new HtmlHelper log.LogInformation($"{GoogleDefaults.AuthenticationScheme}"); IDataReader reader; JObject x = new JObject(); //ODataMessageWriterSettings settings = new ODataMessageWriterSettings(); //SqlConnection connection = new SqlConnection(""); string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; string responseMessage = string.IsNullOrEmpty(name) ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." : $"Hello, {name}. C# HTTP trigger function accessing defaultHttpRequest method and qc and special folder"; //throw new Exception("test ex"); log.LogError(new Exception("testex"), "failed"); return(new OkObjectResult(responseMessage)); }
private bool HasRPCModeSet(MemberInfo Member) { MasterAttribute MasterAtr = Member.GetCustomAttribute(typeof(MasterAttribute)) as MasterAttribute; MasterSyncAttribute MasterSyncAtr = Member.GetCustomAttribute(typeof(MasterSyncAttribute)) as MasterSyncAttribute; PuppetAttribute PuppetAtr = Member.GetCustomAttribute(typeof(PuppetAttribute)) as PuppetAttribute; PuppetSyncAttribute PuppetSyncAtr = Member.GetCustomAttribute(typeof(PuppetSyncAttribute)) as PuppetSyncAttribute; RemoteAttribute RemoteAtr = Member.GetCustomAttribute(typeof(RemoteAttribute)) as RemoteAttribute; RemoteSyncAttribute RemoteSyncAtr = Member.GetCustomAttribute(typeof(RemoteSyncAttribute)) as RemoteSyncAttribute; return(MasterAtr != null || MasterSyncAtr != null || PuppetAtr != null || PuppetSyncAtr != null || RemoteAtr != null || RemoteSyncAtr != null); }
private bool HasRPCModeSet(MemberInfo Member) { MasterAttribute MasterAtr = MDReflectionCache.GetCustomAttribute <MasterAttribute>(Member) as MasterAttribute; MasterSyncAttribute MasterSyncAtr = MDReflectionCache.GetCustomAttribute <MasterSyncAttribute>(Member) as MasterSyncAttribute; PuppetAttribute PuppetAtr = MDReflectionCache.GetCustomAttribute <PuppetAttribute>(Member) as PuppetAttribute; PuppetSyncAttribute PuppetSyncAtr = MDReflectionCache.GetCustomAttribute <PuppetSyncAttribute>(Member) as PuppetSyncAttribute; RemoteAttribute RemoteAtr = MDReflectionCache.GetCustomAttribute <RemoteAttribute>(Member) as RemoteAttribute; RemoteSyncAttribute RemoteSyncAtr = MDReflectionCache.GetCustomAttribute <RemoteSyncAttribute>(Member) as RemoteSyncAttribute; return(MasterAtr != null || MasterSyncAtr != null || PuppetAtr != null || PuppetSyncAtr != null || RemoteAtr != null || RemoteSyncAtr != null); }
public void GuardClauses() { // Act & Assert Assert.ThrowsArgumentNullOrEmpty( () => new RemoteAttribute(null, "controller"), "action"); Assert.ThrowsArgumentNullOrEmpty( () => new RemoteAttribute("action", null), "controller"); Assert.ThrowsArgumentNullOrEmpty( () => new RemoteAttribute(null), "routeName"); Assert.ThrowsArgumentNullOrEmpty( () => RemoteAttribute.FormatPropertyForClientValidation(String.Empty), "property"); Assert.ThrowsArgumentNullOrEmpty( () => new RemoteAttribute("foo").FormatAdditionalFieldsForClientValidation(String.Empty), "property"); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (For != null) { RemoteAttribute remoteAttribute = For.Metadata.ValidatorMetadata.Where(x => x is RemoteAttribute).FirstOrDefault() as RemoteAttribute; if (remoteAttribute != null) { if (output.Attributes.ContainsName("data-valmsg-for-group")) { output.Attributes.SetAttribute("data-valmsg-for-group", remoteAttribute.RemoteName); } else { output.Attributes.Add("data-valmsg-for-group", remoteAttribute.RemoteName); } } base.Process(context, output); } }
public void CreateValidationMetadata(ValidationMetadataProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (context.Key.ContainerType != null && !context.Key.ContainerType.IsValueType) { var viewConfig = ServiceLocator.GetViewConfigure(context.Key.ContainerType); if (viewConfig != null && context.Key.Name.IsNotNullAndWhiteSpace()) { var descriptor = viewConfig.GetViewPortDescriptor(context.Key.Name); if (descriptor != null) { descriptor.Validator.Each(v => { if (v.DisplayName == null) { v.DisplayName = () => descriptor.DisplayName; } string encodeError = Convert.ToBase64String(JsonConvert.SerializeObject(new Mapping(v.Name, v.Property)).ToByte()); if (v is RangeValidator rangeValid) { RangeAttribute range = new RangeAttribute(rangeValid.Min, rangeValid.Max); range.ErrorMessage = encodeError; context.ValidationMetadata.ValidatorMetadata.Add(range); } else if (v is RegularValidator regularValid) { RegularExpressionAttribute regular = new RegularExpressionAttribute(regularValid.Expression); regular.ErrorMessage = encodeError; context.ValidationMetadata.ValidatorMetadata.Add(regular); } else if (v is RemoteValidator remoteValid) { RemoteAttribute remote = new RemoteAttribute(remoteValid.Action, remoteValid.Controller, remoteValid.Area); remote.ErrorMessage = encodeError; context.ValidationMetadata.ValidatorMetadata.Add(remote); } else if (v is RequiredValidator) { RequiredAttribute required = new RequiredAttribute(); required.ErrorMessage = encodeError; context.ValidationMetadata.ValidatorMetadata.Add(required); } else if (v is StringLengthValidator stringLengthValid) { StringLengthAttribute stringLength = new StringLengthAttribute(stringLengthValid.Max); stringLength.ErrorMessage = encodeError; context.ValidationMetadata.ValidatorMetadata.Add(stringLength); } else { CustomValidationHandler customValidationHandler = new CustomValidationHandler(v.Validate); customValidationHandler.ErrorMessage = encodeError; context.ValidationMetadata.ValidatorMetadata.Add(customValidationHandler); } //todo: CompareAttribute }); } } } }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation($"C# HTTP trigger function processed a request.{Process.GetCurrentProcess().Id}"); //ConfigurationRoot configurationRoot = new ConfigurationRoot(null); //ConfigurationSection configurationSection = new ConfigurationSection(configurationRoot, ""); //JsonSerializerSettings serializerSettings = new JsonSerializerSettings(); //JsonResult jr = new JsonResult("", serializerSettings); //jr.SerializerSettings = serializerSettings; RemoteAttribute remoteAttribute = new RemoteAttribute("sdfsdf"); var castRemoteAttribute = remoteAttribute as ValidationAttribute; var castRemoteAttribute2 = remoteAttribute as IClientModelValidator; ClientModelValidationContext context = null; castRemoteAttribute2.AddValidation(context); IHostingEnvironment he = null; //StaticFileMiddleware sf = new StaticFileMiddleware(null, he, null, null); //DefaultHttpRequest defaultHttpRequest = new DefaultHttpRequest(new DefaultHttpContext()); //FacebookOptions fbOptions = new FacebookOptions(); //DatabaseErrorPageMiddleware databaseErrorPageMiddleware = new DatabaseErrorPageMiddleware(null, null, null); //databaseErrorPageMiddleware.IsArray(); //log.LogInformation($"{fbOptions.AppId}"); //GoogleOptions googleOptions = new GoogleOptions(); //log.LogInformation($"{googleOptions.ClientId}"); //UIFrameworkAttribute uIFrameworkAttribute = new UIFrameworkAttribute(""); //AnalysisMiddleware analysisMiddleware = new AnalysisMiddleware(null, null, ""); //NodeServicesOptions nodeServicesOptions = new NodeServicesOptions(null); //FeatureMap featureMap = new OwinEnvironment.FeatureMap(null, null); //var buffer = Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal.KestrelMemoryPool.Create(); //log.LogInformation($"{ListenType.FileHandle}"); //SpaOptions spaOptions = new SpaOptions(); //log.LogInformation($"{spaOptions.DefaultPage}"); //WsFederationConfiguration wsFederationConfiguration = new WsFederationConfiguration(); //log.LogInformation($"{wsFederationConfiguration.GetType()}"); //SamlAction samlAction = new SamlAction(""); //EnvelopedSignatureReader envelopedSignatureReader = new EnvelopedSignatureReader(null); //var webSocket = System.Net.WebSockets.WebSocketProtocol.CreateFromStream(null, true, null, TimeSpan.Zero); IDataReader reader; JObject x = new JObject(); // SqlServerCacheOptions sqlServerCacheOptions = new SqlServerCacheOptions(); //log.LogInformation($"sqlServerCacheOption:{sqlServerCacheOptions.SystemClock}"); //ODataMessageWriterSettings settings = new ODataMessageWriterSettings(); SqlConnection connection = new SqlConnection(""); string name = req.Query["name"]; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; string responseMessage = string.IsNullOrEmpty(name) ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response." : $"Hello, {name}. This HTTP triggered function executed successfully."; //throw new Exception("test ex"); return(new OkObjectResult(responseMessage)); }