using FluentAssertions;
using FluentValidation.TestHelper;
using MyNewProjectName.Application.Features.Sample.Commands.CreateSample;

namespace MyNewProjectName.UnitTest.Application;

public class CreateSampleCommandValidatorTests
{
    private readonly CreateSampleCommandValidator _validator;

    public CreateSampleCommandValidatorTests()
    {
        _validator = new CreateSampleCommandValidator();
    }

    [Fact]
    public void Validate_WithValidCommand_ShouldNotHaveErrors()
    {
        // Arrange
        var command = new CreateSampleCommand("Test Name", "Test Description");

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldNotHaveAnyValidationErrors();
    }

    [Fact]
    public void Validate_WithEmptyName_ShouldHaveError()
    {
        // Arrange
        var command = new CreateSampleCommand("", "Test Description");

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldHaveValidationErrorFor(x => x.Name);
    }

    [Fact]
    public void Validate_WithNameExceeding200Characters_ShouldHaveError()
    {
        // Arrange
        var longName = new string('a', 201);
        var command = new CreateSampleCommand(longName, "Test Description");

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldHaveValidationErrorFor(x => x.Name);
    }

    [Fact]
    public void Validate_WithDescriptionExceeding1000Characters_ShouldHaveError()
    {
        // Arrange
        var longDescription = new string('a', 1001);
        var command = new CreateSampleCommand("Test Name", longDescription);

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldHaveValidationErrorFor(x => x.Description);
    }

    [Fact]
    public void Validate_WithNullDescription_ShouldNotHaveError()
    {
        // Arrange
        var command = new CreateSampleCommand("Test Name", null);

        // Act
        var result = _validator.TestValidate(command);

        // Assert
        result.ShouldNotHaveValidationErrorFor(x => x.Description);
    }
}
