#region ========================================================================= USING ===================================================================================== using ErrorOr; using Lumina.Application.Common.Infrastructure.Validation; using System.Collections.Generic; #endregion namespace Lumina.Application.UnitTests.Common.Setup; /// /// Validator extension methods for for unit tests. /// public static class ValidatorTestExtensions { /// /// Executes the validator against the specified request instance and returns the resulting errors. /// /// The type of the request being validated. /// The validator instance to execute. /// The request instance to validate. /// A list of produced by the validator. If the request is valid, the list will be empty. public static List TestValidate(this IValidator validator, TRequest request) { return validator.Validate(request); } /// /// Asserts that the validation results do not contain the specified error. /// /// The list of errors returned by the validator. /// The error that should not be present in the validation results. public static void ShouldNotHaveValidationError(this List errors, Error expectedError) { Assert.DoesNotContain(errors, error => error.Description == expectedError.Description); } /// /// Asserts that the validation results contain the specified error. /// /// The list of errors returned by the validator. /// The error that should be present in the validation results. public static void ShouldHaveValidationError(this List errors, Error expectedError) { Assert.Contains(errors, error => error.Description == expectedError.Description); } /// /// Asserts that the validation results are completely empty, indicating the request is valid. /// /// The list of errors returned by the validator. public static void ShouldNotHaveAnyValidationErrors(this List errors) { Assert.Empty(errors); } }