Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release/2.2.0-preview.9_failure-tests #137

Merged
merged 8 commits into from
Feb 11, 2024
Merged
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
31 changes: 15 additions & 16 deletions src/core-taggeds-failure/Failure.Tests/AssertHelper/AssertHelper.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using Xunit;

namespace PrimeFuncPack.Core.Tests;

internal static class AssertHelper
{
public static void AssertEqualFailures<TFailureCode>(
(TFailureCode FailureCode, string FailureMessage, Exception? SourceException) expected,
(TFailureCode FailureCode, string FailureMessage, Exception? SourceException) actual)
where TFailureCode : struct
{
Assert.StrictEqual(expected.FailureCode, actual.FailureCode);
Assert.Equal(expected.FailureMessage, actual.FailureMessage);
Assert.Equal(expected.SourceException, actual.SourceException);
}
}

namespace PrimeFuncPack.Core.Tests;

internal static class AssertHelper
{
internal static void AssertEqualFailures<TFailureCode>(
(TFailureCode FailureCode, string FailureMessage, Exception? SourceException) expected,
(TFailureCode FailureCode, string FailureMessage, Exception? SourceException) actual)
where TFailureCode : struct
{
Assert.StrictEqual(expected.FailureCode, actual.FailureCode);
Assert.Equal(expected.FailureMessage, actual.FailureMessage);
Assert.Same(expected.SourceException, actual.SourceException);
}
}
1 change: 1 addition & 0 deletions src/core-taggeds-failure/Failure.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Xunit;
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ internal static partial class FailureTestSource
{
private sealed class SomeException : Exception
{
public static readonly SomeException SomeInstance;

static SomeException()
=>
SomeInstance = new();
internal static SomeException Instance { get; } = new();
}
}
29 changes: 9 additions & 20 deletions src/core-taggeds-failure/Failure.Tests/Source/Source.Equal.cs
Original file line number Diff line number Diff line change
@@ -1,78 +1,67 @@
using System;
using System.Collections.Generic;
using PrimeFuncPack.UnitTest;

namespace PrimeFuncPack.Core.Tests;

