A class representing a Stump rule that examines the content of the body using text evaluations for an HTTP request.
Inheritance: IStumpRule
        public void InitializeFromSettings_WithValidSettings_MatchesCorrectly()
        {
            var settings = new[]
            {
                new RuleSetting {
                    Name = "text.evaluation", Value = "passed"
                },
                new RuleSetting {
                    Name = string.Empty, Value = string.Empty
                },
                new RuleSetting {
                    Name = null, Value = string.Empty
                },
                new RuleSetting {
                    Name = "text.evaluation", Value = string.Empty
                }
            };

            var rule = new BodyContentRule();

            rule.InitializeFromSettings(settings);

            Assert.IsTrue(rule.IsInitialized);

            var request = CreateTextRequest("passed");

            Assert.IsTrue(rule.IsMatch(request));
        }
        public void GetRuleSettings_WhenCalled_ReturnsList()
        {
            var rule = new BodyContentRule(new string[] { "Hello" });
            var list = new List <RuleSetting>(rule.GetRuleSettings());

            Assert.AreEqual(1, list.Count);
        }
        public void InitializeFromSettings_WithNullSettings_ThrowsException()
        {
            var rule = new BodyContentRule();

            Assert.That(
                () => rule.InitializeFromSettings(null),
                Throws.Exception.TypeOf <ArgumentNullException>().With.Property("ParamName").EqualTo("settings"));
        }
示例#4
0
        public void InitializeFromSettings_WithNullSettings_ThrowsException()
        {
            var rule = new BodyContentRule();

            Assert.That(
                () => rule.InitializeFromSettings(null),
                Throws.Exception.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("settings"));
        }
示例#5
0
        public void InitializeFromSettings_WhenInitialized_ThrowsException()
        {
            var rule = new BodyContentRule(new string[] { "ABCD" });
            var settings = new[] { new RuleSetting { Name = "text.evaluation", Value = "passed" } };

            Assert.That(
                () => rule.InitializeFromSettings(settings),
                Throws.Exception.TypeOf<InvalidOperationException>());
        }
        public void IsMatch_NullContext_ReturnsFalse()
        {
            var rule = new BodyContentRule(
                new string[]
            {
                "passed"
            });

            Assert.IsFalse(rule.IsMatch(null));
        }
        public void InitializeFromSettings_WhenInitialized_ThrowsException()
        {
            var rule     = new BodyContentRule(new string[] { "ABCD" });
            var settings = new[] { new RuleSetting {
                                       Name = "text.evaluation", Value = "passed"
                                   } };

            Assert.That(
                () => rule.InitializeFromSettings(settings),
                Throws.Exception.TypeOf <InvalidOperationException>());
        }
        public void IsMatch_RegexTextWithNonMatchingString_ReturnsFalse()
        {
            var rule = new BodyContentRule(
                new string[]
            {
                "regex:AA.*ssed.*D"
            });

            var request = CreateTextRequest("failed");

            Assert.IsFalse(rule.IsMatch(request));
        }
        public void IsMatch_ContainsTextWithMatchingString_ReturnsTrue()
        {
            var rule = new BodyContentRule(
                new string[]
            {
                "passed", "AAA"
            });

            var request = CreateTextRequest("passed");

            Assert.IsTrue(rule.IsMatch(request));
        }
示例#10
0
        public void IsMatch_ContainsTextInversedWithNonMatchingText_ReturnsFalse()
        {
            var rule = new BodyContentRule(
                new string[]
            {
                "not:passed"
            });

            var request = CreateTextRequest("passed");

            Assert.IsFalse(rule.IsMatch(request));
        }
示例#11
0
        public void IsMatch_BinaryContentWithTextString_ReturnsFalse()
        {
            var request = CreateBinaryRequest();

            var rule = new BodyContentRule(
                new string[]
            {
                "passed"
            });

            Assert.IsFalse(rule.IsMatch(request));
        }
示例#12
0
        public void IsMatch_WithoutBody_ReturnsFalse()
        {
            var request = Substitute.For <IStumpsHttpRequest>();

            request.BodyLength.Returns(0);

            var rule = new BodyContentRule(
                new string[]
            {
                "passed"
            });

            Assert.IsFalse(rule.IsMatch(null));
        }
