public void ValidatesAtObjectLevel()
 {
     var validator = new DataAnnotationsValidator(typeof(Foo2));
     var result = validator.Validate(new Foo2 { Id = 1, Name = "bar" });
     result.IsValid.ShouldBeFalse();
     result.Single().ErrorMessage.ShouldEqual("Id: 1 Name: bar");
 }
        public void ValidationSucceedsForValidValue()
        {
            var validator = new DataAnnotationsValidator(typeof(Foo1));
            var foo = new Foo1() { Name = "Jeremy" };
            var result = validator.Validate(foo);

            result.IsValid.ShouldBeTrue();
        }
        public void ValidationFailsForInvalidValue()
        {
            var validator = new DataAnnotationsValidator(typeof(Foo1));
            var foo = new Foo1();
            var result = validator.Validate(foo);

            result.IsValid.ShouldBeFalse();
        }
        public void FormatsErrorMessage()
        {
            var originalCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-gb");

            try {
                var validator = new DataAnnotationsValidator(typeof(Foo1));
                var result = validator.Validate(new Foo1());
                result.Single().ErrorMessage.ShouldEqual("The Name field is required.");
            }
            finally {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }