-
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 branch information
Bruno de Souza Melo
committed
Sep 9, 2024
1 parent
0b3dda4
commit d8e4b40
Showing
5 changed files
with
117 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,5 +30,5 @@ public interface IResult | |
|
||
public interface IResult<out T> : IResult | ||
{ | ||
T Data { get; } | ||
T? Data { 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,96 @@ | ||
using NUnit.Framework; | ||
using NUnit.Framework.Internal; | ||
using NuvTools.Common.ResultWrapper; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace NuvTools.Common.Tests.ResultWrapper; | ||
|
||
[TestFixture()] | ||
public class ResultTests | ||
{ | ||
[Test()] | ||
public async Task GetResultOnly() | ||
public void ValidationFail() | ||
{ | ||
var list = new List<MessageDetail>() { new("aa"), new("bb") }; | ||
|
||
await Result.ValidationFailAsync(messages: list); | ||
Result.ValidationFail(list); | ||
|
||
Result.ValidationFail(new MessageDetail("Validation error")); | ||
|
||
Result.ValidationFail("Validation error"); | ||
|
||
var result = Result.ValidationFail(["Validation error"]); | ||
Assert.That(result.Messages[0].Title, Is.EqualTo("Validation error")); | ||
} | ||
|
||
[Test()] | ||
public async Task GetResultLong() | ||
public void ValidationFailTyped() | ||
{ | ||
var list = new List<MessageDetail>() { new("aa"), new("bb") }; | ||
Result<int>.ValidationFail("Validation error"); | ||
Result<int>.ValidationFail(new MessageDetail("Validation error")); | ||
|
||
Result<int>.ValidationFail("Validation error", 1); | ||
Result<int>.ValidationFail(new MessageDetail("Validation error"), 1); | ||
|
||
var resultTyped = Result<int>.ValidationFail(["Validation error"]); | ||
Assert.That(resultTyped.Messages[0].Title, Is.EqualTo("Validation error")); | ||
|
||
resultTyped = Result<int>.ValidationFail(["Validation error"], 0); | ||
Assert.That(resultTyped.Messages[0].Title, Is.EqualTo("Validation error")); | ||
} | ||
|
||
[Test()] | ||
public void Fail() | ||
{ | ||
Result.Fail(); | ||
|
||
var result = Result.Fail("Not work"); | ||
|
||
Assert.That(result.Messages[0].Title, Is.EqualTo("Not work")); | ||
|
||
Result.Fail(new MessageDetail("Not work")); | ||
|
||
Result.Fail(["not work"]); | ||
|
||
Result.Fail([new MessageDetail("Not work")]); | ||
|
||
Assert.That(result.Messages[0].Title, Is.EqualTo("Not work")); | ||
|
||
} | ||
|
||
[Test()] | ||
public void FailTyped() | ||
{ | ||
var resultTyped = Result<int>.Fail("Not work"); | ||
Assert.That(resultTyped.Messages[0].Title, Is.EqualTo("Not work")); | ||
} | ||
|
||
[Test()] | ||
public void Success() | ||
{ | ||
Result.Success(); | ||
|
||
var result = Result.Success("It works!"); | ||
Assert.That(result.Messages[0].Title, Is.EqualTo("It works!")); | ||
|
||
Result.Success(new MessageDetail("It works!")); | ||
} | ||
|
||
private static IResult<int> TestSuccessTypedReturn() | ||
{ | ||
return Result<int>.Success(); | ||
} | ||
|
||
[Test()] | ||
public void SuccessTyped() | ||
{ | ||
TestSuccessTypedReturn(); | ||
|
||
Result<int>.Success(1); | ||
Result<int>.Success(1, "It works!"); | ||
|
||
await Result<long>.ValidationFailAsync(0L, list); | ||
var resultTyped = Result<int>.Success(1, new MessageDetail("It works!")); | ||
Assert.That(resultTyped.Messages[0].Title, Is.EqualTo("It works!")); | ||
Assert.That(resultTyped.Data, Is.EqualTo(1)); | ||
} | ||
} |