-
Notifications
You must be signed in to change notification settings - Fork 309
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 #588 from bothzoli/feature/maybe-to-inverted-result
Create `ToInvertedResult` extension methods on Maybe
- Loading branch information
Showing
19 changed files
with
440 additions
and
167 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
74 changes: 74 additions & 0 deletions
74
CSharpFunctionalExtensions.Tests/MaybeTests/Extensions/ToInvertedResultTests.Task.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,74 @@ | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CSharpFunctionalExtensions.Tests.MaybeTests.Extensions | ||
{ | ||
public class ToInvertedResultTests_Task : MaybeTestBase | ||
{ | ||
[Fact] | ||
public async Task ToInvertedResult_Task_returns_failure_if_has_value() | ||
{ | ||
var maybe = Maybe<T>.From(T.Value); | ||
|
||
var result = await maybe.AsTask().ToInvertedResult("Error"); | ||
|
||
result.IsSuccess.Should().BeFalse(); | ||
result.Error.Should().Be("Error"); | ||
} | ||
|
||
[Fact] | ||
public async Task ToInvertedResult_Task_returns_success_if_has_no_value() | ||
{ | ||
Maybe<T> maybe = null; | ||
|
||
var result = await maybe.AsTask().ToInvertedResult("Error"); | ||
|
||
result.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task ToInvertedResult_Task_returns_custom_failure_if_has_value() | ||
{ | ||
var maybe = Maybe<T>.From(T.Value); | ||
|
||
var result = await maybe.AsTask().ToInvertedResult(E.Value); | ||
|
||
result.IsSuccess.Should().BeFalse(); | ||
result.Error.Should().Be(E.Value); | ||
} | ||
|
||
[Fact] | ||
public async Task ToInvertedResult_Task_custom_failure_returns_success_if_has_no_value() | ||
{ | ||
Maybe<T> maybe = null; | ||
|
||
var result = await maybe.AsTask().ToInvertedResult(E.Value); | ||
|
||
result.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task ToInvertedResult_Task_returns_custom_failure_via_error_function_if_has_value() | ||
{ | ||
var maybe = Maybe<T>.From(T.Value); | ||
|
||
var result = await maybe.AsTask().ToInvertedResult(ErrorFunc); | ||
|
||
result.IsSuccess.Should().BeFalse(); | ||
result.Error.Should().Be(E.Value); | ||
AssertErrorFuncCalled(); | ||
} | ||
|
||
[Fact] | ||
public async Task ToInvertedResult_Task_custom_failure_with_error_function_returns_success_if_has_no_value() | ||
{ | ||
Maybe<T> maybe = null; | ||
|
||
var result = await maybe.AsTask().ToInvertedResult(ErrorFunc); | ||
|
||
result.IsSuccess.Should().BeTrue(); | ||
AssertErrorFuncNotCalled(); | ||
} | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
CSharpFunctionalExtensions.Tests/MaybeTests/Extensions/ToInvertedResultTests.ValueTask.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,74 @@ | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CSharpFunctionalExtensions.Tests.MaybeTests.Extensions | ||
{ | ||
public class ToInvertedResultTests_ValueTask : MaybeTestBase | ||
{ | ||
[Fact] | ||
public async Task ToInvertedResult_ValueTask_returns_failure_if_has_value() | ||
{ | ||
var maybe = Maybe<T>.From(T.Value); | ||
|
||
var result = await maybe.AsValueTask().ToInvertedResult("Error"); | ||
|
||
result.IsSuccess.Should().BeFalse(); | ||
result.Error.Should().Be("Error"); | ||
} | ||
|
||
[Fact] | ||
public async Task ToInvertedResult_ValueTask_returns_success_if_has_no_value() | ||
{ | ||
Maybe<T> maybe = null; | ||
|
||
var result = await maybe.AsValueTask().ToInvertedResult("Error"); | ||
|
||
result.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task ToInvertedResult_ValueTask_returns_custom_failure_if_has_value() | ||
{ | ||
var maybe = Maybe<T>.From(T.Value); | ||
|
||
var result = await maybe.AsValueTask().ToInvertedResult(E.Value); | ||
|
||
result.IsSuccess.Should().BeFalse(); | ||
result.Error.Should().Be(E.Value); | ||
} | ||
|
||
[Fact] | ||
public async Task ToInvertedResult_ValueTask_custom_failure_returns_success_if_has_no_value() | ||
{ | ||
Maybe<T> maybe = null; | ||
|
||
var result = await maybe.AsValueTask().ToInvertedResult(E.Value); | ||
|
||
result.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public async Task ToInvertedResult_ValueTask_returns_custom_failure_via_error_function_if_has_value() | ||
{ | ||
var maybe = Maybe<T>.From(T.Value); | ||
|
||
var result = await maybe.AsValueTask().ToInvertedResult(ErrorFunc); | ||
|
||
result.IsSuccess.Should().BeFalse(); | ||
result.Error.Should().Be(E.Value); | ||
AssertErrorFuncCalled(); | ||
} | ||
|
||
[Fact] | ||
public async Task ToInvertedResult_ValueTask_custom_failure_with_error_function_returns_success_if_has_no_value() | ||
{ | ||
Maybe<T> maybe = null; | ||
|
||
var result = await maybe.AsValueTask().ToInvertedResult(ErrorFunc); | ||
|
||
result.IsSuccess.Should().BeTrue(); | ||
AssertErrorFuncNotCalled(); | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
CSharpFunctionalExtensions.Tests/MaybeTests/Extensions/ToInvertedResultTests.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,73 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CSharpFunctionalExtensions.Tests.MaybeTests.Extensions | ||
{ | ||
public class ToInvertedResultTests : MaybeTestBase | ||
{ | ||
[Fact] | ||
public void ToInvertedResult_returns_failure_if_has_value() | ||
{ | ||
var maybe = Maybe<T>.From(T.Value); | ||
|
||
var result = maybe.ToInvertedResult("Error"); | ||
|
||
result.IsSuccess.Should().BeFalse(); | ||
result.Error.Should().Be("Error"); | ||
} | ||
|
||
[Fact] | ||
public void ToInvertedResult_returns_success_if_has_no_value() | ||
{ | ||
Maybe<T> maybe = null; | ||
|
||
var result = maybe.ToInvertedResult("Error"); | ||
|
||
result.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void ToInvertedResult_returns_custom_failure_if_has_value() | ||
{ | ||
var maybe = Maybe<T>.From(T.Value); | ||
|
||
var result = maybe.ToInvertedResult(E.Value); | ||
|
||
result.IsSuccess.Should().BeFalse(); | ||
result.Error.Should().Be(E.Value); | ||
} | ||
|
||
[Fact] | ||
public void ToInvertedResult_custom_failure_returns_success_if_has_no_value() | ||
{ | ||
Maybe<T> maybe = null; | ||
|
||
var result = maybe.ToInvertedResult(E.Value); | ||
|
||
result.IsSuccess.Should().BeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void ToInvertedResult_returns_custom_failure_via_error_function_if_has_value() | ||
{ | ||
Maybe<T> maybe = Maybe<T>.From(T.Value); | ||
|
||
var result = maybe.ToInvertedResult(ErrorFunc); | ||
|
||
result.IsSuccess.Should().BeFalse(); | ||
result.Error.Should().Be(E.Value); | ||
AssertErrorFuncCalled(); | ||
} | ||
|
||
[Fact] | ||
public void ToInvertedResult_custom_failure_with_error_function_returns_success_if_has_no_value() | ||
{ | ||
Maybe<T> maybe = null; | ||
|
||
var result = maybe.ToInvertedResult(ErrorFunc); | ||
|
||
result.IsSuccess.Should().BeTrue(); | ||
AssertErrorFuncNotCalled(); | ||
} | ||
} | ||
} |
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.