-
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.
Added AbstractValidatorExtensions tests
- Loading branch information
Showing
2 changed files
with
68 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
62 changes: 62 additions & 0 deletions
62
test/YuckQi.Domain.Validation.UnitTests/Extensions/AbstractValidatorExtensionsTests.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,62 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentValidation; | ||
using NUnit.Framework; | ||
using YuckQi.Domain.Validation.Extensions; | ||
|
||
namespace YuckQi.Domain.Validation.UnitTests.Extensions; | ||
|
||
public class AbstractValidatorExtensionsTests | ||
{ | ||
public class StringValidator : AbstractValidator<String> | ||
{ | ||
public StringValidator() | ||
{ | ||
RuleFor(t => t.Length).GreaterThan(1).WithMessage("it is too short"); | ||
} | ||
} | ||
|
||
[SetUp] | ||
public void Setup() { } | ||
|
||
[Test] | ||
public void AbstractValidator_GetResultWithValidItem_IsValid() | ||
{ | ||
var validator = new StringValidator(); | ||
var result = validator.GetResult("hello"); | ||
|
||
Assert.That(result.IsValid, Is.True); | ||
} | ||
|
||
[Test] | ||
public async Task AbstractValidator_GetResultAsyncWithValidItem_IsValid() | ||
{ | ||
var validator = new StringValidator(); | ||
var result = await validator.GetResult("hello", CancellationToken.None); | ||
|
||
Assert.That(result.IsValid, Is.True); | ||
} | ||
|
||
[Test] | ||
public void AbstractValidator_GetResultWithInvalidItem_HasDetail() | ||
{ | ||
var validator = new StringValidator(); | ||
var result = validator.GetResult(String.Empty); | ||
|
||
Assert.That(result.IsValid, Is.False); | ||
Assert.That(result.Detail, Is.Not.Empty); | ||
} | ||
|
||
[Test] | ||
public void AbstractValidator_GetResultWithNullReference_ThrowsException() | ||
{ | ||
Assert.That(() => AbstractValidatorExtensions.GetResult(null!, String.Empty), Throws.ArgumentNullException); | ||
} | ||
|
||
[Test] | ||
public void AbstractValidator_GetResultAsyncWithNullReference_ThrowsException() | ||
{ | ||
Assert.That(() => AbstractValidatorExtensions.GetResult(null!, String.Empty, CancellationToken.None), Throws.ArgumentNullException); | ||
} | ||
} |