-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Map Extension Method to Support Mapping from Result<T> to Result (#…
…213)
- Loading branch information
Showing
2 changed files
with
159 additions
and
0 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
125 changes: 125 additions & 0 deletions
125
tests/Ardalis.Result.UnitTests/ResultGenericToVoidMap.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,125 @@ | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using System; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Ardalis.Result.UnitTests; | ||
|
||
public class ResultGenericToVoidMap | ||
{ | ||
[Fact] | ||
public void ShouldProduceSuccess() | ||
{ | ||
var result = Result<int>.Success(1); | ||
|
||
var actual = result.Map(); | ||
|
||
actual.Status.Should().Be(ResultStatus.Ok); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProduceNotFound() | ||
{ | ||
var result = Result<int>.NotFound(); | ||
|
||
var actual = result.Map(); | ||
|
||
actual.Status.Should().Be(ResultStatus.NotFound); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProduceUnauthorized() | ||
{ | ||
var result = Result<int>.Unauthorized(); | ||
|
||
var actual = result.Map(); | ||
|
||
actual.Status.Should().Be(ResultStatus.Unauthorized); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProduceForbidden() | ||
{ | ||
var result = Result<int>.Forbidden(); | ||
|
||
var actual = result.Map(); | ||
|
||
actual.Status.Should().Be(ResultStatus.Forbidden); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProduceInvalid() | ||
{ | ||
var result = Result<int>.Invalid(new ValidationError()); | ||
|
||
var actual = result.Map(); | ||
|
||
actual.Status.Should().Be(ResultStatus.Invalid); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProduceError() | ||
{ | ||
var result = Result<int>.Error(); | ||
|
||
var actual = result.Map(); | ||
|
||
actual.Status.Should().Be(ResultStatus.Error); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProduceErrorWhenConstructedWithErrorList() | ||
{ | ||
string correlationId = Guid.NewGuid().ToString(); | ||
string errorMessage = "Error occured 💥"; | ||
var result = Result<int>.Error(new ErrorList([errorMessage], correlationId)); | ||
|
||
var actual = result.Map(); | ||
|
||
using var assertionScope = new AssertionScope(); | ||
actual.Status.Should().Be(ResultStatus.Error); | ||
actual.CorrelationId.Should().Be(correlationId); | ||
actual.Errors.Single().Should().Be(errorMessage); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProduceConflict() | ||
{ | ||
var result = Result<int>.Conflict(); | ||
|
||
var actual = result.Map(); | ||
|
||
actual.Status.Should().Be(ResultStatus.Conflict); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProduceCriticalError() | ||
{ | ||
var result = Result<int>.CriticalError(); | ||
|
||
var actual = result.Map(); | ||
|
||
actual.Status.Should().Be(ResultStatus.CriticalError); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProduceUnavailable() | ||
{ | ||
var result = Result<int>.Unavailable(); | ||
|
||
var actual = result.Map(); | ||
|
||
actual.Status.Should().Be(ResultStatus.Unavailable); | ||
} | ||
|
||
[Fact] | ||
public void ShouldProduceNoContent() | ||
{ | ||
var result = Result<int>.NoContent(); | ||
|
||
var actual = result.Map(); | ||
|
||
actual.Status.Should().Be(ResultStatus.NoContent); | ||
} | ||
} |