forked from zarusz/SlimMessageBus
-
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.
[Host.FluentValidation] Duplicated error messages zarusz#192
Signed-off-by: Tomasz Maruszak <[email protected]>
- Loading branch information
Showing
39 changed files
with
204 additions
and
121 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
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
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
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
56 changes: 56 additions & 0 deletions
56
src/Tests/SlimMessageBus.Host.FluentValidation.Test/AbstractValidationInterceptorTests.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,56 @@ | ||
namespace SlimMessageBus.Host.FluentValidation.Test; | ||
|
||
using global::FluentValidation; | ||
using global::FluentValidation.Results; | ||
|
||
public class AbstractValidationInterceptorTests | ||
{ | ||
private readonly Message _message; | ||
private readonly Mock<IValidator<Message>> _validatorMock; | ||
private readonly CancellationToken _cancellationToken; | ||
private readonly AbstractValidationInterceptor<Message> _subject; | ||
|
||
public AbstractValidationInterceptorTests() | ||
{ | ||
_message = new Message(); | ||
_validatorMock = new Mock<IValidator<Message>>(); | ||
_cancellationToken = new CancellationToken(); | ||
_subject = new Mock<AbstractValidationInterceptor<Message>>(new[] { _validatorMock.Object }, null) { CallBase = true }.Object; | ||
} | ||
|
||
public record Message; | ||
|
||
[Fact] | ||
public async Task When_OnValidate_Given_ValidationFails_Then_RaisesException() | ||
{ | ||
// arrange | ||
_validatorMock | ||
.Setup(x => x.ValidateAsync(It.IsAny<ValidationContext<Message>>(), _cancellationToken)) | ||
.ReturnsAsync(new ValidationResult { Errors = new List<ValidationFailure> { new() { ErrorMessage = "Something is Wrong" } } }); | ||
|
||
// act | ||
Func<Task> act = () => _subject.OnValidate(_message, _cancellationToken); | ||
|
||
// asset | ||
await act.Should().ThrowAsync<ValidationException>(); | ||
|
||
_validatorMock | ||
.Verify(x => x.ValidateAsync(It.IsAny<ValidationContext<Message>>(), _cancellationToken), Times.Once); | ||
} | ||
|
||
[Fact] | ||
public async Task When_OnValidate_Given_ValidationSucceeds_Then_CallsNext() | ||
{ | ||
// arrange | ||
_validatorMock | ||
.Setup(x => x.ValidateAsync(It.IsAny<ValidationContext<Message>>(), _cancellationToken)) | ||
.ReturnsAsync(new ValidationResult()); | ||
|
||
// act | ||
await _subject.OnValidate(_message, _cancellationToken); | ||
|
||
// asset | ||
_validatorMock | ||
.Verify(x => x.ValidateAsync(It.IsAny<ValidationContext<Message>>(), _cancellationToken), Times.Once); | ||
} | ||
} |
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
Oops, something went wrong.