add unit tests
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using Application.Models;
|
||||
using Application.Validators;
|
||||
|
||||
namespace Application.UnitTest.Validators;
|
||||
|
||||
public class LoginRequestValidatorTests
|
||||
{
|
||||
private readonly LoginRequestValidator _sut = new();
|
||||
|
||||
[Fact]
|
||||
public void Validate_ShouldPass_WhenAllFieldsAreValid()
|
||||
{
|
||||
var request = new LoginRequest("test@example.com", "password123");
|
||||
|
||||
var result = _sut.Validate(request);
|
||||
|
||||
Assert.True(result.IsValid);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("", "password123", "Email")]
|
||||
[InlineData("not-an-email", "password123", "Email")]
|
||||
[InlineData("test@example.com", "", "Password")]
|
||||
public void Validate_ShouldFail_WhenFieldIsInvalid(string email, string password, string expectedProperty)
|
||||
{
|
||||
var request = new LoginRequest(email, password);
|
||||
|
||||
var result = _sut.Validate(request);
|
||||
|
||||
Assert.False(result.IsValid);
|
||||
Assert.Contains(result.Errors, e => e.PropertyName == expectedProperty);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user