-
-
Notifications
You must be signed in to change notification settings - Fork 1
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 #290 from bfren/289-make-result-class-implement-ia…
…ctionresult Implementing IActionResult in Result class - #289
- Loading branch information
Showing
14 changed files
with
283 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
8.0.0-beta.220410.1 | ||
8.0.0-beta.220412.1 |
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,39 @@ | ||
// Jeebs Rapid Application Development | ||
// Copyright (c) bfren - licensed under https://mit.bfren.dev/2013 | ||
|
||
using Jeebs.Mvc.Models; | ||
|
||
namespace Jeebs.Mvc; | ||
|
||
/// <summary> | ||
/// Represents the result of an operation | ||
/// </summary> | ||
/// <typeparam name="T">Value type</typeparam> | ||
public interface IResult<out T> | ||
{ | ||
/// <summary> | ||
/// Returns true if the operation was a success | ||
/// </summary> | ||
bool Success { get; } | ||
|
||
/// <summary> | ||
/// User feedback alert message - by default returns 'Success' or the Reason message, | ||
/// but can be set to display something else | ||
/// </summary> | ||
Alert Message { get; } | ||
|
||
/// <summary> | ||
/// Returns the value if the operation succeeded, or null if not | ||
/// </summary> | ||
T? Value { get; } | ||
|
||
/// <summary> | ||
/// HTTP status code - by default returns 200 on success or 500 on failure | ||
/// </summary> | ||
int StatusCode { get; } | ||
|
||
/// <summary> | ||
/// Optional URL to redirect to on success | ||
/// </summary> | ||
string? RedirectTo { get; } | ||
} |
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,43 @@ | ||
// Jeebs Unit Tests | ||
// Copyright (c) bfren - licensed under https://mit.bfren.dev/2013 | ||
|
||
using Jeebs.Mvc.Models; | ||
using MaybeF; | ||
|
||
namespace Jeebs.Mvc.Result_Tests; | ||
public class Create_Tests | ||
{ | ||
[Fact] | ||
public void With_Value__Sets_Value() | ||
{ | ||
// Arrange | ||
var value = Rnd.Guid; | ||
|
||
// Act | ||
var r0 = Result.Create(value); | ||
var r1 = Result.Create(F.Some(value)); | ||
|
||
// Assert | ||
Assert.Equal(value, r0.Value); | ||
Assert.Equal(value, r1.Value); | ||
} | ||
|
||
[Fact] | ||
public void With_Value_And_Message__Sets_Value_And_Message() | ||
{ | ||
// Arrange | ||
var value = Rnd.Guid; | ||
var message = Alert.Warning(Rnd.Str); | ||
|
||
// Act | ||
var r0 = Result.Create(value, message); | ||
var r1 = Result.Create(F.Some(value), message); | ||
|
||
// Assert | ||
Assert.Equal(value, r0.Value); | ||
Assert.Equal(message, r0.Message); | ||
Assert.Equal(value, r1.Value); | ||
Assert.Equal(value, r1.Value); | ||
Assert.Equal(message, r1.Message); | ||
} | ||
} |
Oops, something went wrong.