Fixed null reference on ModelStateDictionary.ChildNodes when calling Clear

This commit is contained in:
Michiel Post 2016-05-18 16:59:49 +02:00 committed by Pranav K
parent abf9319e6c
commit b6794ab1b7
2 changed files with 17 additions and 1 deletions

View File

@ -633,7 +633,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
HasRecordedMaxModelError = false;
ErrorCount = 0;
_root.Reset();
_root.ChildNodes.Clear();
_root.ChildNodes?.Clear();
}
/// <inheritdoc />

View File

@ -125,6 +125,22 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
Assert.Equal(ModelValidationState.Valid, dictionary.ValidationState);
}
[Fact]
public void Clear_RemovesAllEntries_IfDictionaryIsEmpty()
{
// Arrange
var dictionary = new ModelStateDictionary();
// Act
dictionary.Clear();
// Assert
Assert.Equal(0, dictionary.Count);
Assert.Equal(0, dictionary.ErrorCount);
Assert.Empty(dictionary);
Assert.Equal(ModelValidationState.Valid, dictionary.ValidationState);
}
[Fact]
public void MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsUnvalidated()
{