Fixed null reference on ModelStateDictionary.ChildNodes when calling Clear
This commit is contained in:
parent
abf9319e6c
commit
b6794ab1b7
|
|
@ -633,7 +633,7 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
||||||
HasRecordedMaxModelError = false;
|
HasRecordedMaxModelError = false;
|
||||||
ErrorCount = 0;
|
ErrorCount = 0;
|
||||||
_root.Reset();
|
_root.Reset();
|
||||||
_root.ChildNodes.Clear();
|
_root.ChildNodes?.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,22 @@ namespace Microsoft.AspNetCore.Mvc.ModelBinding
|
||||||
Assert.Equal(ModelValidationState.Valid, dictionary.ValidationState);
|
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]
|
[Fact]
|
||||||
public void MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsUnvalidated()
|
public void MarkFieldSkipped_MarksFieldAsSkipped_IfStateIsUnvalidated()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue