Ejemplo n.º 1
0
        public async void Test_BetweenIntChecker()
        {
            var checker = new BetweenIntChecker <Student>(3, 10, _Validation);
            var ex      = Assert.Throws <ArgumentOutOfRangeException>(() => new BetweenIntChecker <Student>(33, 10, _Validation));

            Assert.Equal("max", ex.ParamName);
            Assert.True(ex.Message.Contains("Max should be larger than min."));

            var result = await checker.ValidateAsync(new ValidateResult(), 4, "", "");

            Assert.True(result.IsValid);

            result = await checker.ValidateAsync(new ValidateResult(), 3, "a", "c");

            Assert.False(result.IsValid);
            Assert.Equal(1, result.Failures.Count);
            Assert.Equal("a", result.Failures[0].Name);
            Assert.Equal("c", result.Failures[0].Error);
            Assert.Equal(3, result.Failures[0].Value);

            result = await checker.ValidateAsync(new ValidateResult(), 1, "a1", "c1");

            Assert.False(result.IsValid);
            Assert.Equal(1, result.Failures.Count);
            Assert.Equal("a1", result.Failures[0].Name);
            Assert.Equal("c1", result.Failures[0].Error);
            Assert.Equal(1, result.Failures[0].Value);

            result = await checker.ValidateAsync(new ValidateResult(), 10, "b", null);

            Assert.False(result.IsValid);
            Assert.Equal(1, result.Failures.Count);
            Assert.Equal("b", result.Failures[0].Name);
            Assert.Equal("The value is not between 3 and 10", result.Failures[0].Error);
            Assert.Equal(10, result.Failures[0].Value);

            result = await checker.ValidateAsync(new ValidateResult(), 100, "b1", null);

            Assert.False(result.IsValid);
            Assert.Equal(1, result.Failures.Count);
            Assert.Equal("b1", result.Failures[0].Name);
            Assert.Equal("The value is not between 3 and 10", result.Failures[0].Error);
            Assert.Equal(100, result.Failures[0].Value);
        }
Ejemplo n.º 2
0
        public async void Test_BetweenIntChecker()
        {
            var checker = new BetweenIntChecker<Student>(3, 10, _Validation);
            var ex = Assert.Throws<ArgumentOutOfRangeException>(() => new BetweenIntChecker<Student>(33, 10, _Validation));
            Assert.Equal("max", ex.ParamName);
            Assert.True(ex.Message.Contains("Max should be larger than min."));

            var result = await checker.ValidateAsync(new ValidateResult(), 4, "", "");
            Assert.True(result.IsValid);

            result = await checker.ValidateAsync(new ValidateResult(), 3, "a", "c");
            Assert.False(result.IsValid);
            Assert.Equal(1, result.Failures.Count);
            Assert.Equal("a", result.Failures[0].Name);
            Assert.Equal("c", result.Failures[0].Error);
            Assert.Equal(3, result.Failures[0].Value);

            result = await checker.ValidateAsync(new ValidateResult(), 1, "a1", "c1");
            Assert.False(result.IsValid);
            Assert.Equal(1, result.Failures.Count);
            Assert.Equal("a1", result.Failures[0].Name);
            Assert.Equal("c1", result.Failures[0].Error);
            Assert.Equal(1, result.Failures[0].Value);

            result = await checker.ValidateAsync(new ValidateResult(), 10, "b", null);
            Assert.False(result.IsValid);
            Assert.Equal(1, result.Failures.Count);
            Assert.Equal("b", result.Failures[0].Name);
            Assert.Equal("The value is not between 3 and 10", result.Failures[0].Error);
            Assert.Equal(10, result.Failures[0].Value);

            result = await checker.ValidateAsync(new ValidateResult(), 100, "b1", null);
            Assert.False(result.IsValid);
            Assert.Equal(1, result.Failures.Count);
            Assert.Equal("b1", result.Failures[0].Name);
            Assert.Equal("The value is not between 3 and 10", result.Failures[0].Error);
            Assert.Equal(100, result.Failures[0].Value);
        }