-
Notifications
You must be signed in to change notification settings - Fork 304
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 #246 from mingazhev/ChangeCheckToTap
Changed some Tap and TapIf overloads to Check and CheckIf
- Loading branch information
Showing
42 changed files
with
1,089 additions
and
746 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
50 changes: 50 additions & 0 deletions
50
CSharpFunctionalExtensions.Tests/ResultTests/Extensions/CheckAsyncBothTests.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,50 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CSharpFunctionalExtensions.Tests.ResultTests.Extensions | ||
{ | ||
public class CheckAsyncBothTests : CheckTestsBase | ||
{ | ||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void Check_T_AsyncBoth_func_result(bool resultSuccess, bool funcSuccess) | ||
{ | ||
Result<T> result = Result.SuccessIf(resultSuccess, T.Value, ErrorMessage); | ||
|
||
var returned = result.AsTask().Check(_ => GetResult(funcSuccess).AsTask()).Result; | ||
|
||
actionExecuted.Should().Be(resultSuccess); | ||
returned.Should().Be(funcSuccess ? result : FailedResultT); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void Check_T_AsyncBoth_func_result_K(bool resultSuccess, bool funcSuccess) | ||
{ | ||
Result<T> result = Result.SuccessIf(resultSuccess, T.Value, ErrorMessage); | ||
|
||
var returned = result.AsTask().Check(Func_Task_Result_K(funcSuccess)).Result; | ||
|
||
actionExecuted.Should().Be(resultSuccess); | ||
returned.Should().Be(funcSuccess ? result : FailedResultT); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void Check_T_AsyncBoth_func_result_KE(bool resultSuccess, bool funcSuccess) | ||
{ | ||
Result<T, E> result = Result.SuccessIf(resultSuccess, T.Value, E.Value); | ||
|
||
var returned = result.AsTask().Check(Func_Task_Result_KE(funcSuccess)).Result; | ||
|
||
actionExecuted.Should().Be(resultSuccess); | ||
returned.Should().Be(funcSuccess ? result : returned); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
CSharpFunctionalExtensions.Tests/ResultTests/Extensions/CheckAsyncLeftTests.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,50 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CSharpFunctionalExtensions.Tests.ResultTests.Extensions | ||
{ | ||
public class CheckAsyncLeftTests : CheckTestsBase | ||
{ | ||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void Check_T_AsyncLeft_func_result(bool resultSuccess, bool funcSuccess) | ||
{ | ||
Result<T> result = Result.SuccessIf(resultSuccess, T.Value, ErrorMessage); | ||
|
||
var returned = result.AsTask().Check(_ => GetResult(funcSuccess)).Result; | ||
|
||
actionExecuted.Should().Be(resultSuccess); | ||
returned.Should().Be(funcSuccess ? result : FailedResultT); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void Check_T_AsyncLeft_func_result_KE(bool resultSuccess, bool funcSuccess) | ||
{ | ||
Result<T, E> result = Result.SuccessIf(resultSuccess, T.Value, E.Value); | ||
|
||
var returned = result.AsTask().Check(Func_Result_KE(funcSuccess)).Result; | ||
|
||
actionExecuted.Should().Be(resultSuccess); | ||
returned.Should().Be(funcSuccess ? result : returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void Check_T_AsyncLeft_func_result_K(bool resultSuccess, bool funcSuccess) | ||
{ | ||
Result<T> result = Result.SuccessIf(resultSuccess, T.Value, ErrorMessage); | ||
|
||
var returned = result.AsTask().Check(Func_Result_K(funcSuccess)).Result; | ||
|
||
actionExecuted.Should().Be(resultSuccess); | ||
returned.Should().Be(funcSuccess ? result : FailedResultT); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
CSharpFunctionalExtensions.Tests/ResultTests/Extensions/CheckAsyncRightTests.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,50 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CSharpFunctionalExtensions.Tests.ResultTests.Extensions | ||
{ | ||
public class CheckAsyncRightTests : CheckTestsBase | ||
{ | ||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void Check_T_AsyncRight_func_result(bool resultSuccess, bool funcSuccess) | ||
{ | ||
Result<T> result = Result.SuccessIf(resultSuccess, T.Value, ErrorMessage); | ||
|
||
var returned = result.Check(_ => GetResult(funcSuccess).AsTask()).Result; | ||
|
||
actionExecuted.Should().Be(resultSuccess); | ||
returned.Should().Be(funcSuccess ? result : FailedResultT); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void Check_T_AsyncRight_func_result_KE(bool resultSuccess, bool funcSuccess) | ||
{ | ||
Result<T, E> result = Result.SuccessIf(resultSuccess, T.Value, E.Value); | ||
|
||
var returned = result.Check(Func_Task_Result_KE(funcSuccess)).Result; | ||
|
||
actionExecuted.Should().Be(resultSuccess); | ||
returned.Should().Be(funcSuccess ? result : returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, false)] | ||
public void Check_T_AsyncRight_func_result_K(bool resultSuccess, bool funcSuccess) | ||
{ | ||
Result<T> result = Result.SuccessIf(resultSuccess, T.Value, ErrorMessage); | ||
|
||
var returned = result.Check(Func_Task_Result_K(funcSuccess)).Result; | ||
|
||
actionExecuted.Should().Be(resultSuccess); | ||
returned.Should().Be(funcSuccess ? result : FailedResultT); | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
CSharpFunctionalExtensions.Tests/ResultTests/Extensions/CheckIfAsyncBothTests.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,98 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CSharpFunctionalExtensions.Tests.ResultTests.Extensions | ||
{ | ||
public class CheckIfAsyncBothTests : CheckIfTestsBase | ||
{ | ||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_AsyncBoth_executes_func_result_T_conditionally_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool> result = Result.SuccessIf(isSuccess, condition, ErrorMessage); | ||
|
||
var returned = result.AsTask().CheckIf(condition, Task_Func_Result).Result; | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_AsyncBoth_executes_func_result_K_conditionally_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool> result = Result.SuccessIf(isSuccess, condition, ErrorMessage); | ||
|
||
var returned = result.AsTask().CheckIf(condition, Task_Func_Result_K).Result; | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_AsyncBoth_executes_func_result_K_E_conditionally_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool, E> result = Result.SuccessIf(isSuccess, condition, E.Value); | ||
|
||
var returned = result.AsTask().CheckIf(condition, Task_Func_Result_K_E).Result; | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_AsyncBoth_executes_func_result_T_per_predicate_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool> result = Result.SuccessIf(isSuccess, condition, ErrorMessage); | ||
|
||
var returned = result.AsTask().CheckIf(Predicate, Task_Func_Result).Result; | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_AsyncBoth_executes_func_result_K_per_predicate_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool> result = Result.SuccessIf(isSuccess, condition, ErrorMessage); | ||
|
||
var returned = result.AsTask().CheckIf(Predicate, Task_Func_Result_K).Result; | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_AsyncBoth_executes_func_result_K_E_per_predicate_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool, E> result = Result.SuccessIf(isSuccess, condition, E.Value); | ||
|
||
var returned = result.AsTask().CheckIf(Predicate, Task_Func_Result_K_E).Result; | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
CSharpFunctionalExtensions.Tests/ResultTests/Extensions/CheckIfTests.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,98 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CSharpFunctionalExtensions.Tests.ResultTests.Extensions | ||
{ | ||
public class CheckIfTests : CheckIfTestsBase | ||
{ | ||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_executes_func_result_T_conditionally_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool> result = Result.SuccessIf(isSuccess, condition, ErrorMessage); | ||
|
||
var returned = result.CheckIf(condition, Func_Result); | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_executes_func_result_K_conditionally_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool> result = Result.SuccessIf(isSuccess, condition, ErrorMessage); | ||
|
||
var returned = result.CheckIf(condition, Func_Result_K); | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_executes_func_result_K_E_conditionally_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool, E> result = Result.SuccessIf(isSuccess, condition, E.Value); | ||
|
||
var returned = result.CheckIf(condition, Func_Result_K_E); | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_executes_func_result_K_per_predicate_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool> result = Result.SuccessIf(isSuccess, condition, ErrorMessage); | ||
|
||
var returned = result.CheckIf(Predicate, Func_Result_K); | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_executes_func_result_K_E_per_predicate_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool, E> result = Result.SuccessIf(isSuccess, condition, E.Value); | ||
|
||
var returned = result.CheckIf(Predicate, Func_Result_K_E); | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
|
||
[Theory] | ||
[InlineData(true, true)] | ||
[InlineData(true, false)] | ||
[InlineData(false, true)] | ||
[InlineData(false, false)] | ||
public void CheckIf_T_executes_func_result_T_per_predicate_and_returns_self(bool isSuccess, bool condition) | ||
{ | ||
Result<bool> result = Result.SuccessIf(isSuccess, condition, ErrorMessage); | ||
|
||
var returned = result.CheckIf(Predicate, Func_Result); | ||
|
||
actionExecuted.Should().Be(isSuccess && condition); | ||
result.Should().Be(returned); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
CSharpFunctionalExtensions.Tests/ResultTests/Extensions/CheckIfTestsBase.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,27 @@ | ||
using System.Threading.Tasks; | ||
|
||
namespace CSharpFunctionalExtensions.Tests.ResultTests.Extensions | ||
{ | ||
public abstract class CheckIfTestsBase : TestBase | ||
{ | ||
protected bool actionExecuted; | ||
protected bool predicateExecuted; | ||
|
||
protected CheckIfTestsBase() | ||
{ | ||
actionExecuted = false; | ||
predicateExecuted = false; | ||
} | ||
|
||
protected Result Func_Result(bool _) { actionExecuted = true; return Result.Success(); } | ||
|
||
protected Result<K> Func_Result_K(bool _) { actionExecuted = true; return Result.Success<K>(K.Value); } | ||
protected Result<K,E> Func_Result_K_E(bool _) { actionExecuted = true; return Result.Success<K, E>(K.Value); } | ||
|
||
protected Task<Result> Task_Func_Result(bool _) { actionExecuted = true; return Result.Success().AsTask(); } | ||
protected Task<Result<K>> Task_Func_Result_K(bool _) { actionExecuted = true; return Result.Success<K>(K.Value).AsTask(); } | ||
protected Task<Result<K, E>> Task_Func_Result_K_E(bool _) { actionExecuted = true; return Result.Success<K, E>(K.Value).AsTask(); } | ||
|
||
protected bool Predicate(bool b) { predicateExecuted = true; return b; } | ||
} | ||
} |
Oops, something went wrong.