示例#13
0
        public void InitializeFromSettings_WithValidSettings_MatchesCorrectly()
        {
            var settings = new[]
            {
                new RuleSetting { Name = "text.evaluation", Value = "passed" },
                new RuleSetting { Name = string.Empty, Value = string.Empty },
                new RuleSetting { Name = null, Value = string.Empty },
                new RuleSetting { Name = "text.evaluation", Value = string.Empty }
            };

            var rule = new BodyContentRule();
            rule.InitializeFromSettings(settings);

            Assert.IsTrue(rule.IsInitialized);

            var request = CreateTextRequest("passed");
            Assert.IsTrue(rule.IsMatch(request));
        }
示例#14
0
        public void IsMatch_ContainsTextWithNonMatchingString_ReturnsFalse()
        {
            var ruleCaseMatches = new BodyContentRule(
                new string[]
            {
                "failed", "AAA"
            });

            var ruleCaseDoesNotMatch = new BodyContentRule(
                new string[]
            {
                "PASSED", "AAA"
            });

            var request = CreateTextRequest("passed");

            Assert.IsFalse(ruleCaseMatches.IsMatch(request));

            // correct text, wrong case
            Assert.IsFalse(ruleCaseDoesNotMatch.IsMatch(request));
        }
示例#15
0
        public void Constructor_ListOfStrings_Initialized()
        {
            var rule = new BodyContentRule(new string[] { "Test1", "Test2" });

            Assert.True(rule.IsInitialized);
        }
示例#16
0
 public void Constructor_ListOfStrings_Initialized()
 {
     var rule = new BodyContentRule(new string[] { "Test1", "Test2" });
     Assert.True(rule.IsInitialized);
 }
示例#17
0
 public void GetRuleSettings_WhenCalled_ReturnsList()
 {
     var rule = new BodyContentRule(new string[] { "Hello" });
     var list = new List<RuleSetting>(rule.GetRuleSettings());
     Assert.AreEqual(1, list.Count);
 }
示例#18
0
        public void IsMatch_RegexTextWithNonMatchingString_ReturnsFalse()
        {
            var rule = new BodyContentRule(
                new string[]
                {
                    "regex:AA.*ssed.*D"
                });

            var request = CreateTextRequest("failed");
            Assert.IsFalse(rule.IsMatch(request));
        }
示例#19
0
        public void IsMatch_WithoutBody_ReturnsFalse()
        {
            var request = Substitute.For<IStumpsHttpRequest>();
            request.BodyLength.Returns(0);

            var rule = new BodyContentRule(
                new string[]
                {
                    "passed"
                });

            Assert.IsFalse(rule.IsMatch(null));
        }
示例#20
0
        public void IsMatch_NullContext_ReturnsFalse()
        {
            var rule = new BodyContentRule(
                new string[]
                {
                    "passed"
                });

            Assert.IsFalse(rule.IsMatch(null));
        }
示例#21
0
 public void Constructor_Default_NotInitialized()
 {
     var rule = new BodyContentRule();
     Assert.IsFalse(rule.IsInitialized);
 }
示例#22
0
        public void IsMatch_ContainsTextWithNonMatchingString_ReturnsFalse()
        {
            var ruleCaseMatches = new BodyContentRule(
                new string[]
                {
                    "failed", "AAA"
                });

            var ruleCaseDoesNotMatch = new BodyContentRule(
                new string[]
                {
                    "PASSED", "AAA"
                });

            var request = CreateTextRequest("passed");

            Assert.IsFalse(ruleCaseMatches.IsMatch(request));

            // correct text, wrong case
            Assert.IsFalse(ruleCaseDoesNotMatch.IsMatch(request));
        }
示例#23
0
        public void Constructor_Default_NotInitialized()
        {
            var rule = new BodyContentRule();

            Assert.IsFalse(rule.IsInitialized);
        }
示例#24
0
        public void IsMatch_BinaryContentWithTextString_ReturnsFalse()
        {
            var request = CreateBinaryRequest();

            var rule = new BodyContentRule(
                new string[]
                {
                    "passed"
                });

            Assert.IsFalse(rule.IsMatch(request));
        }
示例#25
0
        public void IsMatch_ContainsTextInversedWithMatchingText_ReturnsTrue()
        {
            var rule = new BodyContentRule(
                new string[]
                {
                    "not:failed"
                });

            var request = CreateTextRequest("passed");
            Assert.IsTrue(rule.IsMatch(request));
        }
示例#26
0
        public void IsMatch_ContainsTextWithMatchingString_ReturnsTrue()
        {
            var rule = new BodyContentRule(
                new string[]
                {
                    "passed", "AAA"
                });

            var request = CreateTextRequest("passed");
            Assert.IsTrue(rule.IsMatch(request));
        }