Skip to content

Commit

Permalink
Theorydata
Browse files Browse the repository at this point in the history
  • Loading branch information
Gcaya committed Jun 4, 2024
1 parent 10fd218 commit abe6491
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 109 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
Expand All @@ -9,15 +8,15 @@ 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();
Assert.True(attr.IsValid(inputs));
}

[Theory]
[ClassData(typeof(InvalidData))]
[MemberData(nameof(InvalidData))]
public void Given_InvalidGuids_When_Validate_Then_Invalid(object? inputs)
{
var attr = new ContainsNonEmptyGuidAttribute();
Expand All @@ -40,38 +39,34 @@ public void Validator_TryValidateObject_Returns_The_Expected_Error_Message_When_
Assert.Equal(expectedErrorMessage, result.ErrorMessage);
}

private sealed class ValidData : IEnumerable<object?[]>
public static TheoryData<object?> ValidData()
{
public IEnumerator<object?[]> GetEnumerator()
return new TheoryData<object?>
{
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<object?[]>
public static TheoryData<object?> InvalidData()
{
public IEnumerator<object?[]> GetEnumerator()
return new TheoryData<object?>
{
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
Expand All @@ -9,15 +8,15 @@ 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();
Assert.True(attr.IsValid(inputs));
}

[Theory]
[ClassData(typeof(InvalidData))]
[MemberData(nameof(InvalidData))]
public void Given_InvalidGuids_When_Validate_Then_Invalid(object? inputs)
{
var attr = new ContainsNonEmptyStringAttribute();
Expand All @@ -41,32 +40,29 @@ public void Validator_TryValidateObject_Returns_The_Expected_Error_Message_When_
Assert.Equal(expectedErrorMessage, result.ErrorMessage);
}

Check failure on line 42 in src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyStringAttributeTests.cs

View workflow job for this annotation

GitHub Actions / main

Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000)

Check failure on line 42 in src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyStringAttributeTests.cs

View workflow job for this annotation

GitHub Actions / main

Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000)

Check failure on line 42 in src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyStringAttributeTests.cs

View workflow job for this annotation

GitHub Actions / main

Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000)

Check failure on line 42 in src/Workleap.ComponentModel.DataAnnotations.Tests/ContainsNonEmptyStringAttributeTests.cs

View workflow job for this annotation

GitHub Actions / main

Avoid multiple blank lines (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide2000)
private sealed class ValidData : IEnumerable<object?[]>

public static TheoryData<string?[]?> ValidData()
{
public IEnumerator<object?[]> GetEnumerator()
return new TheoryData<string?[]?>
{
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<object?[]>
public static TheoryData<string?[]?> InvalidData()
{
public IEnumerator<object?[]> GetEnumerator()
return new TheoryData<string?[]?>
{
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ 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();
Assert.True(attr.IsValid(inputs));
}

[Theory]
[ClassData(typeof(InvalidData))]
[MemberData(nameof(InvalidData))]
public void Given_InvalidGuids_When_Validate_Then_Invalid(object? inputs)
{
var attr = new ContainsOnlyNonEmptyGuidsAttribute();
Expand All @@ -40,42 +40,38 @@ public void Validator_TryValidateObject_Returns_The_Expected_Error_Message_When_
Assert.Equal(expectedErrorMessage, result.ErrorMessage);
}

private sealed class ValidData : IEnumerable<object?[]>
public static TheoryData<object?> ValidData()
{
public IEnumerator<object?[]> GetEnumerator()
return new TheoryData<object?>
{
yield return new object?[] { null };
yield return new object[] { Array.Empty<Guid>() };
yield return new object[] { Array.Empty<Guid?>() };
yield return new object[] { Array.Empty<string>() };
yield return new object[] { Array.Empty<string?>() };
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<Guid>(),
Array.Empty<Guid?>(),
Array.Empty<string>(),
Array.Empty<string?>(),
new Guid[] { new("f8daff85-4393-42ae-9ab5-8620ab20c8da") },
new string[] { "d78b48f9-37b8-47dd-8e47-0325dd3e7899" }
};
}

private sealed class InvalidData : IEnumerable<object?[]>
public static TheoryData<object?> InvalidData()
{
public IEnumerator<object?[]> GetEnumerator()
return new TheoryData<object?>
{
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
Expand All @@ -9,15 +8,15 @@ 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();
Assert.True(attr.IsValid(inputs));
}

[Theory]
[ClassData(typeof(InvalidData))]
[MemberData(nameof(InvalidData))]
public void Given_InvalidGuids_When_Validate_Then_Invalid(object? inputs)
{
var attr = new ContainsOnlyNonEmptyStringsAttribute();
Expand All @@ -41,34 +40,30 @@ public void Validator_TryValidateObject_Returns_The_Expected_Error_Message_When_
Assert.Equal(expectedErrorMessage, result.ErrorMessage);
}

private sealed class ValidData : IEnumerable<object?[]>
public static TheoryData<string?[]?> ValidData()
{
public IEnumerator<object?[]> GetEnumerator()
return new TheoryData<string?[]?>
{
yield return new object?[] { null };
yield return new object[] { Array.Empty<string?>() };
yield return new object[] { Array.Empty<string>() };
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<string?>(),
Array.Empty<string>(),
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<object?[]>
public static TheoryData<string?[]?> InvalidData()
{
public IEnumerator<object?[]> GetEnumerator()
return new TheoryData<string?[]?>
{
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
Expand Down

0 comments on commit abe6491

Please sign in to comment.