public void IsValid_GetValidationResult_ReturnsValidationResultWhenValueDoesNotContainOnlyDigits(object testObject) { // Arrange ValidationContext validationContext = new ValidationContext(new { }, null, null); ValidateAllDigitsAttribute validateAllDigitsAttribute = new ValidateAllDigitsAttribute(nameof(DummyStrings.Dummy), typeof(DummyStrings)); // Act // IsValid is a protected function, the public function GetValidationResult calls it. ValidationResult validationResult = validateAllDigitsAttribute.GetValidationResult(testObject, validationContext); // Assert Assert.Equal(DummyStrings.Dummy, validationResult.ErrorMessage); }
public void IsValid_GetValidationResult_ReturnsNullWhenValueIsNullOrAnEmptyStringOrContainsOnlyDigits(object testObject) { // Arrange ValidationContext validationContext = new ValidationContext(new { }, null, null); ValidateAllDigitsAttribute validateAllDigitsAttribute = new ValidateAllDigitsAttribute(nameof(DummyStrings.Dummy), typeof(DummyStrings)); // Act // IsValid is a protected function, the public function GetValidationResult calls it. ValidationResult validationResult = validateAllDigitsAttribute.GetValidationResult(testObject, validationContext); // Assert Assert.Null(validationResult); }