예제 #1
0
        public void AllNegative()
        {
            var expected = new NotificationAssertion();
            expected.RegisterMessage("Name", Notification.REQUIRED_FIELD, Severity.Error);
            expected.RegisterMessage("Amount", Notification.REQUIRED_FIELD, Severity.Error);
            expected.RegisterMessage("TradeDate", Notification.REQUIRED_FIELD, Severity.Error);

            var target = new RequiredPropertyTarget();

            var actual = Validator.ValidateObject(target);
            expected.AssertEquals(actual);
        }
예제 #2
0
        public void AllPositive2()
        {
            var expected = new NotificationAssertion();

            var target = new RequiredPropertyTarget();
            target.Amount =0;
            target.Name = "Jeremy";

            target.TradeDate = DateTime.Now;

            var actual = Validator.ValidateObject(target);
            expected.AssertEquals(actual);
        }
예제 #3
0
        public void Customize_the_message_builder()
        {
            RequiredAttribute.GetMessage = (att, prop) => prop.Name + " is required";

            var expected = new NotificationAssertion();
            expected.RegisterMessage("Name", "Name is required", Severity.Error);
            expected.RegisterMessage("Amount", "Amount is required", Severity.Error);
            expected.RegisterMessage("TradeDate", "TradeDate is required", Severity.Error);

            var target = new RequiredPropertyTarget();

            var actual = Validator.ValidateObject(target);
            expected.AssertEquals(actual);
        }
예제 #4
0
        public void Empty_string_fails_validation()
        {
            var expected = new NotificationAssertion();
            expected.RegisterMessage("Name", Notification.REQUIRED_FIELD, Severity.Error);

            var target = new RequiredPropertyTarget(){Amount = 3, TradeDate = DateTime.Today, Name = string.Empty};

            var actual = Validator.ValidateObject(target);
            expected.AssertEquals(actual);
        }