Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/MiniValidation/MiniValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -592,12 +592,12 @@ private static async Task<bool> TryValidateEnumerable(
throw;
}

isValid = await validateTask.ConfigureAwait(false);

if (!isValid)
var thisOneIsValid = await validateTask.ConfigureAwait(false);
if (!thisOneIsValid)
{
break;
isValid = false;
}

index++;
}
}
Expand Down
65 changes: 64 additions & 1 deletion tests/MiniValidation.UnitTests/TryValidate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ public void Validator_DisplayAttribute_Name_Used_In_Error_Message_For_Record()
}
#endif

[Fact]
public void List_Invalid_When_Entry_Valid()
{
var collectionToValidate = new List<TestType> { new() { RequiredName = "test" } };

var result = MiniValidator.TryValidate(collectionToValidate, out var errors);

Assert.True(result);
}

[Fact]
public void List_Invalid_When_Entry_Invalid()
{
Expand All @@ -180,6 +190,59 @@ public void List_Invalid_When_Entry_Invalid()
Assert.Single(errors);
}

[Fact]
public void List_Invalid_When_Multiple_Entries_Invalid()
{
var collectionToValidate = new List<TestType> { new() { RequiredName = null }, new() { RequiredName = "test", TenOrMore = 5 } };

var result = MiniValidator.TryValidate(collectionToValidate, out var errors);

Assert.False(result);
Assert.Equal(2, errors.Count);
}

[Fact]
public void List_Invalid_When_Dictionary_Entry_Valid()
{
var collectionToValidate = new Dictionary<string, TestType>
{
["key1"] = new() { RequiredName = "test" }
};

var result = MiniValidator.TryValidate(collectionToValidate, out var errors);

Assert.True(result);
}

[Fact]
public void List_Invalid_When_Dictionary_Entry_Invalid()
{
var collectionToValidate = new Dictionary<string, TestType>
{
["key1"] = new() { RequiredName = null }
};

var result = MiniValidator.TryValidate(collectionToValidate, out var errors);

Assert.False(result);
Assert.Single(errors);
}

[Fact]
public void List_Invalid_When_Multiple_Dictionary_Entries_Invalid()
{
var collectionToValidate = new Dictionary<string, TestType>
{
["key1"] = new() { RequiredName = null },
["key2"] = new() { RequiredName = "test", TenOrMore = 5 },
};

var result = MiniValidator.TryValidate(collectionToValidate, out var errors);

Assert.False(result);
Assert.Equal(2, errors.Count);
}

public static TheoryData<object> PrimitiveValues
=> new() {
new object[] { "A string" },
Expand Down Expand Up @@ -453,7 +516,7 @@ public async Task TryValidateAsync_With_Attribute_Attached_Via_TypeDescriptor()
var thingToValidate = new TestTypeForTypeDescriptor();

typeof(TestTypeForTypeDescriptor).AttachAttribute(
nameof(TestTypeForTypeDescriptor.PropertyToBeRequired),
nameof(TestTypeForTypeDescriptor.PropertyToBeRequired),
_ => new RequiredAttribute());

var (isValid, errors) = await MiniValidator.TryValidateAsync(thingToValidate);
Expand Down
Loading