Inheritance: ValueObjectBase
コード例 #1
0
        public void CustomerValidatorTest() {
            var customer = new Customer()
                           {
                               Name = "배성혁",
                               Company = "리얼웹",
                               Discount = 12.5m,
                               ZipCode = "135-010"
                           };

            var result = ValidatorTool.Validate(customer);

            result.IsValid.Should().Be.True();
            result.Errors.Count.Should().Be(0);

            customer = new Customer()
                       {
                           Name = "",
                           Company = "",
                           Discount = 12.5m,
                           ZipCode = ""
                       };

            result = ValidatorTool.Validate(customer);

            result.IsValid.Should().Be.False();
            result.Errors.Count.Should().Be.GreaterThan(0);

            foreach(var failure in result.Errors) {
                Console.WriteLine(failure);
            }
        }
コード例 #2
0
        public void GetValidatorOfTest() {
            var customer = new Customer();
            var validator = ValidatorTool.GetValidatorOf(customer);
            validator.Should().Not.Be.Null();

            var user = new User();
            validator = ValidatorTool.GetValidatorOf(user);
            validator.Should().Not.Be.Null();
        }
コード例 #3
0
        public void InValidCustomerTest() {
            var customer = new Customer()
                           {
                               Name = "",
                               Company = "",
                               HasDiscount = true,
                           };

            var customerValidator = new CustomerValidator();

            var result = customerValidator.Validate(customer);
            result.IsValid.Should().Be.False();
            result.Errors.Count.Should().Be.GreaterThan(0);
        }
コード例 #4
0
        public void ValidCustomerTest() {
            var customer = new Customer()
                           {
                               Name = "배성혁",
                               Company = "리얼웹",
                               Discount = 12.5m,
                               ZipCode = "135-010"
                           };

            var customerValidator = new CustomerValidator();

            var result = customerValidator.Validate(customer);
            result.IsValid.Should().Be.True();
            result.Errors.Count.Should().Be(0);
        }
コード例 #5
0
        public void InValidCustomerTest() {
            var customer = new Customer()
                           {
                               Name = "",
                               Company = "",
                               HasDiscount = true,
                           };

            var factory = new ValidatorFactory();
            var customerValidator = factory.GetValidator(typeof(Customer));

            var result = customerValidator.Validate(customer);
            result.IsValid.Should().Be.False();
            result.Errors.Count.Should().Be.GreaterThan(0);

            result.Errors.RunEach(err => Console.WriteLine(err.ErrorMessage));
        }