52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
|
|
using FluentValidation.TestHelper;
|
||
|
|
using SIGCM2.Application.Roles.Update;
|
||
|
|
|
||
|
|
namespace SIGCM2.Application.Tests.Roles.Update;
|
||
|
|
|
||
|
|
public class UpdateRolCommandValidatorTests
|
||
|
|
{
|
||
|
|
private static UpdateRolCommandValidator BuildValidator() => new();
|
||
|
|
private static UpdateRolCommand Valid() => new("cajero", "Cajero Updated", "Desc updated", true);
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Validate_Valid_NoErrors()
|
||
|
|
{
|
||
|
|
BuildValidator().TestValidate(Valid()).ShouldNotHaveAnyValidationErrors();
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Validate_EmptyCodigo_HasError()
|
||
|
|
{
|
||
|
|
BuildValidator().TestValidate(Valid() with { Codigo = "" })
|
||
|
|
.ShouldHaveValidationErrorFor(c => c.Codigo);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Validate_EmptyNombre_HasError()
|
||
|
|
{
|
||
|
|
BuildValidator().TestValidate(Valid() with { Nombre = "" })
|
||
|
|
.ShouldHaveValidationErrorFor(c => c.Nombre);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Validate_NombreTooLong_HasError()
|
||
|
|
{
|
||
|
|
BuildValidator().TestValidate(Valid() with { Nombre = new string('a', 61) })
|
||
|
|
.ShouldHaveValidationErrorFor(c => c.Nombre);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Validate_NullDescripcion_Allowed()
|
||
|
|
{
|
||
|
|
BuildValidator().TestValidate(Valid() with { Descripcion = null })
|
||
|
|
.ShouldNotHaveValidationErrorFor(c => c.Descripcion);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Validate_DescripcionTooLong_HasError()
|
||
|
|
{
|
||
|
|
BuildValidator().TestValidate(Valid() with { Descripcion = new string('a', 251) })
|
||
|
|
.ShouldHaveValidationErrorFor(c => c.Descripcion);
|
||
|
|
}
|
||
|
|
}
|