public void GivenInvalidObject_WhenValidateObjectRecursively_ThenCorrectValidationResults() { RecursiveValidator validator = new RecursiveValidator(null); List <ValidationResult> results = validator.ValidateObjectRecursively(TestStructure.Invalid()); Assert.Single(results); ValidationResultUtility.AssertValidationResultEquals(results[0], "The SomeString field has to be lower cased.", "SomeString"); }
public void GivenInvalidParent_WhenValidateRecursively_ThenCorrectValidationResults() { RecursiveValidator validator = new RecursiveValidator(null); List <ValidationResult> results = validator.ValidateObjectRecursively(CyclicObjectGraph.WithInvalidParent()); Assert.Single(results); ValidationResultUtility.AssertValidationResultEquals(results[0], "The RequiredString field is required.", "RequiredString"); }
public void GivenInvalidChild_WhenValidateRecursively_ThenCorrectValidationResults(object dictionary, string key) { RecursiveValidator validator = new RecursiveValidator(null); List <ValidationResult> results = validator.ValidateObjectRecursively(dictionary); Assert.Single(results); ValidationResultUtility.AssertValidationResultEquals(results[0], "The RequiredString field is required.", $"Child.{key}.RequiredString"); }
public void GivenInvalidGenericType_WithMissingChildValue_ThenCorrectValidationResults() { RecursiveValidator validator = new RecursiveValidator(null); List <ValidationResult> results = validator.ValidateObjectRecursively(GenericType.WithMissingChildValue()); Assert.Single(results); ValidationResultUtility.AssertValidationResultEquals(results[0], "The Value field is required.", "Child.Value"); }
public void GivenInvalidFuncs_WhenValidateRecursively_ThenCorrectValidationResults() { RecursiveValidator validator = new RecursiveValidator(null); List <ValidationResult> results = validator.ValidateObjectRecursively(Funcs.Invalid()); Assert.Single(results); ValidationResultUtility.AssertValidationResultEquals(results[0], "The SomeFunc field is required.", "SomeFunc"); }
public void GivenInvalidChild_WhenValidateRecursively_ThenCorrectValidationResults() { RecursiveValidator validator = new RecursiveValidator(null); List <ValidationResult> results = validator.ValidateObjectRecursively(NestedList.WithInvalidChild()); Assert.Equal(3, results.Count); ValidationResultUtility.AssertValidationResultEquals(results[0], "The RequiredString field is required.", "Child[0].RequiredString"); ValidationResultUtility.AssertValidationResultEquals(results[1], "The RequiredLong field is required.", "Child[0].RequiredLong"); ValidationResultUtility.AssertValidationResultEquals(results[2], "The RequiredUnsignedLong field is required.", "Child[0].RequiredUnsignedLong"); }
public void WhenValidateRecursively_ThenNamingPolicyIsReflectedInPath() { IServiceProvider services = new ServiceCollection().AddRecursiveValidator(options => { options.ValidationNamingPolicy = new NaiveCamelCasingPolicy(); }).BuildServiceProvider(); IRecursiveValidator validator = services.GetRequiredService <IRecursiveValidator>(); List <ValidationResult> results = validator.ValidateObjectRecursively(NestedObject.WithInvalidChild()); Assert.Equal(3, results.Count); ValidationResultUtility.AssertValidationResultEquals(results[0], "The RequiredString field is required.", "child.requiredString"); ValidationResultUtility.AssertValidationResultEquals(results[1], "The RequiredLong field is required.", "child.requiredLong"); ValidationResultUtility.AssertValidationResultEquals(results[2], "The RequiredUnsignedLong field is required.", "child.requiredUnsignedLong"); }
public void GivenInvalidNullablePrimitives_WhenValidateRecursively_ThenCorrectValidationResults() { RecursiveValidator validator = new RecursiveValidator(null); List <ValidationResult> results = validator.ValidateObjectRecursively(new NullablePrimitives()); Assert.Equal(17, results.Count); ValidationResultUtility.AssertValidationResultEquals(results[0], "The RequiredString field is required.", "RequiredString"); ValidationResultUtility.AssertValidationResultEquals(results[1], "The RequiredLong field is required.", "RequiredLong"); ValidationResultUtility.AssertValidationResultEquals(results[2], "The RequiredUnsignedLong field is required.", "RequiredUnsignedLong"); ValidationResultUtility.AssertValidationResultEquals(results[3], "The RequiredInt field is required.", "RequiredInt"); ValidationResultUtility.AssertValidationResultEquals(results[4], "The RequiredUnsignedInt field is required.", "RequiredUnsignedInt"); ValidationResultUtility.AssertValidationResultEquals(results[5], "The RequiredShort field is required.", "RequiredShort"); ValidationResultUtility.AssertValidationResultEquals(results[6], "The RequiredUnsignedShort field is required.", "RequiredUnsignedShort"); ValidationResultUtility.AssertValidationResultEquals(results[7], "The RequiredByte field is required.", "RequiredByte"); ValidationResultUtility.AssertValidationResultEquals(results[8], "The RequiredChar field is required.", "RequiredChar"); ValidationResultUtility.AssertValidationResultEquals(results[9], "The RequiredBool field is required.", "RequiredBool"); ValidationResultUtility.AssertValidationResultEquals(results[10], "The RequiredFloat field is required.", "RequiredFloat"); ValidationResultUtility.AssertValidationResultEquals(results[11], "The RequiredDouble field is required.", "RequiredDouble"); ValidationResultUtility.AssertValidationResultEquals(results[12], "The RequiredDecimal field is required.", "RequiredDecimal"); ValidationResultUtility.AssertValidationResultEquals(results[13], "The RequiredDateTime field is required.", "RequiredDateTime"); ValidationResultUtility.AssertValidationResultEquals(results[14], "The RequiredDateTimeOffset field is required.", "RequiredDateTimeOffset"); ValidationResultUtility.AssertValidationResultEquals(results[15], "The RequiredTimeSpan field is required.", "RequiredTimeSpan"); ValidationResultUtility.AssertValidationResultEquals(results[16], "The RequiredGuid field is required.", "RequiredGuid"); }