Beispiel #1
0
        public void Test_OrderValidator()
        {
            var validator = new OrderValidator();

            var validationResults = validator.Validate(new Order());

            // Id = 0 驗證應該要有錯
            validator.ShouldHaveValidationErrorFor(order => order.Id, 0);

            // Id = 1 驗證不應該有錯
            validator.ShouldNotHaveValidationErrorFor(order => order.Id, 1);
        }
Beispiel #2
0
        public override OrderCreatingResult AddOrder(Order order)
        {
            var result = new OrderCreatingResult();

            var validator = new OrderValidator();

            var validationResult = validator.Validate(order);

            if (validationResult.IsValid)
            {
                result = this.orderService.AddOrder(order);
            }
            else
            {
                result.Message = string.Join("\r\n", validationResult.Errors.Select(e => e.ErrorMessage));
            }

            return(result);
        }