partial class FailureTestSource
{
public static IEnumerable<object[]> EqualPairTestData
public static TheoryData<Failure<EnumType>, Failure<EnumType>> EqualPairTestData
=>
new[]
new()
{
new object[]
{
new Failure<EnumType>(),
default(Failure<EnumType>)
default
},
new object[]
{
new Failure<EnumType>(),
new Failure<EnumType>(default, null)
},
new object[]
{
default(Failure<EnumType>),
default,
new Failure<EnumType>(default, string.Empty)
{
SourceException = null
}
},
new object[]
{
new Failure<EnumType>(default, null),
new Failure<EnumType>()
},
new object[]
{
new Failure<EnumType>(default, string.Empty),
default(Failure<EnumType>)
default
},
new object[]
{
new Failure<EnumType>(EnumType.One, null)
{
SourceException = SomeException.SomeInstance
SourceException = SomeException.Instance
},
new Failure<EnumType>(EnumType.One, null)
{
SourceException = SomeException.SomeInstance
SourceException = SomeException.Instance
}
},
new object[]
{
new Failure<EnumType>(EnumType.Two, string.Empty),
new Failure<EnumType>(EnumType.Two, null)
},
new object[]
{
new Failure<EnumType>(EnumType.Three, null),
new Failure<EnumType>(EnumType.Three, string.Empty)
},
new object[]
{
new Failure<EnumType>(EnumType.Zero, string.Empty),
new Failure<EnumType>(EnumType.Zero, string.Empty)
},
new object[]
{
new Failure<EnumType>(EnumType.One, TestData.SomeString)
{
SourceException = SomeException.SomeInstance
SourceException = SomeException.Instance
},
new Failure<EnumType>(EnumType.One, TestData.SomeString)
{
SourceException = SomeException.SomeInstance
SourceException = SomeException.Instance
}
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,66 +1,56 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using PrimeFuncPack.UnitTest;

namespace PrimeFuncPack.Core.Tests;

partial class FailureTestSource
{
public static IEnumerable<object[]> ToExceptionTestData
public static TheoryData<Failure<EnumType>, Failure<EnumType>.Exception> ToExceptionTestData
=>
new[]
new()
{
new object[]
{
default(Failure<EnumType>),
default,
InnerCreate(default(EnumType), null, null)
},
new object[]
{
new Failure<EnumType>(EnumType.One, null),
InnerCreate(EnumType.One, null, null)
},
new object[]
{
new Failure<EnumType>(EnumType.Two, string.Empty),
InnerCreate(EnumType.Two, null, null)
},
new object[]
{
new Failure<EnumType>(EnumType.Zero, TestData.WhiteSpaceString),
InnerCreate(EnumType.Zero, TestData.WhiteSpaceString, null)
},
new object[]
{
new Failure<EnumType>(EnumType.Two, TestData.SomeString),
InnerCreate(EnumType.Two, TestData.SomeString, null)
},
new object[]
{
new Failure<EnumType>(EnumType.Three, null)
{
SourceException = new InvalidOperationException("Some error message")
},
InnerCreate(EnumType.Three, null, new InvalidOperationException("Some error message"))
},
new object[]
{
new Failure<EnumType>(EnumType.One, string.Empty)
{
SourceException = new("Some Exception")
},
InnerCreate(EnumType.One, null, new("Some Exception"))
},
new object[]
{
new Failure<EnumType>(EnumType.One, TestData.MixedWhiteSpacesString)
{
SourceException = new("Some Exception")
},
InnerCreate(EnumType.One, TestData.MixedWhiteSpacesString, new("Some Exception"))
},
new object[]
{
new Failure<EnumType>(EnumType.Two, TestData.AnotherString)
{
Expand All @@ -78,9 +68,9 @@ private static Failure<TFailureCode>.Exception InnerCreate<TFailureCode>(

var constructor = typeof(Failure<TFailureCode>.Exception).GetConstructor(
bindingAttr: BindingFlags.NonPublic | BindingFlags.Instance,
types: new[] { typeof(TFailureCode), typeof(string), typeof(Exception) })
types: [typeof(TFailureCode), typeof(string), typeof(Exception)])
?? throw new InvalidOperationException($"Required constructor in type {type} was not found");

return (Failure<TFailureCode>.Exception)constructor.Invoke(new object?[] { failureCode, message, innerException });
return (Failure<TFailureCode>.Exception)constructor.Invoke([failureCode, message, innerException]);
}
}
20 changes: 6 additions & 14 deletions src/core-taggeds-failure/Failure.Tests/Source/Source.Unequal.cs
Original file line number Diff line number Diff line change
@@ -1,52 +1,44 @@
using System;
using System.Collections.Generic;
using PrimeFuncPack.UnitTest;

namespace PrimeFuncPack.Core.Tests;

partial class FailureTestSource
{
public static IEnumerable<object[]> UnequalPairTestData
public static TheoryData<Failure<EnumType>, Failure<EnumType>> UnequalPairTestData
=>
new[]
new()
{
new object[]
{
new Failure<EnumType>(),
new Failure<EnumType>(EnumType.One, null)
},
new object[]
{
default(Failure<EnumType>),
default,
new Failure<EnumType>(EnumType.Two, TestData.WhiteSpaceString)
},
new object[]
{
new Failure<EnumType>(EnumType.Three, null),
default(Failure<EnumType>)
default
},
new object[]
{
new Failure<EnumType>(EnumType.One, TestData.TabString),
new Failure<EnumType>()
},
new object[]
{
new Failure<EnumType>(EnumType.One, TestData.SomeString),
new Failure<EnumType>(EnumType.Two, TestData.SomeString)
},
new object[]
{
new Failure<EnumType>(EnumType.One, TestData.SomeString)
{
SourceException = SomeException.SomeInstance
SourceException = SomeException.Instance
},
new Failure<EnumType>(EnumType.One, TestData.UpperSomeString)
{
SourceException = SomeException.SomeInstance
SourceException = SomeException.Instance
}
},
new object[]
{
new Failure<EnumType>(EnumType.One, TestData.SomeString)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;
using static PrimeFuncPack.Core.Tests.AssertHelper;
using static PrimeFuncPack.UnitTest.TestData;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;
using static PrimeFuncPack.Core.Tests.AssertHelper;
using static PrimeFuncPack.UnitTest.TestData;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;

namespace PrimeFuncPack.Core.Tests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;

namespace PrimeFuncPack.Core.Tests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;

namespace PrimeFuncPack.Core.Tests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;

namespace PrimeFuncPack.Core.Tests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;

namespace PrimeFuncPack.Core.Tests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using DeepEqual.Syntax;
using PrimeFuncPack.UnitTest;
using Xunit;

namespace PrimeFuncPack.Core.Tests;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;
using static PrimeFuncPack.Core.Tests.AssertHelper;
using static PrimeFuncPack.UnitTest.TestData;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;
using static PrimeFuncPack.Core.Tests.AssertHelper;
using static PrimeFuncPack.UnitTest.TestData;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;
using static PrimeFuncPack.Core.Tests.AssertHelper;

namespace PrimeFuncPack.Core.Tests;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using PrimeFuncPack.UnitTest;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;

namespace PrimeFuncPack.Core.Tests;
Expand All @@ -15,7 +14,7 @@ public static void GetHashCode_FirstIsEqualToSecondAndTypesAreSame_ExpectHashCod
var firstHashCode = first.GetHashCode();
var secondHashCode = second.GetHashCode();

Assert.Equal(firstHashCode, secondHashCode);
Assert.StrictEqual(firstHashCode, secondHashCode);
}

[Fact]
Expand All @@ -27,7 +26,7 @@ public static void GetHashCode_FirstTypeIsNotEqualToSecondType_ExpectHashCodesAr
var firstHashCode = first.GetHashCode();
var secondHashCode = second.GetHashCode();

Assert.NotEqual(firstHashCode, secondHashCode);
Assert.NotStrictEqual(firstHashCode, secondHashCode);
}

[Theory]
Expand All @@ -38,6 +37,6 @@ public static void GetHashCode_FirstIsNotEqualToSecondAndTypesAreSame_ExpectHash
var firstHashCode = first.GetHashCode();
var secondHashCode = second.GetHashCode();

Assert.NotEqual(firstHashCode, secondHashCode);
Assert.NotStrictEqual(firstHashCode, secondHashCode);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Globalization;
using PrimeFuncPack.UnitTest;
using Xunit;
using static PrimeFuncPack.UnitTest.TestData;

namespace PrimeFuncPack.Core.Tests;
Expand Down
Loading