-
Notifications
You must be signed in to change notification settings - Fork 104
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
Showing
15 changed files
with
309 additions
and
69 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
11 changes: 11 additions & 0 deletions
11
sample/Ardalis.Result.Sample.Core/Services/BadResultService.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,11 @@ | ||
namespace Ardalis.Result.Sample.Core.Services; | ||
|
||
public class BadResultService | ||
{ | ||
public Result ReturnErrorWithMessage(string message) | ||
{ | ||
var result = Result.Error(message); | ||
return result; | ||
} | ||
|
||
} |
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
20 changes: 20 additions & 0 deletions
20
...le/Ardalis.Result.Sample.UnitTests/ServiceTests/BadResultService_ReturnResultWithError.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,20 @@ | ||
using System.Linq; | ||
using Ardalis.Result.Sample.Core.Services; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Ardalis.Result.Sample.UnitTests.ServiceTests; | ||
|
||
public class BadResultService_ReturnResultWithError | ||
{ | ||
[Fact] | ||
public void ReturnsErrorResultGivenMessage() | ||
{ | ||
var service = new BadResultService(); | ||
|
||
var result = service.ReturnErrorWithMessage("Some error message"); | ||
|
||
result.Status.Should().Be(ResultStatus.Error); | ||
result.Errors.Single().Should().Be("Some error message"); | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
namespace Ardalis.Result; | ||
|
||
public static class IResultExtensions | ||
{ | ||
/// <summary> | ||
/// Returns true if the result is successful (status is Ok). | ||
/// </summary> | ||
public static bool IsOk(this IResult result) => result.Status == ResultStatus.Ok; | ||
|
||
/// <summary> | ||
/// Returns true if the result is created (status is Created). | ||
/// </summary> | ||
public static bool IsCreated(this IResult result) => result.Status == ResultStatus.Created; | ||
|
||
/// <summary> | ||
/// Returns true if the result is an error (status is Error). | ||
/// </summary> | ||
public static bool IsError(this IResult result) => result.Status == ResultStatus.Error; | ||
|
||
/// <summary> | ||
/// Returns true if the result is forbidden (status is Forbidden). | ||
/// </summary> | ||
public static bool IsForbidden(this IResult result) => result.Status == ResultStatus.Forbidden; | ||
|
||
/// <summary> | ||
/// Returns true if the result is unauthorized (status is Unauthorized). | ||
/// </summary> | ||
public static bool IsUnauthorized(this IResult result) => result.Status == ResultStatus.Unauthorized; | ||
|
||
/// <summary> | ||
/// Returns true if the result is invalid (status is Invalid). | ||
/// </summary> | ||
public static bool IsInvalid(this IResult result) => result.Status == ResultStatus.Invalid; | ||
|
||
/// <summary> | ||
/// Returns true if the result is not found (status is NotFound). | ||
/// </summary> | ||
public static bool IsNotFound(this IResult result) => result.Status == ResultStatus.NotFound; | ||
|
||
/// <summary> | ||
/// Returns true if the result is no content (status is NoContent). | ||
/// </summary> | ||
public static bool IsNoContent(this IResult result) => result.Status == ResultStatus.NoContent; | ||
|
||
/// <summary> | ||
/// Returns true if the result is a conflict (status is Conflict). | ||
/// </summary> | ||
public static bool IsConflict(this IResult result) => result.Status == ResultStatus.Conflict; | ||
|
||
/// <summary> | ||
/// Returns true if the result is a critical error (status is CriticalError). | ||
/// </summary> | ||
public static bool IsCriticalError(this IResult result) => result.Status == ResultStatus.CriticalError; | ||
|
||
/// <summary> | ||
/// Returns true if the result is unavailable (status is Unavailable). | ||
/// </summary> | ||
public static bool IsUnavailable(this IResult result) => result.Status == ResultStatus.Unavailable; | ||
} |
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.