-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Add new derived types for clarity.
1 parent
67f4fa7
commit cffca7f
Showing
10 changed files
with
117 additions
and
71 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,3 +1,4 @@ | ||
.vs | ||
bin | ||
obj | ||
*.user |
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,17 @@ | ||
using Musts; | ||
|
||
namespace Utility; | ||
|
||
public class ObjectResultTests | ||
{ | ||
[Test] | ||
public void Ok_Result_WithValue_Returns_Success() | ||
{ | ||
ObjectResult<int> result = OkObjectResult<int>.Ok(99); | ||
|
||
result.Value.MustBeEqual(99); | ||
result.MustBeSuccess(); | ||
result.Error.MustBeNullOrEmpty(); | ||
result.ErrorCode.MustBeZero(); | ||
} | ||
} |
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,6 @@ | ||
<LUTConfig Version="1.0"> | ||
<Repository /> | ||
<ParallelBuilds>true</ParallelBuilds> | ||
<ParallelTestRuns>true</ParallelTestRuns> | ||
<TestCaseTimeout>180000</TestCaseTimeout> | ||
</LUTConfig> |
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,14 @@ | ||
namespace Utility; | ||
|
||
public record ErrorObjectResult<T> : ObjectResult<T> | ||
{ | ||
protected internal ErrorObjectResult(T value, string error, int errorCode) : base(value, false, error, errorCode) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public static ErrorObjectResult<T> Fail(string message, int errorCode = 0) | ||
{ | ||
return new ErrorObjectResult<T>(default(T), message, errorCode); | ||
Check warning on line 12 in Utility.Result/ErrorObjectResult.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 @@ | ||
namespace Utility; | ||
|
||
/// <summary> | ||
/// Represents an error result with an associated error message and error code. | ||
/// </summary> | ||
public record ErrorResult : Result | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ErrorResult"/> class. | ||
/// </summary> | ||
/// <param name="error">The error message associated with the result.</param> | ||
/// <param name="errorCode">The error code associated with the result (optional).</param> | ||
internal ErrorResult(string error, int errorCode = -1) : base(false, error, errorCode) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Creates a failure result with the specified error message and error code. | ||
/// </summary> | ||
/// <param name="message">The error message.</param> | ||
/// <param name="errorCode">The error code (optional).</param> | ||
/// <returns>An error result.</returns> | ||
public static ErrorResult Fail(string message, int errorCode = -1) | ||
{ | ||
return new ErrorResult(message, errorCode); | ||
} | ||
} |
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 Utility; | ||
|
||
public record ObjectResult<T> : Result | ||
{ | ||
public T Value { get; set; } | ||
|
||
protected internal ObjectResult(T value, bool success, string error, int errorCode) : base(success, error, errorCode) | ||
{ | ||
Value = value; | ||
} | ||
} |
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,14 @@ | ||
namespace Utility; | ||
|
||
public record OkObjectResult<T> : ObjectResult<T> | ||
{ | ||
protected internal OkObjectResult(T value) : base(value, true, string.Empty, 0) | ||
{ | ||
Value = value; | ||
} | ||
|
||
public static OkObjectResult<T> Ok(T value) | ||
{ | ||
return new OkObjectResult<T>(value); | ||
} | ||
} |
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,14 @@ | ||
namespace Utility; | ||
|
||
/// <summary> | ||
/// Represents a successful result with no associated value. | ||
/// </summary> | ||
public record OkResult : Result | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OkResult"/> class. | ||
/// </summary> | ||
internal OkResult() : base(true) | ||
{ | ||
} | ||
} |
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