From abe649188253205fc9a7ea60a0a3cb7d740638f7 Mon Sep 17 00:00:00 2001 From: "guillaume.caya" Date: Tue, 4 Jun 2024 14:41:44 -0400 Subject: [PATCH] Theorydata --- .../ContainsNonEmptyGuidAttributeTests.cs | 53 ++++++++-------- .../ContainsNonEmptyStringAttributeTests.cs | 42 ++++++------- ...ContainsOnlyNonEmptyGuidsAttributeTests.cs | 60 +++++++++---------- ...ntainsOnlyNonEmptyStringsAttributeTests.cs | 45 +++++++------- 4 files changed, 91 insertions(+), 109 deletions(-) diff --git a/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyGuidAttributeTests.cs b/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyGuidAttributeTests.cs index c8f2932..c1e8421 100644 --- a/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyGuidAttributeTests.cs +++ b/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyGuidAttributeTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Globalization; @@ -9,7 +8,7 @@ namespace Workleap.ComponentModel.DataAnnotations.Tests; public sealed class ContainsNonEmptyGuidAttributeTests { [Theory] - [ClassData(typeof(ValidData))] + [MemberData(nameof(ValidData))] public void Given_ValidGuids_When_Validate_Then_Valid(object? inputs) { var attr = new ContainsNonEmptyGuidAttribute(); @@ -17,7 +16,7 @@ public void Given_ValidGuids_When_Validate_Then_Valid(object? inputs) } [Theory] - [ClassData(typeof(InvalidData))] + [MemberData(nameof(InvalidData))] public void Given_InvalidGuids_When_Validate_Then_Invalid(object? inputs) { var attr = new ContainsNonEmptyGuidAttribute(); @@ -40,38 +39,34 @@ public void Validator_TryValidateObject_Returns_The_Expected_Error_Message_When_ Assert.Equal(expectedErrorMessage, result.ErrorMessage); } - private sealed class ValidData : IEnumerable + public static TheoryData ValidData() { - public IEnumerator GetEnumerator() + return new TheoryData { - yield return new object?[] { null }; - yield return new object[] { new Guid[] { new("f8daff85-4393-42ae-9ab5-8620ab20c8da") } }; - yield return new object[] { new string[] { "d78b48f9-37b8-47dd-8e47-0325dd3e7899" } }; - yield return new object[] { new Guid[] { default, new("846398d2-416d-4f05-86b0-431e11117abc") } }; - yield return new object[] { new Guid[] { Guid.Empty, new("08bfec4a-da43-40de-a15a-0d10f227e6b7") } }; - yield return new object[] { new Guid?[] { default, new Guid("2dd81281-7498-411c-aea1-5cec96f2dd8d") } }; - yield return new object[] { new string[] { "00000000-0000-0000-0000-000000000000", "7d8c61f7-a334-4599-b801-45f0934099a4" } }; - yield return new object[] { new string[] { string.Empty, "7c3cdfba-4466-44ab-bb95-da02eac67380" } }; - yield return new object[] { new string?[] { default, "f8daff85-4393-42ae-9ab5-8620ab20c8da" } }; - } - - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + null, + new Guid[] { new("f8daff85-4393-42ae-9ab5-8620ab20c8da") }, + new string[] { "d78b48f9-37b8-47dd-8e47-0325dd3e7899" }, + new Guid[] { default, new("846398d2-416d-4f05-86b0-431e11117abc") }, + new Guid[] { Guid.Empty, new("08bfec4a-da43-40de-a15a-0d10f227e6b7") }, + new Guid?[] { default, new Guid("2dd81281-7498-411c-aea1-5cec96f2dd8d") }, + new string[] { "00000000-0000-0000-0000-000000000000", "7d8c61f7-a334-4599-b801-45f0934099a4" }, + new string[] { string.Empty, "7c3cdfba-4466-44ab-bb95-da02eac67380" }, + new string?[] { default, "f8daff85-4393-42ae-9ab5-8620ab20c8da" }, + }; } - private sealed class InvalidData : IEnumerable + public static TheoryData InvalidData() { - public IEnumerator GetEnumerator() + return new TheoryData { - yield return new object[] { new Guid[] { default } }; - yield return new object[] { new Guid?[] { default } }; - yield return new object[] { new string[] { string.Empty } }; - yield return new object[] { new string?[] { default } }; - yield return new object[] { new Guid[] { Guid.Empty } }; - yield return new object[] { new string[] { "00000000-0000-0000-0000-000000000000" } }; - yield return new object[] { new int[] { 0 } }; - } - - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + new Guid[] { default }, + new Guid?[] { default }, + new string[] { string.Empty }, + new string?[] { default }, + new Guid[] { Guid.Empty }, + new string[] { "00000000-0000-0000-0000-000000000000" }, + new int[] { 0 }, + }; } private sealed class SomeClass diff --git a/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyStringAttributeTests.cs b/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyStringAttributeTests.cs index 4efb0fc..4ddd42f 100644 --- a/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyStringAttributeTests.cs +++ b/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyStringAttributeTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Globalization; @@ -9,7 +8,7 @@ namespace Workleap.ComponentModel.DataAnnotations.Tests; public sealed class ContainsNonEmptyStringAttributeTests { [Theory] - [ClassData(typeof(ValidData))] + [MemberData(nameof(ValidData))] public void Given_ValidStrings_When_Validate_Then_Valid(object? inputs) { var attr = new ContainsNonEmptyStringAttribute(); @@ -17,7 +16,7 @@ public void Given_ValidStrings_When_Validate_Then_Valid(object? inputs) } [Theory] - [ClassData(typeof(InvalidData))] + [MemberData(nameof(InvalidData))] public void Given_InvalidGuids_When_Validate_Then_Invalid(object? inputs) { var attr = new ContainsNonEmptyStringAttribute(); @@ -41,32 +40,29 @@ public void Validator_TryValidateObject_Returns_The_Expected_Error_Message_When_ Assert.Equal(expectedErrorMessage, result.ErrorMessage); } - private sealed class ValidData : IEnumerable + + public static TheoryData ValidData() { - public IEnumerator GetEnumerator() + return new TheoryData { - yield return new object?[] { null }; - yield return new object[] { new string[] { "Lorem ipsum dolor sit amet" } }; - yield return new object[] { new string[] { "Lorem ipsum dolor sit amet", "Etiam porta velit non nisi feugiat pulvinar" } }; - yield return new object[] { new string[] { string.Empty, "Lorem ipsum dolor sit amet" } }; - yield return new object[] { new string?[] { default, "Lorem ipsum dolor sit amet" } }; - yield return new object[] { new string[] { "Lorem ipsum dolor sit amet", " " } }; - } - - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + null, + new string[] { "Lorem ipsum dolor sit amet" }, + new string[] { "Lorem ipsum dolor sit amet", "Etiam porta velit non nisi feugiat pulvinar" }, + new string[] { string.Empty, "Lorem ipsum dolor sit amet" }, + new string?[] { default, "Lorem ipsum dolor sit amet" }, + new string[] { "Lorem ipsum dolor sit amet", " " }, + }; } - private sealed class InvalidData : IEnumerable + public static TheoryData InvalidData() { - public IEnumerator GetEnumerator() + return new TheoryData { - yield return new object[] { new string?[] { string.Empty, default } }; - yield return new object[] { new string?[] { string.Empty } }; - yield return new object[] { new string?[] { default } }; - yield return new object[] { new string[] { " " } }; - } - - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + new string?[] { string.Empty, default }, + new string?[] { string.Empty }, + new string?[] { default }, + new string[] { " " }, + }; } private sealed class SomeClass diff --git a/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsOnlyNonEmptyGuidsAttributeTests.cs b/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsOnlyNonEmptyGuidsAttributeTests.cs index 0ec13df..25cfa54 100644 --- a/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsOnlyNonEmptyGuidsAttributeTests.cs +++ b/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsOnlyNonEmptyGuidsAttributeTests.cs @@ -9,7 +9,7 @@ namespace Workleap.ComponentModel.DataAnnotations.Tests; public sealed class ContainsOnlyNonEmptyGuidsAttributeTests { [Theory] - [ClassData(typeof(ValidData))] + [MemberData(nameof(ValidData))] public void Given_ValidGuids_When_Validate_Then_Valid(object? inputs) { var attr = new ContainsOnlyNonEmptyGuidsAttribute(); @@ -17,7 +17,7 @@ public void Given_ValidGuids_When_Validate_Then_Valid(object? inputs) } [Theory] - [ClassData(typeof(InvalidData))] + [MemberData(nameof(InvalidData))] public void Given_InvalidGuids_When_Validate_Then_Invalid(object? inputs) { var attr = new ContainsOnlyNonEmptyGuidsAttribute(); @@ -40,42 +40,38 @@ public void Validator_TryValidateObject_Returns_The_Expected_Error_Message_When_ Assert.Equal(expectedErrorMessage, result.ErrorMessage); } - private sealed class ValidData : IEnumerable + public static TheoryData ValidData() { - public IEnumerator GetEnumerator() + return new TheoryData { - yield return new object?[] { null }; - yield return new object[] { Array.Empty() }; - yield return new object[] { Array.Empty() }; - yield return new object[] { Array.Empty() }; - yield return new object[] { Array.Empty() }; - yield return new object[] { new Guid[] { new("f8daff85-4393-42ae-9ab5-8620ab20c8da") } }; - yield return new object[] { new string[] { "d78b48f9-37b8-47dd-8e47-0325dd3e7899" } }; - } - - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + null, + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + new Guid[] { new("f8daff85-4393-42ae-9ab5-8620ab20c8da") }, + new string[] { "d78b48f9-37b8-47dd-8e47-0325dd3e7899" } + }; } - private sealed class InvalidData : IEnumerable + public static TheoryData InvalidData() { - public IEnumerator GetEnumerator() + return new TheoryData { - yield return new object[] { new Guid[] { default } }; - yield return new object[] { new Guid?[] { default } }; - yield return new object[] { new string[] { string.Empty } }; - yield return new object[] { new string?[] { default } }; - yield return new object[] { new Guid[] { Guid.Empty } }; - yield return new object[] { new string[] { "00000000-0000-0000-0000-000000000000" } }; - yield return new object[] { new int[] { 0 } }; - yield return new object[] { new Guid[] { default, new("846398d2-416d-4f05-86b0-431e11117abc") } }; - yield return new object[] { new Guid[] { Guid.Empty, new("08bfec4a-da43-40de-a15a-0d10f227e6b7") } }; - yield return new object[] { new Guid?[] { default, new Guid("2dd81281-7498-411c-aea1-5cec96f2dd8d") } }; - yield return new object[] { new string[] { "00000000-0000-0000-0000-000000000000", "7d8c61f7-a334-4599-b801-45f0934099a4" } }; - yield return new object[] { new string[] { string.Empty, "7c3cdfba-4466-44ab-bb95-da02eac67380" } }; - yield return new object[] { new string?[] { default, "f8daff85-4393-42ae-9ab5-8620ab20c8da" } }; - } - - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + new Guid[] { default }, + new Guid?[] { default }, + new string[] { string.Empty }, + new string?[] { default }, + new Guid[] { Guid.Empty }, + new string[] { "00000000-0000-0000-0000-000000000000" }, + new int[] { 0 }, + new Guid[] { default, new("846398d2-416d-4f05-86b0-431e11117abc") }, + new Guid[] { Guid.Empty, new("08bfec4a-da43-40de-a15a-0d10f227e6b7") }, + new Guid?[] { default, new Guid("2dd81281-7498-411c-aea1-5cec96f2dd8d") }, + new string[] { "00000000-0000-0000-0000-000000000000", "7d8c61f7-a334-4599-b801-45f0934099a4" }, + new string[] { string.Empty, "7c3cdfba-4466-44ab-bb95-da02eac67380" }, + new string?[] { default, "f8daff85-4393-42ae-9ab5-8620ab20c8da" } + }; } private sealed class SomeClass diff --git a/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsOnlyNonEmptyStringsAttributeTests.cs b/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsOnlyNonEmptyStringsAttributeTests.cs index 9e75b13..f910571 100644 --- a/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsOnlyNonEmptyStringsAttributeTests.cs +++ b/src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsOnlyNonEmptyStringsAttributeTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Globalization; @@ -9,7 +8,7 @@ namespace Workleap.ComponentModel.DataAnnotations.Tests; public sealed class ContainsOnlyNonEmptyStringsAttributeTests { [Theory] - [ClassData(typeof(ValidData))] + [MemberData(nameof(ValidData))] public void Given_ValidStrings_When_Validate_Then_Valid(object? inputs) { var attr = new ContainsOnlyNonEmptyStringsAttribute(); @@ -17,7 +16,7 @@ public void Given_ValidStrings_When_Validate_Then_Valid(object? inputs) } [Theory] - [ClassData(typeof(InvalidData))] + [MemberData(nameof(InvalidData))] public void Given_InvalidGuids_When_Validate_Then_Invalid(object? inputs) { var attr = new ContainsOnlyNonEmptyStringsAttribute(); @@ -41,34 +40,30 @@ public void Validator_TryValidateObject_Returns_The_Expected_Error_Message_When_ Assert.Equal(expectedErrorMessage, result.ErrorMessage); } - private sealed class ValidData : IEnumerable + public static TheoryData ValidData() { - public IEnumerator GetEnumerator() + return new TheoryData { - yield return new object?[] { null }; - yield return new object[] { Array.Empty() }; - yield return new object[] { Array.Empty() }; - yield return new object[] { new string[] { "Lorem ipsum dolor sit amet" } }; - yield return new object[] { new string[] { "Lorem ipsum dolor sit amet", "Etiam porta velit non nisi feugiat pulvinar" } }; - } - - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + null, + Array.Empty(), + Array.Empty(), + new string[] { "Lorem ipsum dolor sit amet" }, + new string[] { "Lorem ipsum dolor sit amet", "Etiam porta velit non nisi feugiat pulvinar" }, + }; } - private sealed class InvalidData : IEnumerable + public static TheoryData InvalidData() { - public IEnumerator GetEnumerator() + return new TheoryData { - yield return new object[] { new string?[] { string.Empty, default } }; - yield return new object[] { new string?[] { string.Empty } }; - yield return new object[] { new string?[] { default } }; - yield return new object[] { new string[] { " " } }; - yield return new object[] { new string[] { string.Empty, "Lorem ipsum dolor sit amet" } }; - yield return new object[] { new string?[] { default, "Lorem ipsum dolor sit amet" } }; - yield return new object[] { new string[] { "Lorem ipsum dolor sit amet", " " } }; - } - - IEnumerator IEnumerable.GetEnumerator() => this.GetEnumerator(); + new string?[] { string.Empty, default }, + new string?[] { string.Empty }, + new string?[] { default }, + new string[] { " " }, + new string[] { string.Empty, "Lorem ipsum dolor sit amet" }, + new string?[] { default, "Lorem ipsum dolor sit amet" }, + new string[] { "Lorem ipsum dolor sit amet", " " }, + }; } private sealed class SomeClass