-
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
1 parent
06158ac
commit dd4b0d2
Showing
8 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
tests/RailwayResult.FunctionalExtensions.Tests/AndTests/AndTests.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,42 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.AndTests; | ||
|
||
public sealed class AndTests | ||
{ | ||
[Theory] | ||
[ClassData(typeof(TheoryData_R1_And))] | ||
public void R1_And(Func<R1, R2> and, R1 input, R2 expectedOutput) | ||
{ | ||
and.Invoke(input).ShouldBe(expectedOutput); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(TheoryData_TaskOfR1_And))] | ||
public async Task TaskOfR1_And(Func<Task<R1>, Task<R2>> and, R1 input, R2 expectedOutput) | ||
{ | ||
var result = await and.Invoke(Task.FromResult(input)); | ||
result.ShouldBe(expectedOutput); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(TheoryData_R2_And))] | ||
public void R2_And(Func<R2, R3> and, R2 input, R3 expectedOutput) | ||
{ | ||
and.Invoke(input).ShouldBe(expectedOutput); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(TheoryData_TaskOfR2_And))] | ||
public async Task TaskOfR2_And(Func<Task<R2>, Task<R3>> and, R2 input, R3 expectedOutput) | ||
{ | ||
var result = await and.Invoke(Task.FromResult(input)); | ||
result.ShouldBe(expectedOutput); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(TheoryData_R1_AndAsync))] | ||
public async Task R1_AndAsync(Func<R1, Task<R2>> andAsync, R1 input, R2 expectedOutput) | ||
{ | ||
var result = await andAsync.Invoke(input); | ||
result.ShouldBe(expectedOutput); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tests/RailwayResult.FunctionalExtensions.Tests/AndTests/TheoryData_R1_And.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,62 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.AndTests; | ||
|
||
public sealed class TheoryData_R1_And : TheoryData<Func<R1, R2>, R1, R2> | ||
{ | ||
public TheoryData_R1_And() | ||
{ | ||
Add( | ||
result => result.And(() => O.B), | ||
O.A, | ||
(O.A, O.B) | ||
); | ||
|
||
//and should return input failure result | ||
Add( | ||
result => result.And(() => O.B), | ||
Errors.ErrorA, | ||
Errors.ErrorA | ||
); | ||
|
||
//nested result should be unwrapped | ||
Add( | ||
result => result.And(() => R1.Success(O.B)), | ||
O.A, | ||
(O.A, O.B) | ||
); | ||
|
||
//and should return input failure result | ||
Add( | ||
result => result.And(() => R1.Success(O.B)), | ||
Errors.ErrorA, | ||
Errors.ErrorA | ||
); | ||
|
||
//and should return error from nested result | ||
Add( | ||
result => result.And<O, O>(() => Errors.ErrorB), | ||
O.A, | ||
Errors.ErrorB | ||
); | ||
|
||
//nested result should be unwrapped | ||
Add( | ||
result => result.And(_ => R1.Success(O.B)), | ||
O.A, | ||
(O.A, O.B) | ||
); | ||
|
||
//and should return input failure result | ||
Add( | ||
result => result.And(_ => R1.Success(O.B)), | ||
Errors.ErrorA, | ||
Errors.ErrorA | ||
); | ||
|
||
//and should return error from nested result | ||
Add( | ||
result => result.And<O, O>(_ => Errors.ErrorB), | ||
O.A, | ||
Errors.ErrorB | ||
); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/RailwayResult.FunctionalExtensions.Tests/AndTests/TheoryData_R1_AndAsync.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,35 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.AndTests; | ||
|
||
public sealed class TheoryData_R1_AndAsync : TheoryData<Func<R1, Task<R2>>, R1, R2> | ||
{ | ||
public TheoryData_R1_AndAsync() | ||
{ | ||
Add( | ||
result => result.AndAsync(_ => Task.FromResult(O.B)), | ||
O.A, | ||
(O.A, O.B) | ||
); | ||
|
||
//and should return input failure result | ||
Add( | ||
result => result.AndAsync(_ => Task.FromResult(O.B)), | ||
Errors.ErrorA, | ||
Errors.ErrorA | ||
); | ||
|
||
// --- TaskOfR1 --- | ||
|
||
Add( | ||
result => Task.FromResult(result).AndAsync(_ => Task.FromResult(O.B)), | ||
O.A, | ||
(O.A, O.B) | ||
); | ||
|
||
//and should return input failure result | ||
Add( | ||
result => Task.FromResult(result).AndAsync(_ => Task.FromResult(O.B)), | ||
Errors.ErrorA, | ||
Errors.ErrorA | ||
); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/RailwayResult.FunctionalExtensions.Tests/AndTests/TheoryData_R2_And.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,28 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.AndTests; | ||
|
||
public sealed class TheoryData_R2_And : TheoryData<Func<R2, R3>, R2, R3> | ||
{ | ||
public TheoryData_R2_And() | ||
{ | ||
//nested result should be unwrapped | ||
Add( | ||
result => result.And((_, _) => R1.Success(O.C)), | ||
(O.A, O.B), | ||
(O.A, O.B, O.C) | ||
); | ||
|
||
//and should return input failure result | ||
Add( | ||
result => result.And((_, _) => R1.Success(O.C)), | ||
Errors.ErrorA, | ||
Errors.ErrorA | ||
); | ||
|
||
//and should return error from nested result | ||
Add( | ||
result => result.And<O, O, O>((_, _) => Errors.ErrorB), | ||
(O.A, O.B), | ||
Errors.ErrorB | ||
); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tests/RailwayResult.FunctionalExtensions.Tests/AndTests/TheoryData_TaskOfR1_And.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,62 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.AndTests; | ||
|
||
public sealed class TheoryData_TaskOfR1_And : TheoryData<Func<Task<R1>, Task<R2>>, R1, R2> | ||
{ | ||
public TheoryData_TaskOfR1_And() | ||
{ | ||
Add( | ||
result => result.And(() => O.B), | ||
O.A, | ||
(O.A, O.B) | ||
); | ||
|
||
//and should return input failure result | ||
Add( | ||
result => result.And(() => O.B), | ||
Errors.ErrorA, | ||
Errors.ErrorA | ||
); | ||
|
||
//nested result should be unwrapped | ||
Add( | ||
result => result.And(() => R1.Success(O.B)), | ||
O.A, | ||
(O.A, O.B) | ||
); | ||
|
||
//and should return input failure result | ||
Add( | ||
result => result.And(() => R1.Success(O.B)), | ||
Errors.ErrorA, | ||
Errors.ErrorA | ||
); | ||
|
||
//and should return error from nested result | ||
Add( | ||
result => result.And<O, O>(() => Errors.ErrorB), | ||
O.A, | ||
Errors.ErrorB | ||
); | ||
|
||
//nested result should be unwrapped | ||
Add( | ||
result => result.And(_ => R1.Success(O.B)), | ||
O.A, | ||
(O.A, O.B) | ||
); | ||
|
||
//and should return input failure result | ||
Add( | ||
result => result.And(_ => R1.Success(O.B)), | ||
Errors.ErrorA, | ||
Errors.ErrorA | ||
); | ||
|
||
//and should return error from nested result | ||
Add( | ||
result => result.And<O, O>(_ => Errors.ErrorB), | ||
O.A, | ||
Errors.ErrorB | ||
); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
tests/RailwayResult.FunctionalExtensions.Tests/AndTests/TheoryData_TaskOfR2_And.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,28 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.AndTests; | ||
|
||
public sealed class TheoryData_TaskOfR2_And : TheoryData<Func<Task<R2>, Task<R3>>, R2, R3> | ||
{ | ||
public TheoryData_TaskOfR2_And() | ||
{ | ||
//nested result should be unwrapped | ||
Add( | ||
result => result.And((_, _) => R1.Success(O.C)), | ||
(O.A, O.B), | ||
(O.A, O.B, O.C) | ||
); | ||
|
||
//and should return input failure result | ||
Add( | ||
result => result.And((_, _) => R1.Success(O.C)), | ||
Errors.ErrorA, | ||
Errors.ErrorA | ||
); | ||
|
||
//and should return error from nested result | ||
Add( | ||
result => result.And<O, O, O>((_, _) => Errors.ErrorB), | ||
(O.A, O.B), | ||
Errors.ErrorB | ||
); | ||
} | ||
} |
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