-
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 #114 from pfpack/feature/improve-or-throw-methods
Feature/improve or throw methods
- Loading branch information
Showing
16 changed files
with
272 additions
and
32 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
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
72 changes: 72 additions & 0 deletions
72
src/core-taggeds-result/Result.Tests/Test.Result/OrThrow/Failure.FactoryFrom.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,72 @@ | ||
using NUnit.Framework; | ||
using PrimeFuncPack.UnitTest; | ||
using System; | ||
using static PrimeFuncPack.UnitTest.TestData; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class ResultTest | ||
{ | ||
[Test] | ||
[TestCaseSource(typeof(TestDataSource), nameof(TestDataSource.FailureDefaultTestSource))] | ||
public void FailureOrThrowWithExceptionFactoryFromSuccess_ExceptionFactoryIsNull_ExpectDefaultFailureValue( | ||
Result<RefType, StructType> source) | ||
{ | ||
var exceptionFactory = (Func<RefType, Exception>)null!; | ||
var actualException = Assert.Throws<ArgumentNullException>(Test); | ||
|
||
Assert.AreEqual("exceptionFactory", actualException?.ParamName); | ||
|
||
void Test() | ||
=> | ||
_ = source.FailureOrThrow(exceptionFactory); | ||
} | ||
|
||
[Test] | ||
[TestCaseSource(typeof(TestDataSource), nameof(TestDataSource.FailureDefaultTestSource))] | ||
public void FailureOrThrowWithExceptionFactoryFromSuccess_SourceIsDefault_ExpectDefaultFailureValue( | ||
Result<RefType, StructType> source) | ||
{ | ||
var actual = source.FailureOrThrow(CreateException); | ||
var expected = default(StructType); | ||
|
||
Assert.AreEqual(expected, actual); | ||
|
||
static Exception CreateException(RefType success) | ||
=> | ||
new SomeException<RefType>(success); | ||
} | ||
|
||
[Test] | ||
[TestCaseSource(typeof(TestDataSource), nameof(TestDataSource.FailureSomeTextStructTypeTestSource))] | ||
public void FailureOrThrowWithExceptionFactoryFromSuccess_SourceIsFailure_ExpectFailureValue( | ||
Result<RefType, StructType> source) | ||
{ | ||
var actual = source.FailureOrThrow(CreateException); | ||
var expected = SomeTextStructType; | ||
|
||
Assert.AreEqual(expected, actual); | ||
|
||
static Exception CreateException(RefType success) | ||
=> | ||
new SomeException<RefType>(success); | ||
} | ||
|
||
[Test] | ||
[TestCaseSource(typeof(TestDataSource), nameof(TestDataSource.SuccessPlusFifteenIdRefTypeTestSource))] | ||
public void FailureOrThrowWithExceptionFactoryFromSuccess_SourceIsSuccess_ExpectExceptionFromFactory( | ||
Result<RefType, StructType> source) | ||
{ | ||
var actualException = Assert.Throws<SomeException<RefType>>(Test); | ||
|
||
Assert.AreEqual(PlusFifteenIdRefType, actualException?.Value); | ||
|
||
void Test() | ||
=> | ||
_ = source.FailureOrThrow(CreateException); | ||
|
||
static Exception CreateException(RefType success) | ||
=> | ||
new SomeException<RefType>(success); | ||
} | ||
} |
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
70 changes: 70 additions & 0 deletions
70
src/core-taggeds-result/Result.Tests/Test.Result/OrThrow/Success.FactoryFrom.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,70 @@ | ||
using NUnit.Framework; | ||
using PrimeFuncPack.UnitTest; | ||
using System; | ||
using static PrimeFuncPack.UnitTest.TestData; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
partial class ResultTest | ||
{ | ||
[Test] | ||
[TestCaseSource(typeof(TestDataSource), nameof(TestDataSource.SuccessMinusFifteenIdRefTypeTestSource))] | ||
public void SuccessOrThrowWithExceptionFactoryFromFailure_ExceptionFactoryIsNull_ExpectArgumentNullException( | ||
Result<RefType, StructType> source) | ||
{ | ||
var exceptionFactory = (Func<StructType, Exception>)null!; | ||
var actualException = Assert.Throws<ArgumentNullException>(Test); | ||
|
||
Assert.AreEqual("exceptionFactory", actualException?.ParamName); | ||
|
||
void Test() | ||
=> | ||
_ = source.SuccessOrThrow(exceptionFactory); | ||
} | ||
|
||
[Test] | ||
[TestCaseSource(typeof(TestDataSource), nameof(TestDataSource.SuccessNullTestSource))] | ||
public void SuccessOrThrowWithExceptionFactoryFromFailure_SourceIsSuccessAndValueIsNull_ExpectNull( | ||
Result<RefType, StructType> source) | ||
{ | ||
var actual = source.SuccessOrThrow(CreateException); | ||
Assert.IsNull(actual); | ||
|
||
static Exception CreateException(StructType failure) | ||
=> | ||
new SomeException<StructType>(failure); | ||
} | ||
|
||
[Test] | ||
[TestCaseSource(typeof(TestDataSource), nameof(TestDataSource.SuccessPlusFifteenIdRefTypeTestSource))] | ||
public void SuccessOrThrowWithExceptionFactoryFromFailure_SourceIsSuccessAndValueIsNotNull_ExpectSuccessValue( | ||
Result<RefType, StructType> source) | ||
{ | ||
var actual = source.SuccessOrThrow(CreateException); | ||
var expected = PlusFifteenIdRefType; | ||
|
||
Assert.AreEqual(expected, actual); | ||
|
||
static Exception CreateException(StructType failure) | ||
=> | ||
new SomeException<StructType>(failure); | ||
} | ||
|
||
[Test] | ||
[TestCaseSource(typeof(TestDataSource), nameof(TestDataSource.FailureSomeTextStructTypeTestSource))] | ||
public void SuccessOrThrowWithExceptionFactoryFromFailure_SourceIsDefaultOrFailure_ExpectExceptionFromFactory( | ||
Result<RefType, StructType> source) | ||
{ | ||
var actualException = Assert.Throws< SomeException<StructType>>(Test); | ||
|
||
Assert.AreEqual(SomeTextStructType, actualException?.Value); | ||
|
||
void Test() | ||
=> | ||
_ = source.SuccessOrThrow(CreateException); | ||
|
||
static SomeException<StructType> CreateException(StructType failure) | ||
=> | ||
new(failure); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
src/core-taggeds-result/Result.Tests/TestData/SomeException.T.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,12 @@ | ||
using System; | ||
|
||
namespace PrimeFuncPack.Core.Tests; | ||
|
||
internal sealed class SomeException<T> : Exception | ||
{ | ||
public SomeException(T value) | ||
=> | ||
Value = value; | ||
|
||
public T Value { get; } | ||
} |
Oops, something went wrong.