public async Task DuplicateRecordsShouldFail()
        {
            var testClass = new TestClass
            {
                List = new[] { new InnerClass {
                                   DupeVal = "hello"
                               }, new InnerClass {
                                   DupeVal = "hello"
                               }, new InnerClass() }
            };

            var testClassValidator = new TestClassValidator();

            var validationReport = await testClassValidator.Validate(testClass);

            validationReport.IsValid.ShouldBeFalse();

            var violations = validationReport.Violations.ToArray();

            var error1 = ReflectionHelper.PropertyChainToString(violations[0].Property, '.');

            error1.ShouldEqual("List[0].DupeVal");

            var error2 = ReflectionHelper.PropertyChainToString(violations[1].Property, '.');

            error2.ShouldEqual("List[1].DupeVal");
        }
        public void the_validation_report_should_be_valid()
        {
            var validator = new TestClassValidator();
            var report    = validator.Validate(new TestClass());

            report.IsValid.ShouldBeTrue();
        }
Exemplo n.º 3
0
        public async Task InnerViolationsShouldBeReportedCorrectly()
        {
            var testClass = new TestClass
            {
                List = new[] { new InnerClass(), new InnerClass {
                                   Name = "hello"
                               }, new InnerClass() }
            };

            var testClassValidator = new TestClassValidator();

            var validationReport = await testClassValidator.Validate(testClass);

            validationReport.IsValid.ShouldBeFalse();

            var violations = validationReport.Violations.ToArray();

            var error1 = ReflectionHelper.PropertyChainToString(violations[0].Property, '.');

            error1.ShouldEqual("List[0].Name");

            var error2 = ReflectionHelper.PropertyChainToString(violations[1].Property, '.');

            error2.ShouldEqual("List[2].Name");
        }
Exemplo n.º 4
0
        public void ensure_invalid_email3_fails_validation()
        {
            var validator        = new TestClassValidator();
            var testClass        = new TestClass("muonlab.com");
            var validationReport = validator.Validate(testClass);

            validationReport.Violations.First().Error.Key.ShouldEqual("ValidEmail");
        }
Exemplo n.º 5
0
        public void ensure_true_returns_false()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(true);

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.First().Error.Key.ShouldEqual("BeFalse");
        }
        public void ensure_not_null_returns_true()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(new object());

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
Exemplo n.º 7
0
        public void ensure_nulls_pass_validation()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(null);

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
Exemplo n.º 8
0
        public void ensure_strings_that_are_shorter_than_the_maximum_length_pass_validation()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass("1234");

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
Exemplo n.º 9
0
        public void ensure_valid_email_passes_validation()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass("*****@*****.**");

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
        public void when_a_condition_is_false_the_validation_rule_should_not_be_run()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(2, 2);

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
Exemplo n.º 11
0
        public void ensure_not_null_or_empty_passes_validation()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass("a");

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
Exemplo n.º 12
0
        public void ensure_empty_string_fail_validation()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(string.Empty);

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.First().Error.Key.ShouldEqual("Required");
        }
Exemplo n.º 13
0
        public void should_be_valid()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass();

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
Exemplo n.º 14
0
        public void ensure_mismatch_fail_validation()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass("HeLlo");

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.First().Error.Key.ShouldEqual("error");
        }
Exemplo n.º 15
0
        public void ensure_match_passes_validation()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass("different");

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
        public void test_8_equals_4_returns_false()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(8);

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeFalse();
        }
        public void when_the_first_condition_is_false_and_the_second_is_true_there_should_be_no_errors()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(2, 3);

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.Count().ShouldEqual(0);
        }
        public void whe_all_conditions_are_false_all_errors_should_show()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(0, 2);

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.Count().ShouldEqual(2);
        }
        public void when_the_first_condition_is_true_the_second_shoudlnt_be_run()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(1, 2);

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.Count().ShouldEqual(0);
        }
Exemplo n.º 20
0
        public void ensure_true_returns_true()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(true);

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
        public void an_empty_list_should_be_false()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass();

            var report = validator.Validate(testClass);

            report.IsValid.ShouldBeFalse();
        }
Exemplo n.º 22
0
        public void test_1_less_than_or_equal_to_4_returns_true()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(1);

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
Exemplo n.º 23
0
        public void test_2_greater_than_or_equal_2_returns_true()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(2, 2);

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
        public void test_1_not_equals_4_returns_true()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(1, 4);

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
        public void test_4_greater_than_1_returns_true()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(4, 1);

            var validationReport = validator.Validate(testClass);

            validationReport.IsValid.ShouldBeTrue();
        }
Exemplo n.º 26
0
        public void ensure_nulls_fail_validation()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(null);

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.First().Error.Key.ShouldEqual("ValidEmail");
        }
Exemplo n.º 27
0
        public void test_8_less_than_or_equal_to_4_returns_false()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(8);

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.First().Error.Key.ShouldEqual("LessThanEq");
            validationReport.Violations.First().Error.Replacements["arg0"].Value.ShouldEqual("4");
        }
        public void test_2_not_equals_2_returns_false()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(2, 2);

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.First().Error.Key.ShouldEqual("NotEqualTo");
            validationReport.Violations.First().Error.Replacements["arg0"].Value.ToString().ShouldEqual("x.Value2");
        }
        public void test_1_greater_than_4_returns_false()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(1, 4);

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.First().Error.Key.ShouldEqual("GreaterThan");
            validationReport.Violations.First().Error.Replacements["arg0"].Value.ToString().ShouldEqual("x.Value2");
        }
        public void test_1_equals_4_returns_false()
        {
            var validator = new TestClassValidator();
            var testClass = new TestClass(1);

            var validationReport = validator.Validate(testClass);

            validationReport.Violations.First().Error.Key.ShouldEqual("EqualTo");
            validationReport.Violations.First().Error.Replacements["arg0"].Value.ShouldEqual("4");
        }