42 lines
1.6 KiB
C#
42 lines
1.6 KiB
C#
using Application.Models;
|
|
using Application.Validators;
|
|
|
|
namespace Application.UnitTest.Validators;
|
|
|
|
public class RegisterRequestValidatorTests
|
|
{
|
|
private readonly RegisterRequestValidator _sut = new();
|
|
|
|
[Fact]
|
|
public void Validate_ShouldPass_WhenAllFieldsAreValid()
|
|
{
|
|
var request = new RegisterRequest("ValidUser", "test@example.com", "ValidP@ss1");
|
|
|
|
var result = _sut.Validate(request);
|
|
|
|
Assert.True(result.IsValid);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("ValidUser", "", "ValidP@ss1", "Email")]
|
|
[InlineData("ValidUser", "invalid-email", "ValidP@ss1", "Email")]
|
|
[InlineData("ValidUser", "test@example.com", "", "Password")]
|
|
[InlineData("ValidUser", "test@example.com", "short1A@", "Password")]
|
|
[InlineData("ValidUser", "test@example.com", "nouppercase1@", "Password")]
|
|
[InlineData("ValidUser", "test@example.com", "NOLOWERCASE1@", "Password")]
|
|
[InlineData("ValidUser", "test@example.com", "NoDigit@aa", "Password")]
|
|
[InlineData("ValidUser", "test@example.com", "NoSpecialChar1", "Password")]
|
|
[InlineData("", "test@example.com", "ValidP@ss1", "Username")]
|
|
[InlineData("ab", "test@example.com", "ValidP@ss1", "Username")]
|
|
[InlineData("user@name", "test@example.com", "ValidP@ss1", "Username")]
|
|
public void Validate_ShouldFail_WhenFieldIsInvalid(string username, string email, string password, string expectedProperty)
|
|
{
|
|
var request = new RegisterRequest(username, email, password);
|
|
|
|
var result = _sut.Validate(request);
|
|
|
|
Assert.False(result.IsValid);
|
|
Assert.Contains(result.Errors, e => e.PropertyName == expectedProperty);
|
|
}
|
|
}
|