-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
pmosk
committed
Aug 9, 2023
1 parent
db51c16
commit dce101c
Showing
32 changed files
with
506 additions
and
868 deletions.
There are no files selected for viewing
10 changes: 6 additions & 4 deletions
10
src/core-taggeds-failure/Failure.Tests/AssertHelper/AssertHelper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
using Xunit; | ||
using System; | ||
using Xunit; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
internal static class AssertHelper | ||
{ | ||
public static void AssertEqualFailures<TFailureCode>( | ||
(TFailureCode FailureCode, string FailureMessage) expected, | ||
(TFailureCode FailureCode, string FailureMessage) actual) | ||
(TFailureCode FailureCode, string FailureMessage, Exception? SourceException) expected, | ||
(TFailureCode FailureCode, string FailureMessage, Exception? SourceException) actual) | ||
where TFailureCode : struct | ||
{ | ||
Assert.Equal(expected.FailureCode, actual.FailureCode); | ||
Assert.StrictEqual(expected.FailureCode, actual.FailureCode); | ||
Assert.Equal(expected.FailureMessage, actual.FailureMessage); | ||
Assert.Equal(expected.SourceException, actual.SourceException); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/core-taggeds-failure/Failure.Tests/Source/FailureTestSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
internal static partial class FailureTestSource | ||
{ | ||
private sealed class SomeException : Exception | ||
{ | ||
public static readonly SomeException SomeInstance; | ||
|
||
static SomeException() | ||
=> | ||
SomeInstance = new(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/core-taggeds-failure/Failure.Tests/Source/Source.Equal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using PrimeFuncPack.UnitTest; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class FailureTestSource | ||
{ | ||
public static IEnumerable<object[]> EqualPairTestData | ||
=> | ||
new[] | ||
{ | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(), | ||
default(Failure<SomeFailureCode>) | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(), | ||
new Failure<SomeFailureCode>(default, null) | ||
}, | ||
new object[] | ||
{ | ||
default(Failure<SomeFailureCode>), | ||
new Failure<SomeFailureCode>(default, string.Empty) | ||
{ | ||
SourceException = null | ||
} | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(default, null), | ||
new Failure<SomeFailureCode>() | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(default, string.Empty), | ||
default(Failure<SomeFailureCode>) | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, null) | ||
{ | ||
SourceException = SomeException.SomeInstance | ||
}, | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, null) | ||
{ | ||
SourceException = SomeException.SomeInstance | ||
} | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(SomeFailureCode.Second, string.Empty), | ||
new Failure<SomeFailureCode>(SomeFailureCode.Second, null) | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(SomeFailureCode.Third, null), | ||
new Failure<SomeFailureCode>(SomeFailureCode.Third, string.Empty) | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(SomeFailureCode.Unknown, string.Empty), | ||
new Failure<SomeFailureCode>(SomeFailureCode.Unknown, string.Empty) | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, TestData.SomeString) | ||
{ | ||
SourceException = SomeException.SomeInstance | ||
}, | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, TestData.SomeString) | ||
{ | ||
SourceException = SomeException.SomeInstance | ||
} | ||
} | ||
}; | ||
} |
61 changes: 61 additions & 0 deletions
61
src/core-taggeds-failure/Failure.Tests/Source/Source.Unequal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using PrimeFuncPack.UnitTest; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class FailureTestSource | ||
{ | ||
public static IEnumerable<object[]> UnequalPairTestData | ||
=> | ||
new[] | ||
{ | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(), | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, null) | ||
}, | ||
new object[] | ||
{ | ||
default(Failure<SomeFailureCode>), | ||
new Failure<SomeFailureCode>(SomeFailureCode.Second, TestData.WhiteSpaceString) | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(SomeFailureCode.Third, null), | ||
default(Failure<SomeFailureCode>) | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, TestData.TabString), | ||
new Failure<SomeFailureCode>() | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, TestData.SomeString), | ||
new Failure<SomeFailureCode>(SomeFailureCode.Second, TestData.SomeString) | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, TestData.SomeString) | ||
{ | ||
SourceException = SomeException.SomeInstance | ||
}, | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, TestData.UpperSomeString) | ||
{ | ||
SourceException = SomeException.SomeInstance | ||
} | ||
}, | ||
new object[] | ||
{ | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, TestData.SomeString) | ||
{ | ||
SourceException = new SomeException() | ||
}, | ||
new Failure<SomeFailureCode>(SomeFailureCode.First, TestData.SomeString) | ||
{ | ||
SourceException = new SomeException() | ||
} | ||
} | ||
}; | ||
} |
46 changes: 46 additions & 0 deletions
46
src/core-taggeds-failure/Failure.Tests/Test.Failure/FailureTest.Deconstruct.Exception.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System; | ||
using Xunit; | ||
using static PrimeFuncPack.Core.Tests.AssertHelper; | ||
using static PrimeFuncPack.UnitTest.TestData; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class FailureTest | ||
{ | ||
[Theory] | ||
[InlineData(int.MinValue, null, EmptyString)] | ||
[InlineData(Zero, EmptyString, EmptyString)] | ||
[InlineData(PlusFifteen, SomeString, SomeString)] | ||
public static void DeconstructWithSourceException_SourceExceptionIsNull_ExpectCorrectValue( | ||
int sourceFailureCode, string? sourceFailureMessage, string expectedFailureMessage) | ||
{ | ||
var source = new Failure<int>(sourceFailureCode, sourceFailureMessage); | ||
|
||
var (actualFailureCode, actualFailureMessage, actualException) = source; | ||
|
||
AssertEqualFailures( | ||
(sourceFailureCode, expectedFailureMessage, null), | ||
(actualFailureCode, actualFailureMessage, actualException)); | ||
} | ||
|
||
[Theory] | ||
[InlineData(SomeFailureCode.First, null, EmptyString)] | ||
[InlineData(SomeFailureCode.Unknown, EmptyString, EmptyString)] | ||
[InlineData(SomeFailureCode.Second, SomeString, SomeString)] | ||
public static void DeconstructWithSourceException_SourceExceptionIsNotNull_ExpectCorrectValue( | ||
SomeFailureCode sourceFailureCode, string? sourceFailureMessage, string expectedFailureMessage) | ||
{ | ||
var sourceException = new Exception(); | ||
|
||
var source = new Failure<SomeFailureCode>(sourceFailureCode, sourceFailureMessage) | ||
{ | ||
SourceException = sourceException | ||
}; | ||
|
||
var (actualFailureCode, actualFailureMessage, actualException) = source; | ||
|
||
AssertEqualFailures( | ||
(sourceFailureCode, expectedFailureMessage, sourceException), | ||
(actualFailureCode, actualFailureMessage, actualException)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.