-
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.
Merge pull request #133 from pfpack/feature/impl-failure-exception
Add first implementation of FailureException
- Loading branch information
Showing
39 changed files
with
278 additions
and
142 deletions.
There are no files selected for viewing
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
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
86 changes: 86 additions & 0 deletions
86
src/core-taggeds-failure/Failure.Tests/Source/Source.ToException.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,86 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Reflection; | ||
using PrimeFuncPack.UnitTest; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class FailureTestSource | ||
{ | ||
public static IEnumerable<object[]> ToExceptionTestData | ||
=> | ||
new[] | ||
{ | ||
new object[] | ||
{ | ||
default(Failure<EnumType>), | ||
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) | ||
{ | ||
SourceException = new InvalidCastException("Some error text", new SomeException()) | ||
}, | ||
InnerCreate(EnumType.Two, TestData.AnotherString, new InvalidCastException("Some error text", new SomeException())) | ||
} | ||
}; | ||
|
||
private static Failure<TFailureCode>.Exception InnerCreate<TFailureCode>( | ||
TFailureCode failureCode, string? message, Exception? innerException) | ||
where TFailureCode : struct | ||
{ | ||
var type = typeof(Failure<TFailureCode>.Exception); | ||
|
||
var constructor = typeof(Failure<TFailureCode>.Exception).GetConstructor( | ||
bindingAttr: BindingFlags.NonPublic | BindingFlags.Instance, | ||
types: new[] { 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 }); | ||
} | ||
} |
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
9 changes: 0 additions & 9 deletions
9
src/core-taggeds-failure/Failure.Tests/Stubs/SomeFailureCode.cs
This file was deleted.
Oops, something went wrong.
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
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
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
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.