public void Validation_associates_with_repository_and_throws_exception_for_invalid_model_when_saved()
        {
            IRepository<MockInvalidTestObject> repository =
                new ActiveRecordRepository<MockInvalidTestObject>(new ActiveRecordModelValidator());

            var value = new MockInvalidTestObject {Name = null, Email = "invalidEmail"};
            repository.Save(value);
        }
        public void Invalid_property_count_matches_for_invalid_model()
        {
            var value = new MockInvalidTestObject {Name = null, Email = "invalid"};

            var validator = new ActiveRecordModelValidator();
            var errors = validator.GetValidationErrors(value);

            Assert.AreEqual(2, errors.Count);
        }
        public void Can_get_validation_errors_object_for_model()
        {
            var value = new MockInvalidTestObject {Name = "Test", Email = "*****@*****.**"};

            var validator = new ActiveRecordModelValidator();
            var errors = validator.GetValidationErrors(value);

            Assert.IsNotNull(errors);
        }
        public void Can_get_list_of_errors_for_specific_property()
        {
            var value = new MockInvalidTestObject {Name = null, Email = "invalid"};

            var errors = new ActiveRecordModelValidator().GetValidationErrors(value);

            var propErrors = errors.ErrorsForProperty("Name");

            Assert.IsNotNull(propErrors);
            Assert.AreEqual(1, propErrors.Count);
            Assert.AreEqual(propErrors[0].PropertyName, "Name");
        }
 public void Validation_succeeds_for_valid_properties()
 {
     var value = new MockInvalidTestObject {Name = "Test", Email = "*****@*****.**"};
     new ActiveRecordModelValidator().Validate(value);
 }
 public void Validation_exception_thrown_when_invalid_property_encountered()
 {
     var value = new MockInvalidTestObject {Name = null, Email = string.Empty};
     new ActiveRecordModelValidator().Validate(value);
 }