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


C# ModelStateDictionary.MarkFieldSkipped方法代码示例

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


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

示例1: MarkFieldSkipped_MarksFieldAsSkipped_IfKeyIsNotPresent

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

            var source = new ModelStateDictionary();

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

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

示例2: MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsNotInValid

        public void MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsNotInValid(ModelValidationState validationState)
        {
            // Arrange
            var entry = new ModelStateEntry
            {
                ValidationState = validationState
            };

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

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

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

示例3: MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsNotInValid

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

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

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

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

示例4: MarkFieldSkipped_Throws_IfStateIsInvalid

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

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

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

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

示例5: MarkFieldSkipped_MarksFieldAsSkipped_IfKeyIsNotPresent

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

            var source = new ModelStateDictionary
            {
            };

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

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

示例6: ModelStateDictionary_ClearEntries_KeyHasDot_NonEmptyKey

        public void ModelStateDictionary_ClearEntries_KeyHasDot_NonEmptyKey()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("Product");
            dictionary.AddModelError("Product.Detail1", "Product Detail1 invalid.");
            dictionary.AddModelError("Product.Detail1.Name", "Product Detail1 Name invalid.");
            dictionary.MarkFieldSkipped("Product.Detail1Name");

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

            // Assert
            Assert.Equal(ModelValidationState.Valid, dictionary["Product"].ValidationState);
            Assert.Equal(0, dictionary["Product.Detail1"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail1"].ValidationState);
            Assert.Equal(0, dictionary["Product.Detail1.Name"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Product.Detail1.Name"].ValidationState);
            Assert.Equal(ModelValidationState.Skipped, dictionary["Product.Detail1Name"].ValidationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:20,代码来源:ModelStateDictionaryTest.cs

示例7: 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

示例8: 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

示例9: MarkFieldSkipped_Throws_IfStateIsInvalid

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

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

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

示例10: MarkFieldValid_MarksFieldAsValid_IfStateIsSkipped

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

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

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

示例11: KeysEnumerable_ReturnsAllKeys

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

            // Act
            var keys = dictionary.Keys;

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

示例12: IsValidPropertyReturnsTrueIfNoErrors

        public void IsValidPropertyReturnsTrueIfNoErrors()
        {
            // Arrange
            var dictionary = new ModelStateDictionary();
            dictionary.MarkFieldValid("foo");
            dictionary.MarkFieldSkipped("bar");

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

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

示例13: 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

示例14: ContainsKey_ReturnsTrue_IfNodeHasBeenMutated

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

            // Act
            var result = dictionary.ContainsKey(key);

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

示例15: ModelStateDictionary_ClearsAllEntries_EmptyKey

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

            // Act
            dictionary.ClearValidationState(modelKey);

            // 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(0, dictionary["Property3"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property3"].ValidationState);
            Assert.Equal(0, dictionary["Property4"].Errors.Count);
            Assert.Equal(ModelValidationState.Unvalidated, dictionary["Property4"].ValidationState);
        }
开发者ID:ymd1223,项目名称:Mvc,代码行数:22,代码来源:ModelStateDictionaryTest.cs


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