public void Validate_DependentNullableBoolMatches_NullValue_Throws()
 {
     var instance = new TestClass { DependentPropertyNullableBool = true };
     var attr = new WRequiredIfAttribute("DependentPropertyNullableBool", true);
     var validationContext = new ValidationContext(instance, null, null);
     Assert.Throws<ValidationException>(() => attr.Validate(null, validationContext));
 }
 public void Validate_DependentStringMatches_NullValue_Throws()
 {
     var instance = new TestClass { DependentPropertyString = "ConditionalValue" };
     var attr = new WRequiredIfAttribute("DependentPropertyString", "ConditionalValue");
     var validationContext = new ValidationContext(instance, null, null);
     Assert.Throws<ValidationException>(() => attr.Validate(null, validationContext));
 }
 public void Validate_DependentInt32Matches_NullValue_Throws()
 {
     var instance = new TestClass { DependentPropertyInt32 = 123 };
     var attr = new WRequiredIfAttribute("DependentPropertyInt32", 123);
     var validationContext = new ValidationContext(instance, null, null);
     Assert.Throws<ValidationException>(() => attr.Validate(null, validationContext));
 }
        public void FormatErrorMessage_CustomMessage_MatchesSpecifiedMessage()
        {
            var message = "{0} custom message";
            var attr = new WRequiredIfAttribute("Dummy", "Dummy") { ErrorMessage = message };

            var custommsg = attr.FormatErrorMessage("NAME");

            Assert.AreEqual(String.Format(message, "NAME"), custommsg);
        }
 public void Validate_DependentNullableBoolNullMatches_NonNullValue_DoesNotThrow()
 {
     var instance = new TestClass { DependentPropertyNullableBool = null };
     var attr = new WRequiredIfAttribute("DependentPropertyNullableBool", null);
     var validationContext = new ValidationContext(instance, null, null);
     attr.Validate("Non null text", validationContext);
 }
 public void Validate_DependentInt32Matches_NonNullValue_DoesNotThrow()
 {
     var instance = new TestClass { DependentPropertyInt32 = 123 };
     var attr = new WRequiredIfAttribute("DependentPropertyInt32", 123);
     var validationContext = new ValidationContext(instance, null, null);
     attr.Validate("Non null text", validationContext);
 }
 public void Validate_DependentStringMatches_NonNullValue_DoesNotThrow()
 {
     var instance = new TestClass { DependentPropertyString = "ConditionalValue" };
     var attr = new WRequiredIfAttribute("DependentPropertyString", "ConditionalValue");
     var validationContext = new ValidationContext(instance, null, null);
     attr.Validate("Non null text", validationContext);
 }
 public void Validate_DependentNullableInt32NullMatches_EmptyStringValue_Throws()
 {
     var instance = new TestClass { DependentPropertyNullableInt32 = null };
     var attr = new WRequiredIfAttribute("DependentPropertyNullableInt32", null);
     var validationContext = new ValidationContext(instance, null, null);
     Assert.Throws<ValidationException>(() => attr.Validate(String.Empty, validationContext));
 }