예제 #1
0
        public void CanAdd_should_not_throw_exception_if_success()
        {
            var command = new AddPattern {
                PatternId = patternId, Name = "any", Pattern = ".*"
            };

            GuardAppPattern.CanAdd(patterns_0, command);
        }
예제 #2
0
        public void CanAdd_should_throw_exception_if_pattern_not_valid()
        {
            var command = new AddPattern {
                PatternId = patternId, Name = "any", Pattern = "[0-9{1}"
            };

            ValidationAssert.Throws(() => GuardAppPattern.CanAdd(patterns_0, command),
                                    new ValidationError("Pattern is not a valid regular expression.", "Pattern"));
        }
예제 #3
0
        public void CanAdd_should_throw_exception_if_pattern_empty()
        {
            var command = new AddPattern {
                PatternId = patternId, Name = "any", Pattern = string.Empty
            };

            ValidationAssert.Throws(() => GuardAppPattern.CanAdd(patterns_0, command),
                                    new ValidationError("Pattern is required.", "Pattern"));
        }
예제 #4
0
        public void CanAdd_should_throw_exception_if_pattern_exists()
        {
            var patterns_1 = patterns_0.Add(Guid.NewGuid(), "any", "[a-z]", "Message");

            var command = new AddPattern {
                PatternId = patternId, Name = "other", Pattern = "[a-z]"
            };

            ValidationAssert.Throws(() => GuardAppPattern.CanAdd(patterns_1, command),
                                    new ValidationError("This pattern already exists but with another name."));
        }
예제 #5
0
        public void CanAdd_should_throw_exception_if_name_exists()
        {
            var patterns_1 = patterns_0.Add(Guid.NewGuid(), "any", "[a-z]", "Message");

            var command = new AddPattern {
                PatternId = patternId, Name = "any", Pattern = ".*"
            };

            ValidationAssert.Throws(() => GuardAppPattern.CanAdd(patterns_1, command),
                                    new ValidationError("A pattern with the same name already exists."));
        }