protected override void OnModelUpdated(ControllerContext controllerContext,
                                               ModelBindingContext bindingContext)
        {
            IValidatable model = bindingContext.Model as IValidatable;

            if (model != null)
            {
                if (!model.IsValid())
                {
                    foreach (IValidationResult validationResult in model.ValidationResults())
                    {
                        bindingContext.ModelState
                        .AddModelError(validationResult.ClassContext.Name +
                                       (!string.IsNullOrEmpty(validationResult.PropertyName)
                                ? "." + validationResult.PropertyName
                                : ""),
                                       validationResult.Message);
                    }
                }
            }
        }
 public void AssertValidationResult(IValidatable obj, string expectedName, string expectedMessage)
 {
     AssertValidationResult(obj.ValidationResults(), expectedName, expectedMessage);
 }
 public void AssertIsValid(IValidatable obj)
 {
     Assert.That(obj.IsValid(), Is.True);
     Assert.That(obj.ValidationResults(), Has.Count.EqualTo(0));
 }
 public void AssertIsInvalid(IValidatable obj, int expectedErrorCount)
 {
     Assert.That(obj.IsValid(), Is.False);
     Assert.That(obj.ValidationResults(), Has.Count.EqualTo(expectedErrorCount));
 }