Exemplo n.º 1
0
        public void ShouldFormatCustomMessageWhenValidationFailAgain()
        {
            var validator = new ValidatesPresenceOf();
            validator.Message = "{0} can't be empty";
            var dummy = new VeryDummyClass();

            validator.Validate(dummy, dummy.GetType().GetProperty("DummyText"));
            validator.Validate(dummy, dummy.GetType().GetProperty("DummyProperty"));

            Assert.AreEqual("DummyProperty can't be empty", validator.Message);
        }
Exemplo n.º 2
0
        public void ShouldFailValidationWithMethodName()
        {
            var validator = new CustomValidator();
            validator.CustomMethodName = "FailMethod";
            var dummy = new VeryDummyClass();
            var property = dummy.GetType().GetProperty("DummyText");

            dummy.DummyText = "fail";
            Assert.IsFalse(validator.Validate(dummy, property));
        }
Exemplo n.º 3
0
        public void ShouldEmptyMessageWhenValidationSucceed()
        {
            var validator = new ValidatesPresenceOf();
            var dummy = new VeryDummyClass();
            var property = dummy.GetType().GetProperty("DummyText");
            validator.Validate(dummy, property);
            dummy.DummyText = "dummy dummy";
            validator.Validate(dummy, property);

            Assert.IsNullOrEmpty(validator.Message);
        }
Exemplo n.º 4
0
        public void ShouldEmptyMessageWhenValidationSucceed()
        {
            var validator = new CustomValidator();
            validator.CustomMethod = FailMethod;
            var dummy = new VeryDummyClass();
            var property = dummy.GetType().GetProperty("DummyText");
            validator.Validate(dummy, property);
            validator.CustomMethod = SuccessMethod;
            validator.Validate(dummy, property);

            Assert.IsNullOrEmpty(validator.Message);
        }
Exemplo n.º 5
0
        public void ShouldDoNothingWhenValidationFail()
        {
            var validator = new CustomValidator();
            validator.CustomMethod = FailMethod;
            var dummy = new VeryDummyClass();
            dummy.DummyText = "fail";
            var property = dummy.GetType().GetProperty("DummyText");

            validator.Validate(dummy, property);

            Assert.IsNullOrEmpty(validator.Message);
        }
Exemplo n.º 6
0
        public void ShouldFailStringValidation()
        {
            var validator = new ValidatesPresenceOf();
            var dummy = new VeryDummyClass();
            var property = dummy.GetType().GetProperty("DummyText");

            dummy.DummyText = null;
            Assert.IsFalse(validator.Validate(dummy, property));

            dummy.DummyText = string.Empty;
            Assert.IsFalse(validator.Validate(dummy, property));
        }
Exemplo n.º 7
0
        public void ShouldFormatCustomMessageWhenValidationFail()
        {
            var validator = new CustomValidator();
            validator.CustomMethod = FailMethod;
            validator.Message = "{0} can't be empty";
            var dummy = new VeryDummyClass();
            var property = dummy.GetType().GetProperty("DummyText");

            validator.Validate(dummy, property);

            Assert.AreEqual("DummyText can't be empty", validator.Message);
        }
Exemplo n.º 8
0
        public void ShouldValidateWithMethodName()
        {
            var validator = new CustomValidator();
            validator.CustomMethodName = "SuccessMethod";
            var dummy = new VeryDummyClass();
            var property = dummy.GetType().GetProperty("DummyText");
            dummy.DummyText = "Dummy dummy";

            Assert.IsTrue(validator.Validate(dummy, property));
        }
Exemplo n.º 9
0
        public void ShouldFormatMessageWhenValidationFailAgain()
        {
            var validator = new CustomValidator();
            validator.Message = "{0} can't be blank";
            validator.CustomMethod = FailMethod;
            var dummy = new VeryDummyClass();

            validator.Validate(dummy, dummy.GetType().GetProperty("DummyText"));
            validator.Validate(dummy, dummy.GetType().GetProperty("DummyProperty"));

            Assert.AreEqual("DummyProperty can't be blank", validator.Message);
        }
Exemplo n.º 10
0
        public void ShouldFormatMessageWhenValidationFail()
        {
            var validator = new ValidatesPresenceOf();
            var dummy = new VeryDummyClass();
            var property = dummy.GetType().GetProperty("DummyText");

            validator.Validate(dummy, property);

            Assert.AreEqual("DummyText can't be blank", validator.Message);
        }
Exemplo n.º 11
0
        public void ShouldValidateString()
        {
            var validator = new ValidatesPresenceOf();
            var dummy = new VeryDummyClass();
            var property = dummy.GetType().GetProperty("DummyText");
            dummy.DummyText = "Dummy dummy";

            Assert.IsTrue(validator.Validate(dummy, property));
        }