Exemplo n.º 1
0
        public async Task Input_Required_Should_Required()
        {
            var input = new TestInput
            {
                Integer1 = 101,
                Integer2 = 99,
                Length   = "123456"
            }
            ;
            var exception = await Assert.ThrowsAsync <AbpValidationException>(async() =>
            {
                await _ruleProvider.ExecuteAsync(input);
            });

            exception.Message.ShouldBe("一个或多个规则未通过");
            exception.ValidationErrors.Count.ShouldBe(1);
            exception.ValidationErrors[0].ErrorMessage.ShouldBe("字段 Required 必须输入!");
        }
        public async Task Multiple_Rule_Input_Should_Failed()
        {
            var input = new TestMultipleRuleInput
            {
                Length   = "12345",
                Integer1 = 100,
                Integer2 = 100
            };

            var exception = await Assert.ThrowsAsync <AbpValidationException>(async() =>
            {
                await _ruleProvider.ExecuteAsync(input);
            });

            exception.Message.ShouldBe("一个或多个规则未通过");
            exception.ValidationErrors.Count.ShouldBe(2);
            exception.ValidationErrors[0].ErrorMessage.ShouldBe("输入字段验证无效!");
            exception.ValidationErrors[1].ErrorMessage.ShouldBe("长度与求和验证无效!");
        }