47 lines
1.5 KiB
C#
47 lines
1.5 KiB
C#
|
using FluentValidation.Results;
|
|||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|||
|
using UserManager.Application.Features.Users.Requests;
|
|||
|
|
|||
|
namespace UserManager.Application.UnitTests.Features.Users
|
|||
|
{
|
|||
|
[TestClass]
|
|||
|
public class CreateUserRequestDtoValidationUnitTests
|
|||
|
{
|
|||
|
[TestMethod]
|
|||
|
public void CreateUserRequestDtoValidator_WhenFirstNameIsEmpty_ShouldReturnValidationError()
|
|||
|
{
|
|||
|
// Arrange
|
|||
|
CreateUserRequestDto request = new()
|
|||
|
{
|
|||
|
FirstName = string.Empty,
|
|||
|
LastName = "Doe"
|
|||
|
};
|
|||
|
|
|||
|
// Act
|
|||
|
ValidationResult validationResult = new CreateUserRequestDtoValidator().Validate(request);
|
|||
|
|
|||
|
// Assert
|
|||
|
Assert.IsFalse(validationResult.IsValid);
|
|||
|
Assert.AreEqual("FirstName is required.", validationResult.Errors[0].ErrorMessage);
|
|||
|
}
|
|||
|
|
|||
|
[TestMethod]
|
|||
|
public void CreateUserRequestDtoValidator_WhenLastNameIsEmpty_ShouldReturnValidationError()
|
|||
|
{
|
|||
|
// Arrange
|
|||
|
CreateUserRequestDto request = new()
|
|||
|
{
|
|||
|
FirstName = "John",
|
|||
|
LastName = string.Empty
|
|||
|
};
|
|||
|
|
|||
|
// Act
|
|||
|
ValidationResult validationResult = new CreateUserRequestDtoValidator().Validate(request);
|
|||
|
|
|||
|
// Assert
|
|||
|
Assert.IsFalse(validationResult.IsValid);
|
|||
|
Assert.AreEqual("LastName is required.", validationResult.Errors[0].ErrorMessage);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|