"景先生毕设|www.jxszl.com

C# ActionContext类代码示例

2023-12-29 16:58编辑: www.jxszl.com景先生毕设
本文整理汇总了C#中ActionContext类的典型用法代码示例。如果您正苦于以下问题:C# ActionContext类的具体用法?C# ActionContext怎么用?C# ActionContext使用的例子? 这里精选的类代码示例或许可以为您提供帮助。 示例1: AddValidation_DoesNotTrounceExistingAttributes public void AddValidation_DoesNotTrounceExistingAttributes() { // Arrange var provider = TestModelMetadataProvider.CreateDefaultProvider(); var metadata = provider.GetMetadataForProperty(typeof(string), "Length"); var attribute = new RangeAttribute(typeof(decimal), "0", "100"); attribute.ErrorMessage = "The field Length must be between {1} and {2}."; var adapter = new RangeAttributeAdapter(attribute, stringLocalizer: null); var actionContext = new ActionContext(); var context = new ClientModelValidationContext(actionContext, metadata, provider, new AttributeDictionary()); context.Attributes.Add("data-val", "original"); context.Attributes.Add("data-val-range", "original"); context.Attributes.Add("data-val-range-max", "original"); context.Attributes.Add("data-val-range-min", "original"); // Act adapter.AddValidation(context); // Assert Assert.Collection( context.Attributes, kvp => { Assert.Equal("data-val", kvp.Key); Assert.Equal("original", kvp.Value); }, kvp => { Assert.Equal("data-val-range", kvp.Key); Assert.Equal("original", kvp.Value); }, kvp => { Assert.Equal("data-val-range-max", kvp.Key); Assert.Equal("original", kvp.Value); }, kvp => { Assert.Equal("data-val-range-min", kvp.Key); Assert.Equal("original", kvp.Value); }); }
原文链接:http://www.jxszl.com/biancheng/C/556455.html