Specialized skill for testing FluentValidation validators. Use when you need to create tests for Validator classes, validate business rules, or test error messages. Covers complete FluentValidation.TestHelper usage, ShouldHaveValidationErrorFor, async validation, cross-field logic, etc.
Keywords: validator, validation, fluentvalidation, validation testing, UserValidator, CreateOrderValidator, TestHelper, ShouldHaveValidationErrorFor, ShouldNotHaveValidationErrorFor, TestValidate, TestValidateAsync, testing validators, validating business rules
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
A direct command skips the review prompt. Inspect the source before running it.
Specialized skill for testing FluentValidation validators. Use when you need to create tests for Validator classes, validate business rules, or test error messages. Covers complete FluentValidation.TestHelper usage, ShouldHaveValidationErrorFor, async validation, cross-field logic, etc.
Keywords: validator, validation, fluentvalidation, validation testing, UserValidator, CreateOrderValidator, TestHelper, ShouldHaveValidationErrorFor, ShouldNotHaveValidationErrorFor, TestValidate, TestValidateAsync, testing validators, validating business rules
{"short-description":".NET skill guidance for dotnet-testing-fluentvalidation-testing"}
copilot
{}
geminicli
{}
antigravity
{}
Source: kevintsengtw/dotnet-testing-agent-skills (MIT). Ported into dotnet-agent-harness.
FluentValidation Validator Testing Guide
Applicable Scenarios
This skill focuses on testing data validation logic using FluentValidation.TestHelper, covering basic validation,
complex business rules, async validation, and testing best practices.
Why Test Validators?
Validators are the first line of defense for applications, testing validators can:
Ensure Data Integrity - Prevent invalid data from entering the system
Document Business Rules - Tests serve as living documentation, clearly showing business rules
Security Protection - Prevent malicious or inappropriate data input
Refactoring Safety Net - Provide protection when business rules change
Cross-Field Logic Validation - Ensure complex logic works correctly
using FluentValidation;
using FluentValidation.TestHelper;
using Microsoft.Extensions.Time.Testing;
using NSubstitute;
using Xunit;
using AwesomeAssertions;
Core Testing Patterns
This section covers 7 core testing patterns, each including validator definitions and complete test examples.
Use Parameterized Tests - Use Theory to test multiple input combinations
Test Boundary Values - Pay special attention to boundary conditions
Control Time - Use FakeTimeProvider for time-dependent scenarios
Mock External Dependencies - Use NSubstitute to isolate external services
Create Helper Methods - Uniformly manage test data
Clear Test Naming - Use Method_Scenario_ExpectedResult format
Test Error Messages - Ensure users see correct error messages
❌ Practices to Avoid
Avoid Using DateTime.Now - Causes unstable tests
Avoid Overly Coupled Tests - Each test should only validate one rule
Avoid Hardcoded Test Data - Use helper methods to create
Avoid Ignoring Boundary Conditions - Boundary values are where errors most easily occur
Avoid Skipping Error Message Validation - Error messages are part of user experience
Common Testing Scenarios
Scenario 1: Email Format Validation
[Theory]
[InlineData("", "Email cannot be null or blank")]
[InlineData("invalid", "Email format is incorrect")]
[InlineData("@example.com", "Email format is incorrect")]
publicvoidValidate_Invalid_Email_Should_Validation_Fail(string email, string expectedError)
{
var request = new UserRegistrationRequest { Email = email };
var result = _validator.TestValidate(request);
result.ShouldHaveValidationErrorFor(x => x.Email).WithErrorMessage(expectedError);
}
Scenario 2: Age Range Validation
[Theory]
[InlineData(17, "Age must be greater than or equal to 18")]
[InlineData(121, "Age must be less than or equal to 120")]
publicvoidValidate_Invalid_Age_Should_Validation_Fail(int age, string expectedError)
{
var request = new UserRegistrationRequest { Age = age };
var result = _validator.TestValidate(request);
result.ShouldHaveValidationErrorFor(x => x.Age).WithErrorMessage(expectedError);
}
Scenario 3: Required Field Validation
[Fact]
publicvoidValidate_Not_Agree_To_Terms_Should_Validation_Fail()
{
var request = new UserRegistrationRequest { AgreeToTerms = false };
var result = _validator.TestValidate(request);
result.ShouldHaveValidationErrorFor(x => x.AgreeToTerms)
.WithErrorMessage("Must agree to terms of use");
}