mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-10-14 17:54:42 +00:00
Add validator tests for brewery and user commands (#282)
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using Features.Users.Commands.Authentication.Login;
|
||||
using FluentValidation.TestHelper;
|
||||
|
||||
namespace Features.Users.Tests.Commands;
|
||||
|
||||
public class LoginValidatorTests
|
||||
{
|
||||
private readonly LoginValidator _validator = new();
|
||||
|
||||
private static LoginCommand ValidCommand() => new("valid.user-99", "Password1!");
|
||||
|
||||
[Fact]
|
||||
public void Validate_ValidCommand_HasNoValidationErrors()
|
||||
{
|
||||
TestValidationResult<LoginCommand> result = _validator.TestValidate(ValidCommand());
|
||||
|
||||
result.ShouldNotHaveAnyValidationErrors();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_EmptyUsername_HasErrorForUsername()
|
||||
{
|
||||
LoginCommand command = ValidCommand() with { Username = "" };
|
||||
|
||||
TestValidationResult<LoginCommand> result = _validator.TestValidate(command);
|
||||
|
||||
result.ShouldHaveValidationErrorFor(x => x.Username).WithErrorMessage("Username is required");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Validate_EmptyPassword_HasErrorForPassword()
|
||||
{
|
||||
LoginCommand command = ValidCommand() with { Password = "" };
|
||||
|
||||
TestValidationResult<LoginCommand> result = _validator.TestValidate(command);
|
||||
|
||||
result.ShouldHaveValidationErrorFor(x => x.Password).WithErrorMessage("Password is required");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user