当前位置: 首页>>代码示例>>C#>>正文


C# ModelStateDictionary.MarkFieldValid方法代码示例

本文整理汇总了C#中ModelStateDictionary.MarkFieldValid方法的典型用法代码示例。如果您正苦于以下问题:C# ModelStateDictionary.MarkFieldValid方法的具体用法?C# ModelStateDictionary.MarkFieldValid怎么用?C# ModelStateDictionary.MarkFieldValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModelStateDictionary的用法示例。


在下文中一共展示了ModelStateDictionary.MarkFieldValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MarkFieldValid_Throws_IfStateIsInvalid

        public void MarkFieldValid_Throws_IfStateIsInvalid()
        {
            // Arrange
            var source = new ModelStateDictionary();
            source.AddModelError("key", "some-error");

            // Act
            var exception = Assert.Throws<InvalidOperationException>(() => source.MarkFieldValid("key"));

            // Assert
            Assert.Equal(
                "A field previously marked invalid should not be marked valid.",
                exception.Message);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:14,代码来源:ModelStateDictionaryTest.cs

示例2: ModelStateDictionary_ClearEntriesPrefixedWithKey_NonEmptyKey

        public void ModelStateDictionary_ClearEntriesPrefixedWithKey_NonEmptyKey()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("Product");
            dictionary.AddModelError("Product.Detail1", "Product Detail1 invalid.");
            dictionary.AddModelError("Product.Detail2[0]", "Product Detail2[0] invalid.");
            dictionary.AddModelError("Product.Detail2[1]", "Product Detail2[1] invalid.");
            dictionary.MarkFieldSkipped("Product.Detail2[2]");
            dictionary.MarkFieldSkipped("Product.Detail3");
            dictionary.AddModelError("ProductName", "ProductName invalid.");

            // Act
            dictionary.ClearValidationState("Product");

            // Assert
            Assert.Equal(0, dictionary["Product"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product"].ValidationState);
            Assert.Equal(0, dictionary["Product.Detail1"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail1"].ValidationState);
            Assert.Equal(0, dictionary["Product.Detail2[0]"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail2[0]"].ValidationState);
            Assert.Equal(0, dictionary["Product.Detail2[1]"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail2[1]"].ValidationState);
            Assert.Equal(0, dictionary["Product.Detail2[2]"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail2[2]"].ValidationState);
            Assert.Equal(0, dictionary["Product.Detail3"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail3"].ValidationState);
            Assert.Equal(1, dictionary["ProductName"].Errors.Count);
            Assert.Equal(ModelValidationState.Invalid, dictionary["ProductName"].ValidationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:31,代码来源:ModelStateDictionaryTest.cs

示例3: MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsValid

        public void MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsValid()
        {
            // Arrange
            var source = new ModelStateDictionary();
            source.MarkFieldValid("key");

            // Act
            source.MarkFieldSkipped("key");

            // Assert
            Assert.Equal(ModelValidationState.Skipped, source["key"].ValidationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:12,代码来源:ModelStateDictionaryTest.cs

示例4: MarkFieldValid_MarksFieldAsValid_IfStateIsUnvalidated

        public void MarkFieldValid_MarksFieldAsValid_IfStateIsUnvalidated()
        {
            // Arrange
            var source = new ModelStateDictionary();
            source.SetModelValue("key", "value", "value");

            // Act
            source.MarkFieldValid("key");

            // Assert
            Assert.Equal(ModelValidationState.Valid, source["key"].ValidationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:12,代码来源:ModelStateDictionaryTest.cs

示例5: MarkFieldValid_Throws_IfStateIsInvalid

        public void MarkFieldValid_Throws_IfStateIsInvalid()
        {
            // Arrange
            var entry = new ModelStateEntry
            {
                ValidationState = ModelValidationState.Invalid
            };

            var source = new ModelStateDictionary
            {
                { "key",  entry }
            };

            // Act
            var exception = Assert.Throws<InvalidOperationException>(() => source.MarkFieldValid("key"));

            // Assert
            Assert.Equal(
                "A field previously marked invalid should not be marked valid.",
                exception.Message);
        }
开发者ID:huoxudong125,项目名称:Mvc,代码行数:21,代码来源:ModelStateDictionaryTest.cs

示例6: GetEnumerable_ReturnsAllNonContainerNodes

        public void GetEnumerable_ReturnsAllNonContainerNodes()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("Property1");
            dictionary.SetModelValue("Property1.Property2", "value", "value");
            dictionary.AddModelError("Property2", "Property invalid.");
            dictionary.AddModelError("Property2[Property3]", "Property2[Property3] invalid.");
            dictionary.MarkFieldSkipped("Property4");
            dictionary.Remove("Property2");

            // Act & Assert
            Assert.Collection(
                dictionary,
                entry =>
                {
                    Assert.Equal("Property1", entry.Key);
                    Assert.Equal(ModelValidationState.Valid, entry.Value.ValidationState);
                    Assert.Null(entry.Value.RawValue);
                    Assert.Null(entry.Value.AttemptedValue);
                    Assert.Empty(entry.Value.Errors);
                },
                entry =>
                {
                    Assert.Equal("Property4", entry.Key);
                    Assert.Equal(ModelValidationState.Skipped, entry.Value.ValidationState);
                    Assert.Null(entry.Value.RawValue);
                    Assert.Null(entry.Value.AttemptedValue);
                    Assert.Empty(entry.Value.Errors);
                },
                entry =>
                {
                    Assert.Equal("Property1.Property2", entry.Key);
                    Assert.Equal(ModelValidationState.Unvalidated, entry.Value.ValidationState);
                    Assert.Equal("value", entry.Value.RawValue);
                    Assert.Equal("value", entry.Value.AttemptedValue);
                    Assert.Empty(entry.Value.Errors);
                },
                entry =>
                {
                    Assert.Equal("Property2[Property3]", entry.Key);
                    Assert.Equal(ModelValidationState.Invalid, entry.Value.ValidationState);
                    Assert.Null(entry.Value.RawValue);
                    Assert.Null(entry.Value.AttemptedValue);
                    Assert.Collection(entry.Value.Errors,
                        error => Assert.Equal("Property2[Property3] invalid.", error.ErrorMessage));
                });
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:48,代码来源:ModelStateDictionaryTest.cs

示例7: IsValidPropertyReturnsFalseIfErrors

        public void IsValidPropertyReturnsFalseIfErrors()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("foo");
            dictionary.AddModelError("bar", "some error");

            // Act
            var isValid = dictionary.IsValid;
            var validationState = dictionary.ValidationState;

            // Assert
            Assert.False(isValid);
            Assert.Equal(ModelValidationState.Invalid, validationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:15,代码来源:ModelStateDictionaryTest.cs

示例8: MarkFieldValid_MarksFieldAsValid_IfStateIsNotInvalid

        public void MarkFieldValid_MarksFieldAsValid_IfStateIsNotInvalid(ModelValidationState validationState)
        {
            // Arrange
            var modelState = new ModelState
            {
                Value = GetValueProviderResult("value"),
                ValidationState = validationState
            };

            var source = new ModelStateDictionary
            {
                { "key",  modelState }
            };

            // Act
            source.MarkFieldValid("key");

            // Assert
            Assert.Equal(ModelValidationState.Valid, source["key"].ValidationState);
        }
开发者ID:njannink,项目名称:sonarlint-vs,代码行数:20,代码来源:ModelStateDictionaryTest.cs

示例9: GetFieldValidity_ReturnsUnvalidated_IfAnyItemInSubtreeIsInvalid

        public void GetFieldValidity_ReturnsUnvalidated_IfAnyItemInSubtreeIsInvalid()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("user.Address");
            dictionary.SetModelValue("user.Name", new string[] { "some value" }, "some value");
            dictionary.AddModelError("user.Age", "Age is not a valid int");

            // Act
            var validationState = dictionary.GetFieldValidationState("user");

            // Assert
            Assert.Equal(ModelValidationState.Unvalidated, validationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:14,代码来源:ModelStateDictionaryTest.cs

示例10: GetFieldValidity_ReturnsValid_IfAllKeysAreValid

        public void GetFieldValidity_ReturnsValid_IfAllKeysAreValid()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("user.Address");
            dictionary.MarkFieldValid("user.Name");

            // Act
            var validationState = dictionary.GetFieldValidationState("user");

            // Assert
            Assert.Equal(ModelValidationState.Valid, validationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:13,代码来源:ModelStateDictionaryTest.cs

示例11: GetFieldValidity_ReturnsInvalid_IfAllKeysAreValidatedAndAnyEntryIsInvalid_Collection

        public void GetFieldValidity_ReturnsInvalid_IfAllKeysAreValidatedAndAnyEntryIsInvalid_Collection(string key)
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("[0].product.Name");
            dictionary.MarkFieldValid("[0].product.Age[0]");
            dictionary.AddModelError("[0].product.Name", "Name is invalid");

            // Act
            var validationState = dictionary.GetFieldValidationState(key);

            // Assert
            Assert.Equal(ModelValidationState.Invalid, validationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:14,代码来源:ModelStateDictionaryTest.cs

示例12: GetFieldValidity_ReturnsInvalid_IfAllKeysAreValidatedAndAnyEntryIsInvalid

        public void GetFieldValidity_ReturnsInvalid_IfAllKeysAreValidatedAndAnyEntryIsInvalid(string key)
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("user.Address");
            dictionary.MarkFieldValid("user.Name");
            dictionary.AddModelError("user.Age", "Age is not a valid int");

            // Act
            var validationState = dictionary.GetFieldValidationState(key);

            // Assert
            Assert.Equal(ModelValidationState.Invalid, validationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:14,代码来源:ModelStateDictionaryTest.cs

示例13: GetFieldValidationState_ReturnsValidIfModelStateDoesNotContainErrors

        public void GetFieldValidationState_ReturnsValidIfModelStateDoesNotContainErrors(string key)
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid(key);

            // Act
            var validationState = dictionary.GetFieldValidationState("foo");

            // Assert
            Assert.Equal(ModelValidationState.Valid, validationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:12,代码来源:ModelStateDictionaryTest.cs

示例14: ModelStateDictionary_ClearEntriesThatMatchWithKey_NonEmptyKey

        public void ModelStateDictionary_ClearEntriesThatMatchWithKey_NonEmptyKey()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("Property1");
            dictionary.AddModelError("Property2", "Property2 invalid.");
            dictionary.AddModelError("Property3", "Property invalid.");
            dictionary.MarkFieldSkipped("Property4");

            // Act
            dictionary.ClearValidationState("Property1");
            dictionary.ClearValidationState("Property2");
            dictionary.ClearValidationState("Property4");

            // Assert
            Assert.Equal(0, dictionary["Property1"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property1"].ValidationState);
            Assert.Equal(0, dictionary["Property2"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property2"].ValidationState);
            Assert.Equal(1, dictionary["Property3"].Errors.Count);
            Assert.Equal(ModelValidationState.Invalid, dictionary["Property3"].ValidationState);
            Assert.Equal(0, dictionary["Property4"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property4"].ValidationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:24,代码来源:ModelStateDictionaryTest.cs

示例15: IsValidPropertyReturnsFalse_IfSomeFieldsAreNotValidated

        public void IsValidPropertyReturnsFalse_IfSomeFieldsAreNotValidated()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("foo");
            dictionary.SetModelValue("qux", "value", "value");
            dictionary.AddModelError("baz", "some error");

            // Act
            var isValid = dictionary.IsValid;
            var validationState = dictionary.ValidationState;

            // Assert
            Assert.False(isValid);
            Assert.Equal(ModelValidationState.Unvalidated, validationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:16,代码来源:ModelStateDictionaryTest.cs


注:本文中的ModelStateDictionary.MarkFieldValid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。