Created
October 6, 2015 14:42
-
-
Save christopherbauer/085057f6423687c6efb8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RequiredIfAttributeTests | |
| { | |
| [TestFixture] | |
| public class when_validating_required_if_attribute | |
| { | |
| private class TestModel | |
| { | |
| [RequiredIf("Property2", true)] | |
| public int? Property1 { get; set; } | |
| public bool Property2 { get; set; } | |
| } | |
| [Test] | |
| public void then_should_fail_model_validation_given_validation_property_null_and_target_property_value_equal_to_expected_value() | |
| { | |
| // Arrange | |
| var model = new TestModel { Property2 = true, Property1 = null }; | |
| // Act | |
| var result = Validator.TryValidateObject(model, new ValidationContext(model, null, null), null, true); | |
| // Assert | |
| Assert.That(result, Is.False); | |
| } | |
| [Test] | |
| public void then_should_succeed_model_validation_given_validation_property_null_and_target_property_value_not_equal_to_expected_value() | |
| { | |
| // Arrange | |
| var model = new TestModel { Property2 = false, Property1 = null }; | |
| // Act | |
| var result = Validator.TryValidateObject(model, new ValidationContext(model, null, null), null, true); | |
| // Assert | |
| Assert.That(result, Is.True); | |
| } | |
| [Test] | |
| public void then_should_fail_model_validation_given_validation_property_has_value_and_target_property_value_not_equal_to_expected_value() | |
| { | |
| // Arrange | |
| var model = new TestModel { Property2 = true, Property1 = 1 }; | |
| // Act | |
| var result = Validator.TryValidateObject(model, new ValidationContext(model, null, null), null, true); | |
| // Assert | |
| Assert.That(result, Is.True); | |
| } | |
| [Test] | |
| public void then_should_succeed_model_validation_given_validation_property_has_value_and_target_property_value_equal_to_expected_value() | |
| { | |
| // Arrange | |
| var model = new TestModel { Property2 = true, Property1 = 1 }; | |
| // Act | |
| var result = Validator.TryValidateObject(model, new ValidationContext(model, null, null), null, true); | |
| // Assert | |
| Assert.That(result, Is.True); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment