clean-architecture-demo-use.../tests/UserManager.Application.Tests/Features/Users/CreateUserRequestDtoValidationUnitTests.cs
2024-10-22 20:52:10 +11:00

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);
}
}
}