-
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.
* changed tested object from string to wrapped string (`Ob`j) * added unit tests for `.EnsureNotNull` extension methods
- Loading branch information
1 parent
d120611
commit 06158ac
Showing
16 changed files
with
387 additions
and
45 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
tests/RailwayResult.FunctionalExtensions.Tests/EnsureNotNullTests/EnsureNotNullTests.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,51 @@ | ||
using RailwayResult.FunctionalExtensions.Tests.EnsureTests; | ||
|
||
namespace RailwayResult.FunctionalExtensions.Tests.EnsureNotNullTests; | ||
|
||
public sealed class EnsureNotNullTests | ||
{ | ||
[Theory] | ||
[ClassData(typeof(TheoryData_Obj_EnsureNotNull))] | ||
public void Obj_EnsureNotNull(Func<O?, R1> ensureNotNull, O? input, R1 expectedOutput) | ||
{ | ||
ensureNotNull.Invoke(input).ShouldBe(expectedOutput); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(TheoryData_TaskOfObj_EnsureNotNull))] | ||
public async Task TaskOfObj_EnsureNotNull(Func<Task<O?>, Task<R1>> ensureNotNull, O? input, R1 expectedOutput) | ||
{ | ||
var result = await ensureNotNull.Invoke(Task.FromResult(input)); | ||
result.ShouldBe(expectedOutput); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(TheoryData_R1_EnsureNotNull))] | ||
public void R1_EnsureNotNull(Func<R1N, R1> ensureNotNull, R1N input, R1 expectedOutput) | ||
{ | ||
ensureNotNull.Invoke(input).ShouldBe(expectedOutput); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(TheoryData_TaskOfR1_EnsureNotNull))] | ||
public async Task TaskOfR1_EnsureNotNull(Func<Task<R1N>, Task<R1>> ensureNotNull, R1N input, R1 expectedOutput) | ||
{ | ||
var result = await ensureNotNull.Invoke(Task.FromResult(input)); | ||
result.ShouldBe(expectedOutput); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(TheoryData_R2_EnsureNotNull))] | ||
public void R2_EnsureNotNull(Func<R2N, R2> ensureNotNull, R2N input, R2 expectedOutput) | ||
{ | ||
ensureNotNull.Invoke(input).ShouldBe(expectedOutput); | ||
} | ||
|
||
[Theory] | ||
[ClassData(typeof(TheoryData_TaskOfR2_EnsureNotNull))] | ||
public async Task TaskOfR2_EnsureNotNull(Func<Task<R2N>, Task<R2>> ensureNotNull, R2N input, R2 expectedOutput) | ||
{ | ||
var result = await ensureNotNull.Invoke(Task.FromResult(input)); | ||
result.ShouldBe(expectedOutput); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...ilwayResult.FunctionalExtensions.Tests/EnsureNotNullTests/TheoryData_Obj_EnsureNotNull.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,21 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.EnsureTests; | ||
|
||
public sealed class TheoryData_Obj_EnsureNotNull : TheoryData<Func<O?, R1>, O?, R1> | ||
{ | ||
public TheoryData_Obj_EnsureNotNull() | ||
{ | ||
//ensure should pass | ||
Add( | ||
result => result.EnsureNotNull(Errors.ErrorA), | ||
O.Empty, | ||
O.Empty | ||
); | ||
|
||
//ensure should fail | ||
Add( | ||
result => result.EnsureNotNull(Errors.ErrorA), | ||
null, | ||
Errors.ErrorA | ||
); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ailwayResult.FunctionalExtensions.Tests/EnsureNotNullTests/TheoryData_R1_EnsureNotNull.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,49 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.EnsureTests; | ||
|
||
public sealed class TheoryData_R1_EnsureNotNull : TheoryData<Func<R1N, R1>, R1N, R1> | ||
{ | ||
public TheoryData_R1_EnsureNotNull() | ||
{ | ||
//ensure should pass | ||
Add( | ||
result => result.EnsureNotNull(Errors.ErrorA), | ||
O.Empty, | ||
O.Empty | ||
); | ||
|
||
//ensure should fail | ||
Add( | ||
result => result.EnsureNotNull(Errors.ErrorA), | ||
R1N.Success(null), | ||
Errors.ErrorA | ||
); | ||
|
||
//ensure should return input failure result | ||
Add( | ||
result => result.EnsureNotNull(Errors.ErrorA), | ||
Errors.ErrorD, | ||
Errors.ErrorD | ||
); | ||
|
||
//ensure with selector should pass | ||
Add( | ||
result => result.EnsureNotNull(o => o!.Value, Errors.ErrorA)!, | ||
O.Empty, | ||
O.Empty | ||
); | ||
|
||
//ensure with selector should fail | ||
Add( | ||
result => result.EnsureNotNull(o => o!.Value, Errors.ErrorA)!, | ||
O.Null, | ||
Errors.ErrorA | ||
); | ||
|
||
//ensure with selector should return input failure result | ||
Add( | ||
result => result.EnsureNotNull(o => o!.Value, Errors.ErrorA)!, | ||
Errors.ErrorD, | ||
Errors.ErrorD | ||
); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...ailwayResult.FunctionalExtensions.Tests/EnsureNotNullTests/TheoryData_R2_EnsureNotNull.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 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.EnsureTests; | ||
|
||
public sealed class TheoryData_R2_EnsureNotNull : TheoryData<Func<R2N, R2>, R2N, R2> | ||
{ | ||
public TheoryData_R2_EnsureNotNull() | ||
{ | ||
//ensure should pass | ||
Add( | ||
result => result.EnsureNotNull((a, _) => a, Errors.ErrorA)!, | ||
(O.Empty, null), | ||
(O.Empty, null)! | ||
); | ||
|
||
//ensure should pass | ||
Add( | ||
result => result.EnsureNotNull((_, b) => b, Errors.ErrorA)!, | ||
(null, O.Empty), | ||
(null, O.Empty)! | ||
); | ||
|
||
//ensure should fail | ||
Add( | ||
result => result.EnsureNotNull((a, _) => a, Errors.ErrorA)!, | ||
(null, O.Empty), | ||
Errors.ErrorA | ||
); | ||
|
||
//ensure should fail | ||
Add( | ||
result => result.EnsureNotNull((_, b) => b, Errors.ErrorA)!, | ||
(O.Empty, null), | ||
Errors.ErrorA | ||
); | ||
|
||
//ensure should return input failure result | ||
Add( | ||
result => result.EnsureNotNull((a, _) => a, Errors.ErrorA)!, | ||
Errors.ErrorD, | ||
Errors.ErrorD | ||
); | ||
|
||
//ensure should return input failure result | ||
Add( | ||
result => result.EnsureNotNull((_, b) => b, Errors.ErrorA)!, | ||
Errors.ErrorD, | ||
Errors.ErrorD | ||
); | ||
|
||
//ensure should pass | ||
Add( | ||
result => result.EnsureSecondNotNull(Errors.ErrorA)!, | ||
(null, O.Empty), | ||
(null, O.Empty)! | ||
); | ||
|
||
//ensure should fail | ||
Add( | ||
result => result.EnsureSecondNotNull(Errors.ErrorA)!, | ||
(O.Empty, null), | ||
Errors.ErrorA | ||
); | ||
|
||
//ensure should return input failure result | ||
Add( | ||
result => result.EnsureSecondNotNull(Errors.ErrorA)!, | ||
Errors.ErrorD, | ||
Errors.ErrorD | ||
); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...esult.FunctionalExtensions.Tests/EnsureNotNullTests/TheoryData_TaskOfObj_EnsureNotNull.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,21 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.EnsureTests; | ||
|
||
public sealed class TheoryData_TaskOfObj_EnsureNotNull : TheoryData<Func<Task<O?>, Task<R1>>, O?, R1> | ||
{ | ||
public TheoryData_TaskOfObj_EnsureNotNull() | ||
{ | ||
//ensure should pass | ||
Add( | ||
result => result.EnsureNotNull(Errors.ErrorA), | ||
O.Empty, | ||
O.Empty | ||
); | ||
|
||
//ensure should fail | ||
Add( | ||
result => result.EnsureNotNull(Errors.ErrorA), | ||
null, | ||
Errors.ErrorA | ||
); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...Result.FunctionalExtensions.Tests/EnsureNotNullTests/TheoryData_TaskOfR1_EnsureNotNull.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,49 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.EnsureTests; | ||
|
||
public sealed class TheoryData_TaskOfR1_EnsureNotNull : TheoryData<Func<Task<R1N>, Task<R1>>, R1N, R1> | ||
{ | ||
public TheoryData_TaskOfR1_EnsureNotNull() | ||
{ | ||
//ensure should pass | ||
Add( | ||
result => result.EnsureNotNull(Errors.ErrorA), | ||
O.Empty, | ||
O.Empty | ||
); | ||
|
||
//ensure should fail | ||
Add( | ||
result => result.EnsureNotNull(Errors.ErrorA), | ||
R1N.Success(null), | ||
Errors.ErrorA | ||
); | ||
|
||
//ensure should return input failure result | ||
Add( | ||
result => result.EnsureNotNull(Errors.ErrorA), | ||
Errors.ErrorD, | ||
Errors.ErrorD | ||
); | ||
|
||
//ensure with selector should pass | ||
Add( | ||
result => result.EnsureNotNull(o => o!.Value, Errors.ErrorA)!, | ||
O.Empty, | ||
O.Empty | ||
); | ||
|
||
//ensure with selector should fail | ||
Add( | ||
result => result.EnsureNotNull(o => o!.Value, Errors.ErrorA)!, | ||
O.Null, | ||
Errors.ErrorA | ||
); | ||
|
||
//ensure with selector should return input failure result | ||
Add( | ||
result => result.EnsureNotNull(o => o!.Value, Errors.ErrorA)!, | ||
Errors.ErrorD, | ||
Errors.ErrorD | ||
); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
...Result.FunctionalExtensions.Tests/EnsureNotNullTests/TheoryData_TaskOfR2_EnsureNotNull.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 @@ | ||
namespace RailwayResult.FunctionalExtensions.Tests.EnsureTests; | ||
|
||
public sealed class TheoryData_TaskOfR2_EnsureNotNull : TheoryData<Func<Task<R2N>, Task<R2>>, R2N, R2> | ||
{ | ||
public TheoryData_TaskOfR2_EnsureNotNull() | ||
{ | ||
//ensure should pass | ||
Add( | ||
result => result.EnsureNotNull((a, _) => a, Errors.ErrorA)!, | ||
(O.Empty, null), | ||
(O.Empty, null)! | ||
); | ||
|
||
//ensure should pass | ||
Add( | ||
result => result.EnsureNotNull((_, b) => b, Errors.ErrorA)!, | ||
(null, O.Empty), | ||
(null, O.Empty)! | ||
); | ||
|
||
//ensure should fail | ||
Add( | ||
result => result.EnsureNotNull((a, _) => a, Errors.ErrorA)!, | ||
(null, O.Empty), | ||
Errors.ErrorA | ||
); | ||
|
||
//ensure should fail | ||
Add( | ||
result => result.EnsureNotNull((_, b) => b, Errors.ErrorA)!, | ||
(O.Empty, null), | ||
Errors.ErrorA | ||
); | ||
|
||
//ensure should return input failure result | ||
Add( | ||
result => result.EnsureNotNull((a, _) => a, Errors.ErrorA)!, | ||
Errors.ErrorD, | ||
Errors.ErrorD | ||
); | ||
|
||
//ensure should return input failure result | ||
Add( | ||
result => result.EnsureNotNull((_, b) => b, Errors.ErrorA)!, | ||
Errors.ErrorD, | ||
Errors.ErrorD | ||
); | ||
|
||
//ensure should pass | ||
Add( | ||
result => result.EnsureSecondNotNull(Errors.ErrorA)!, | ||
(null, O.Empty), | ||
(null, O.Empty)! | ||
); | ||
|
||
//ensure should fail | ||
Add( | ||
result => result.EnsureSecondNotNull(Errors.ErrorA)!, | ||
(O.Empty, null), | ||
Errors.ErrorA | ||
); | ||
|
||
//ensure should return input failure result | ||
Add( | ||
result => result.EnsureSecondNotNull(Errors.ErrorA)!, | ||
Errors.ErrorD, | ||
Errors.ErrorD | ||
); | ||
} | ||
} |
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.