diff --git a/samples/Samples.Console/Program.cs b/samples/Samples.Console/Program.cs index 7900954..f7c283d 100644 --- a/samples/Samples.Console/Program.cs +++ b/samples/Samples.Console/Program.cs @@ -12,7 +12,7 @@ var allValid = true; foreach (var widget in widgets) { - if (!MiniValidator.TryValidate(widget, out var errors)) + if (!MiniValidatorPlus.TryValidate(widget, out var errors)) { allValid = false; Console.WriteLine($"{nameof(Widget)} has errors!"); diff --git a/samples/Samples.Web/Program.cs b/samples/Samples.Web/Program.cs index a202ad6..0a80f61 100644 --- a/samples/Samples.Web/Program.cs +++ b/samples/Samples.Web/Program.cs @@ -24,12 +24,12 @@ new Widget { Name = name }); app.MapPost("/widgets", Results> (Widget widget) => - !MiniValidator.TryValidate(widget, out var errors) + !MiniValidatorPlus.TryValidate(widget, out var errors) ? TypedResults.ValidationProblem(errors) : TypedResults.Created($"/widgets/{widget.Name}", widget)); app.MapPost("/widgets/custom-validation", Results> (WidgetWithCustomValidation widget) => - !MiniValidator.TryValidate(widget, out var errors) + !MiniValidatorPlus.TryValidate(widget, out var errors) ? TypedResults.ValidationProblem(errors) : TypedResults.Created($"/widgets/{widget.Name}", widget)); diff --git a/src/MiniValidationPlus/MiniValidator.cs b/src/MiniValidationPlus/MiniValidatorPlus.cs similarity index 99% rename from src/MiniValidationPlus/MiniValidator.cs rename to src/MiniValidationPlus/MiniValidatorPlus.cs index 5b3dcfd..8e97744 100644 --- a/src/MiniValidationPlus/MiniValidator.cs +++ b/src/MiniValidationPlus/MiniValidatorPlus.cs @@ -13,7 +13,7 @@ namespace MiniValidationPlus; /// Contains methods and properties for performing validation operations with on objects whos properties /// are decorated with s. /// -public static class MiniValidator +public static class MiniValidatorPlus { private static readonly TypeDetailsCache _typeDetailsCache = new(); private static readonly IDictionary _emptyErrors = new ReadOnlyDictionary(new Dictionary()); diff --git a/src/MiniValidationPlus/SkipRecursionAttribute.cs b/src/MiniValidationPlus/SkipRecursionAttribute.cs index 5c58462..7f7440b 100644 --- a/src/MiniValidationPlus/SkipRecursionAttribute.cs +++ b/src/MiniValidationPlus/SkipRecursionAttribute.cs @@ -4,7 +4,7 @@ namespace MiniValidationPlus; /// /// Indicates that a property should be ignored during recursive validation when using -/// . +/// . /// Note that any validation attributes on the property itself will still be validated. /// [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] diff --git a/tests/MiniValidationPlus.Benchmarks/Program.cs b/tests/MiniValidationPlus.Benchmarks/Program.cs index 8af0479..7cd3d3c 100644 --- a/tests/MiniValidationPlus.Benchmarks/Program.cs +++ b/tests/MiniValidationPlus.Benchmarks/Program.cs @@ -22,7 +22,7 @@ public void Initialize() foreach (var type in types) { var target = Activator.CreateInstance(type); - MiniValidator.TryValidate(target, recurse: true, allowAsync: false, out var _); + MiniValidatorPlus.TryValidate(target, recurse: true, allowAsync: false, out var _); } } @@ -30,7 +30,7 @@ public void Initialize() public (bool, IDictionary) NothingToValidate() { var target = new BenchmarkTypes.TodoWithNoValidation(); - var isValid = MiniValidator.TryValidate(target, out var errors); + var isValid = MiniValidatorPlus.TryValidate(target, out var errors); return (isValid, errors); } @@ -38,7 +38,7 @@ public void Initialize() public (bool, IDictionary) SinglePropertyToValidate_NoRecursion_Valid() { var target = new BenchmarkTypes.Todo { Title = "This is the title" }; - var isValid = MiniValidator.TryValidate(target, recurse: false, allowAsync: false, out var errors); + var isValid = MiniValidatorPlus.TryValidate(target, recurse: false, allowAsync: false, out var errors); return (isValid, errors); } @@ -46,7 +46,7 @@ public void Initialize() public (bool, IDictionary) SinglePropertyToValidate_NoRecursion_Invalid() { var target = new BenchmarkTypes.Todo { Title = "" }; - var isValid = MiniValidator.TryValidate(target, recurse: false, allowAsync: false, out var errors); + var isValid = MiniValidatorPlus.TryValidate(target, recurse: false, allowAsync: false, out var errors); return (isValid, errors); } @@ -55,7 +55,7 @@ public void Initialize() { var target = new BenchmarkTypes.Todo { Title = "This is the title" }; target.Tags.Add(new() { Name = "A tag" }); - var isValid = MiniValidator.TryValidate(target, out var errors); + var isValid = MiniValidatorPlus.TryValidate(target, out var errors); return (isValid, errors); } @@ -64,7 +64,7 @@ public void Initialize() { var target = new BenchmarkTypes.Todo { Title = "This is the title" }; target.Tags.Add(new() { Name = "" }); - var isValid = MiniValidator.TryValidate(target, out var errors); + var isValid = MiniValidatorPlus.TryValidate(target, out var errors); return (isValid, errors); } #pragma warning restore CA1822 // Mark members as static diff --git a/tests/MiniValidationPlus.UnitTests/Recursion.cs b/tests/MiniValidationPlus.UnitTests/Recursion.cs index 72be3a9..6b0ebd3 100644 --- a/tests/MiniValidationPlus.UnitTests/Recursion.cs +++ b/tests/MiniValidationPlus.UnitTests/Recursion.cs @@ -9,7 +9,7 @@ public void Recurses_When_Top_Level_Is_Invalid() { var thingToValidate = new TestType { RequiredName = null, Child = new TestChildType { RequiredCategory = null, MinLengthFive = "123" } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Equal(3, errors.Count); @@ -25,7 +25,7 @@ public void Invalid_When_Child_Invalid_And_Recurse_True() { var thingToValidate = new TestType { Child = new TestChildType { RequiredCategory = null, MinLengthFive = "123" } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Equal(2, errors.Count); @@ -36,7 +36,7 @@ public void Invalid_When_Child_Invalid_And_Recurse_Default() { var thingToValidate = new TestType { Child = new TestChildType { RequiredCategory = null } }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -47,7 +47,7 @@ public void Valid_When_Child_Invalid_And_Recurse_False() { var thingToValidate = new TestType { Child = new TestChildType { RequiredCategory = null, MinLengthFive = "123" } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: false, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: false, out var errors); Assert.True(result); Assert.Empty(errors); @@ -58,7 +58,7 @@ public void Valid_When_Child_Invalid_And_Property_Decorated_With_SkipRecursion() { var thingToValidate = new TestType { SkippedChild = new TestChildType { RequiredCategory = null, MinLengthFive = "123" } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: false, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: false, out var errors); Assert.True(result); Assert.Empty(errors); @@ -69,7 +69,7 @@ public void Invalid_When_Enumerable_Item_Invalid_When_Recurse_Default() { var thingToValidate = new List { new() { Child = new TestChildType { RequiredCategory = null, MinLengthFive = "123" } } }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Equal(2, errors.Count); @@ -80,7 +80,7 @@ public void Invalid_When_Enumerable_Item_Invalid_When_Recurse_True() { var thingToValidate = new List { new() { Child = new TestChildType { RequiredCategory = null, MinLengthFive = "123" } } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Equal(2, errors.Count); @@ -91,7 +91,7 @@ public void Valid_When_Enumerable_Item_Invalid_When_Recurse_False() { var thingToValidate = new List { new() { Child = new TestChildType { RequiredCategory = null, MinLengthFive = "123" } } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: false, out _); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: false, out _); Assert.True(result); } @@ -101,7 +101,7 @@ public void Valid_When_Enumerable_Item_Has_Invalid_Descendant_But_Property_Decor { var thingToValidate = new List { new() { SkippedChild = new() { RequiredCategory = null } } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out _); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out _); Assert.True(result); } @@ -116,7 +116,7 @@ public void Error_Message_Keys_For_Descendants_Are_Formatted_Correctly(int maxDe TestChildType.AddDescendents(thingToValidate.Child, maxDepth); - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Single(errors); @@ -135,7 +135,7 @@ public void Error_Message_Keys_For_Root_Enumerable_Are_Formatted_Correctly() new() { RequiredName = null, TenOrMore = 5 }, }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Equal(2, errors.Count); @@ -151,7 +151,7 @@ public void Error_Message_Keys_For_Descendant_Enumerable_Are_Formatted_Correctly thingToValidate.Children.Add(new() { }); thingToValidate.Children.Add(new() { RequiredCategory = null }); - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Single(errors); @@ -168,7 +168,7 @@ public void First_Error_In_Root_Enumerable_Returns_Immediately() new() { RequiredName = null }, }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Single(errors); @@ -183,7 +183,7 @@ public void First_Error_In_Descendant_Enumerable_Returns_Immediately() thingToValidate.Children.Add(new() { MinLengthFive = "123" }); thingToValidate.Children.Add(new() { RequiredCategory = null }); - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Single(errors); @@ -198,7 +198,7 @@ public void All_Errors_From_Invalid_Item_In_Descendant_Enumerable_Reported() thingToValidate.Children.Add(new()); thingToValidate.Children.Add(new() { RequiredCategory = null, MinLengthFive = "123" }); - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Equal(2, errors.Count); @@ -214,7 +214,7 @@ public void Valid_When_Descendant_Invalid_And_Property_Decorated_With_SkipRecurs thingToValidate.Children.Add(new()); thingToValidate.Children.Add(new() { SkippedChild = new() { RequiredCategory = null } }); - var result = MiniValidator.TryValidate(thingToValidate, recurse: false, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: false, out var errors); Assert.True(result); Assert.Empty(errors); @@ -225,7 +225,7 @@ public void Invalid_When_Descendant_Invalid_And_Property_Is_Required_And_Decorat { var thingToValidate = new TestSkippedChildType(); - var result = MiniValidator.TryValidate(thingToValidate, recurse: false, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: false, out var errors); Assert.False(result); Assert.Single(errors); @@ -236,7 +236,7 @@ public void Invalid_When_Derived_Type_Has_Invalid_Inherited_Property() { var thingToValidate = new TestType { Child = new TestChildTypeDerivative { RequiredCategory = null } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Single(errors); @@ -247,7 +247,7 @@ public void Invalid_When_Derived_Type_Has_Invalid_Own_Property() { var thingToValidate = new TestType { Child = new TestChildTypeDerivative { DerivedMinLengthTen = "123" } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, out var errors); Assert.False(result); Assert.Single(errors); @@ -258,7 +258,7 @@ public void Valid_When_Derived_Type_Has_Invalid_Own_Property_With_Recurse_False( { var thingToValidate = new TestType { Child = new TestChildTypeDerivative { DerivedMinLengthTen = "123" } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: false, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: false, out var errors); Assert.True(result); Assert.Empty(errors); @@ -272,7 +272,7 @@ public void Invalid_When_ValidatableObject_Child_Validate_Is_Invalid() ValidatableChild = new TestValidatableChildType { TwentyOrMore = 12 } }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -287,7 +287,7 @@ public void Invalid_When_Derived_ValidatableObject_Child_Validate_Is_Invalid() Child = new TestValidatableChildType { TwentyOrMore = 19 } }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -302,7 +302,7 @@ public void Invalid_When_Derived_Polymorphic_Child_Validate_Is_Invalid() Child = new TestValidatableChildType { MinLengthFive = "123" } }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -318,7 +318,7 @@ public void Child_ValidatableObject_Is_Validated_When_Parent_Is_Invalid() ValidatableChild = new() { TwentyOrMore = 12 } }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Equal(2, errors.Count); @@ -333,7 +333,7 @@ public void Invalid_When_Derived_ValidatableOnlyChild_Is_Invalid() ValidatableOnlyChild = new TestValidatableOnlyType { TwentyOrMore = 12 } }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -348,7 +348,7 @@ public void Invalid_When_Polymorphic_ValidatableOnlyChild_Is_Invalid() PocoChild = new TestValidatableOnlyType { TwentyOrMore = 12 } }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -363,7 +363,7 @@ public void Invalid_When_Polymorphic_Child_With_Validation_Attributes_Is_Invalid PocoChild = new TestChildType { MinLengthFive = "123" } }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -380,7 +380,7 @@ public void Throws_InvalidOperationException_When_AsyncValidatableOnlyChild_Is_I Assert.Throws(() => { - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); }); } @@ -392,7 +392,7 @@ public async Task Invalid_When_AsyncValidatableOnlyChild_Is_Invalid() NeedsAsync = new() { TwentyOrMore = 12 } }; - var (isValid, errors) = await MiniValidator.TryValidateAsync(thingToValidate); + var (isValid, errors) = await MiniValidatorPlus.TryValidateAsync(thingToValidate); Assert.False(isValid); Assert.Single(errors); @@ -407,7 +407,7 @@ public void Invalid_When_AsyncValidatableOnlyChild_Is_Invalid_Allowing_SyncOverA NeedsAsync = new() { TwentyOrMore = 12 } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, allowAsync: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, allowAsync: true, out var errors); Assert.False(result); Assert.Single(errors); @@ -429,7 +429,7 @@ public void Throws_InvalidOperationException_When_Polymorphic_AsyncValidatableOn try { - var result = MiniValidator.TryValidate(thingToValidate, serviceProvider, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, serviceProvider, out var errors); } finally { @@ -446,7 +446,7 @@ public void Invalid_When_Polymorphic_AsyncValidatableOnlyChild_Is_Invalid_Allowi PocoChild = new TestAsyncValidatableChildType { TwentyOrMore = 12 } }; - var result = MiniValidator.TryValidate(thingToValidate, recurse: true, allowAsync: true, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, recurse: true, allowAsync: true, out var errors); Assert.False(result); Assert.Single(errors); @@ -461,7 +461,7 @@ public async Task Invalid_When_Polymorphic_AsyncValidatableOnlyChild_Is_Invalid( PocoChild = new TestAsyncValidatableChildType { TwentyOrMore = 12 } }; - var (isValid, errors) = await MiniValidator.TryValidateAsync(thingToValidate); + var (isValid, errors) = await MiniValidatorPlus.TryValidateAsync(thingToValidate); Assert.False(isValid); Assert.Single(errors); diff --git a/tests/MiniValidationPlus.UnitTests/TryValidate.cs b/tests/MiniValidationPlus.UnitTests/TryValidate.cs index 013551c..57880f7 100644 --- a/tests/MiniValidationPlus.UnitTests/TryValidate.cs +++ b/tests/MiniValidationPlus.UnitTests/TryValidate.cs @@ -11,7 +11,7 @@ public void Throws_ANE_For_Null_Target() TestType thingToValidate = null; Assert.Throws(() => - MiniValidator.TryValidate(thingToValidate, out var errors)); + MiniValidatorPlus.TryValidate(thingToValidate, out var errors)); } #nullable enable @@ -20,7 +20,7 @@ public void RequiredValidator_Invalid_When_Null() { var thingToValidate = new TestType { RequiredName = null }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); var entry = Assert.Single(errors); @@ -32,7 +32,7 @@ public void RequiredValidator_Invalid_When_Empty() { var thingToValidate = new TestType { RequiredName = string.Empty }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); var entry = Assert.Single(errors); @@ -44,7 +44,7 @@ public void RequiredValidator_Valid_When_NonEmpty_Value() { var thingToValidate = new TestType { RequiredName = "test" }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -55,7 +55,7 @@ public void NonRequiredValidator_Invalid_When_Invalid() { var thingToValidate = new TestType { TenOrMore = 5 }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); var entry = Assert.Single(errors); @@ -67,7 +67,7 @@ public void NonRequiredValidator_Valid_When_Valid() { var thingToValidate = new TestType { TenOrMore = 11 }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -79,7 +79,7 @@ public void NonRequiredValidator_Valid_When_Valid_On_Record() { var thingToValidate = new TestRecordType(TenOrMore: 11); - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -90,7 +90,7 @@ public void NonRequiredValidator_Invalid_When_Invalid_On_Record() { var thingToValidate = new TestRecordType(TenOrMore: 9); - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -101,7 +101,7 @@ public void NonNullable_Invalid_When_Null() { var thingToValidate = new TestType { NonNullableString = null! }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); var entry = Assert.Single(errors); @@ -113,7 +113,7 @@ public void NonNullable_Valid_When_Empty() { var thingToValidate = new TestType { NonNullableString = string.Empty }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -124,7 +124,7 @@ public void NonNullable_Valid_When_NonEmpty_Value() { var thingToValidate = new TestType { NonNullableString = "test" }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -135,7 +135,7 @@ public void NonNullable_Valid_When_Empty_On_Record() { var thingToValidate = new TestRecordType(NonNullableString: string.Empty); - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -146,7 +146,7 @@ public void NonNullable_Valid_When_NonEmpty_On_Record() { var thingToValidate = new TestRecordType(NonNullableString: "test"); - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -157,7 +157,7 @@ public void NonNullable_Invalid_When_Null_On_Record() { var thingToValidate = new TestRecordType(NonNullableString: null!); - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -169,7 +169,7 @@ public void MultipleValidators_Valid_When_All_Valid() { var thingToValidate = new TestType { RequiredName = "test", TenOrMore = 11 }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -180,7 +180,7 @@ public void MultipleValidators_Invalid_When_First_Invalid() { var thingToValidate = new TestType { RequiredName = null, TenOrMore = 11 }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -191,7 +191,7 @@ public void MultipleValidators_Invalid_When_One_Other_Than_First_Invalid() { var thingToValidate = new TestType { RequiredName = "test", TenOrMore = 5 }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -202,7 +202,7 @@ public void MultipleValidators_Invalid_When_All_Invalid() { var thingToValidate = new TestType { RequiredName = null, TenOrMore = 5 }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Equal(2, errors.Count); @@ -213,7 +213,7 @@ public void Validator_DisplayAttribute_Name_Used_In_Error_Message() { var thingToValidate = new TestType { RequiredNameWithDisplay = null }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); var entry = Assert.Single(errors); @@ -227,7 +227,7 @@ public void Validator_DisplayAttribute_Name_Used_In_Error_Message_For_Record() { var thingToValidate = new TestRecordType(""); - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); var entry = Assert.Single(errors); @@ -241,7 +241,7 @@ public void List_Invalid_When_Entry_Invalid() { var collectionToValidate = new List { new() { RequiredName = null } }; - var result = MiniValidator.TryValidate(collectionToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(collectionToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -272,7 +272,7 @@ public static TheoryData PrimitiveValues #pragma warning restore xUnit1045 // Avoid using TheoryData type arguments that might not be serializable public void Valid_When_Target_Is_Not_Complex(object thingToValidate) { - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -283,7 +283,7 @@ public void Struct_Valid_When_Valid() { var thingToValidate = new TestStruct(); - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -294,7 +294,7 @@ public void Struct_Invalid_When_Invalid() { var thingToValidate = new TestStruct { RequiredName = null }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -308,7 +308,7 @@ public void Invalid_When_ValidatableObject_Validate_Is_Invalid() TwentyOrMore = 12 }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -323,7 +323,7 @@ public void Invalid_When_ValidatableObject_Has_Invalid_Attributes() TenOrMore = 9 }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -339,7 +339,7 @@ public void ValidatableObject_Is_Not_Validated_When_Has_Invalid_Attributes() TwentyOrMore = 12 }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -354,7 +354,7 @@ public void Invalid_When_ValidatableObject_With_Class_Level_Only_Is_Invalid() TwentyOrMore = 12 }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -369,7 +369,7 @@ public async Task Invalid_When_AsyncValidatableObject_With_Class_Level_Only_Is_I TwentyOrMore = 12 }; - var (isValid, errors) = await MiniValidator.TryValidateAsync(thingToValidate, true); + var (isValid, errors) = await MiniValidatorPlus.TryValidateAsync(thingToValidate, true); Assert.False(isValid); Assert.Single(errors); @@ -386,7 +386,7 @@ public void Throws_ArgumentException_When_TryValidate_Called_On_Target_Requiring Assert.Throws("target", () => { - var isValid = MiniValidator.TryValidate(thingToValidate, out var errors); + var isValid = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); }); } @@ -395,7 +395,7 @@ public void Valid_When_Target_Has_Required_Uri_Property() { var thingToValidate = new ClassWithUri { BaseAddress = new("https://example.com") }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -406,7 +406,7 @@ public void Valid_When_Target_Has_Required_Uri_Property_With_UriKind_Relative_Va { var thingToValidate = new ClassWithUri { BaseAddress = new("/a/relative/path", UriKind.Relative) }; - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.True(result); Assert.Empty(errors); @@ -417,7 +417,7 @@ public void Invalid_When_Target_Has_Required_Uri_Property_With_Null_Value() { var thingToValidate = new ClassWithUri(); - var result = MiniValidator.TryValidate(thingToValidate, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, out var errors); Assert.False(result); Assert.Single(errors); @@ -433,11 +433,11 @@ public void TryValidate_With_ServiceProvider() var thingToValidate = new TestClassLevelValidatableOnlyTypeWithServiceProvider(); - var result = MiniValidator.TryValidate(thingToValidate, serviceProvider, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, serviceProvider, out var errors); Assert.True(result); errors.Clear(); - result = MiniValidator.TryValidate(thingToValidate, out errors); + result = MiniValidatorPlus.TryValidate(thingToValidate, out errors); Assert.False(result); Assert.Single(errors); Assert.Equal(nameof(IServiceProvider), errors.Keys.First()); @@ -452,13 +452,13 @@ public async Task TryValidateAsync_With_ServiceProvider() var thingToValidate = new TestClassLevelValidatableOnlyTypeWithServiceProvider(); - var (isValid, errors) = await MiniValidator.TryValidateAsync(thingToValidate, serviceProvider); + var (isValid, errors) = await MiniValidatorPlus.TryValidateAsync(thingToValidate, serviceProvider); Assert.True(isValid); Assert.Empty(errors); errors.Clear(); - (isValid, errors) = await MiniValidator.TryValidateAsync(thingToValidate); + (isValid, errors) = await MiniValidatorPlus.TryValidateAsync(thingToValidate); Assert.False(isValid); Assert.Single(errors); Assert.Equal(nameof(IServiceProvider), errors.Keys.First()); @@ -479,11 +479,11 @@ public void TryValidate_Enumerable_With_ServiceProvider() } }; - var result = MiniValidator.TryValidate(thingToValidate, serviceProvider, out var errors); + var result = MiniValidatorPlus.TryValidate(thingToValidate, serviceProvider, out var errors); Assert.True(result); errors.Clear(); - result = MiniValidator.TryValidate(thingToValidate, out errors); + result = MiniValidatorPlus.TryValidate(thingToValidate, out errors); Assert.False(result); Assert.Single(errors); Assert.Equal($"{nameof(TestClassWithEnumerable.Enumerable)}.[0].{nameof(IServiceProvider)}", errors.Keys.First()); @@ -504,11 +504,11 @@ public async Task TryValidateAsync_Enumerable_With_ServiceProvider() } }; - var (isValid, errors) = await MiniValidator.TryValidateAsync(thingToValidate, serviceProvider); + var (isValid, errors) = await MiniValidatorPlus.TryValidateAsync(thingToValidate, serviceProvider); Assert.True(isValid); errors.Clear(); - (isValid, errors) = await MiniValidator.TryValidateAsync(thingToValidate); + (isValid, errors) = await MiniValidatorPlus.TryValidateAsync(thingToValidate); Assert.False(isValid); Assert.Single(errors); Assert.Equal($"{nameof(TestClassWithEnumerable.Enumerable)}.[0].{nameof(IServiceProvider)}", errors.Keys.First()); @@ -523,7 +523,7 @@ public async Task TryValidateAsync_With_Attribute_Attached_Via_TypeDescriptor() nameof(TestTypeForTypeDescriptor.PropertyToBeRequired), _ => new RequiredAttribute()); - var (isValid, errors) = await MiniValidator.TryValidateAsync(thingToValidate); + var (isValid, errors) = await MiniValidatorPlus.TryValidateAsync(thingToValidate); Assert.False(isValid); Assert.Equal(2, errors.Count);