Implements tests for commit dfd979ec1e

This commit is contained in:
BinaryAlley committed 2026-10-28 10:07:57 +02:00
1 parent d8adf3c1b6
commit 968061e89a
111 files changed
+19955 -292

No files matched your search

@@ -418,6 +418,54 @@ public class ValidatorUtilitiesTests
result.ShouldNotHaveValidationError(s_nullableEnumValueError);
}
[Fact]
public void Validate_WhenTextualEnumValueIsNull_ShouldNotHaveValidationError()
{
// Arrange
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(textualEnumValue: null);
// Act
List<Error> result = _validator.TestValidate(request);
// Assert
result.ShouldNotHaveValidationError(s_textualEnumValueError);
}
[Theory]
[InlineData(nameof(ValidatorUtilitiesTestEnum.First))] // the exact member name
[InlineData("first")] // the member name in lower case
[InlineData("SECOND")] // the member name in upper case
public void Validate_WhenTextualEnumValueIsAMemberName_ShouldNotHaveValidationError(string textualEnumValue)
{
// Arrange
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(textualEnumValue: textualEnumValue);
// Act
List<Error> result = _validator.TestValidate(request);
// Assert
result.ShouldNotHaveValidationError(s_textualEnumValueError);
}
[Theory]
[InlineData("")] // an empty value
[InlineData(" ")] // a whitespace only value
[InlineData("Unknown")] // a name that is not a member of the enumeration
[InlineData("0")] // a number that is a defined member value, which must still be rejected
[InlineData("1")] // another number that is a defined member value
[InlineData("99")] // a number that is not a member value
public void Validate_WhenTextualEnumValueIsNotAMemberName_ShouldHaveValidationError(string textualEnumValue)
{
// Arrange
ValidatorUtilitiesTestRequest request = _validatorUtilitiesTestRequestFixture.Create(textualEnumValue: textualEnumValue);
// Act
List<Error> result = _validator.TestValidate(request);
// Assert
result.ShouldHaveValidationError(s_textualEnumValueError);
}
[Fact]
public void Validate_WhenMaxLengthValueExceedsMaximumLength_ShouldHaveValidationError()
{
@@ -772,6 +820,7 @@ public class ValidatorUtilitiesTests
RuleFor(request => request.NotEmptyCollectionValue).NotEmpty().WithError(s_notEmptyCollectionValueError);
RuleFor(request => request.EnumValue).IsInEnum().WithError(s_enumValueError);
RuleFor(request => request.NullableEnumValue).IsInEnum().WithError(s_nullableEnumValueError);
RuleFor(request => request.TextualEnumValue).IsInEnum<ValidatorUtilitiesTestRequest, ValidatorUtilitiesTestEnum>().WithError(s_textualEnumValueError);
RuleFor(request => request.MaxLengthValue).MaximumLength(5).WithError(s_maxLengthValueError);
RuleFor(request => request.MinLengthValue).MinimumLength(3).WithError(s_minLengthValueError);
RuleFor(request => request.ExactLengthValue).Length(3).WithError(s_exactLengthValueError);
@@ -798,6 +847,7 @@ public class ValidatorUtilitiesTests
private static readonly Error s_notEmptyCollectionValueError = Error.Validation(description: "NotEmptyCollectionValueError");
private static readonly Error s_enumValueError = Error.Validation(description: "EnumValueError");
private static readonly Error s_nullableEnumValueError = Error.Validation(description: "NullableEnumValueError");
private static readonly Error s_textualEnumValueError = Error.Validation(description: "TextualEnumValueError");
private static readonly Error s_maxLengthValueError = Error.Validation(description: "MaxLengthValueError");
private static readonly Error s_minLengthValueError = Error.Validation(description: "MinLengthValueError");
private static readonly Error s_exactLengthValueError = Error.Validation(description: "ExactLengthValueError");