A class representing a Stump rule that evaluates the headers of an HTTP request.
Inheritance: IStumpRule
Esempio n. 1
0
        public void GetRuleSettings_WhenCalled_ReturnsList()
        {
            var rule = new HeaderRule("a", "b");
            var list = new List <RuleSetting>(rule.GetRuleSettings());

            Assert.AreEqual(2, list.Count);
        }
Esempio n. 2
0
        public void InitializeFromSettings_WithNullSettings_ThrowsException()
        {
            var rule = new HeaderRule();

            Assert.That(
                () => rule.InitializeFromSettings(null),
                Throws.Exception.TypeOf <ArgumentNullException>().With.Property("ParamName").EqualTo("settings"));
        }
Esempio n. 3
0
        public void InitializeFromSettings_WithNullSettings_ThrowsException()
        {
            var rule = new HeaderRule();

            Assert.That(
                () => rule.InitializeFromSettings(null),
                Throws.Exception.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("settings"));
        }
Esempio n. 4
0
        public void IsMatch_WithRegexNameAndExactValue_ReturnsExpected(
            string headerName, string headerValue, bool expectedResult)
        {
            var rule = new HeaderRule("regex:he.*me", "headervalue");

            var request = CreateWithHeaders(headerName, headerValue);

            Assert.AreEqual(expectedResult, rule.IsMatch(request));
        }
Esempio n. 5
0
        public void IsMatch_WithExactNameAndRegexValueInversed_ReturnsExpected(
            string headerName, string headerValue, bool expectedResult)
        {
            var rule = new HeaderRule("headername", "not:regex:he.*ue");

            var request = CreateWithHeaders(headerName, headerValue);

            Assert.AreEqual(expectedResult, rule.IsMatch(request));
        }
Esempio n. 6
0
        public void IsMatch_HeadersAreNull_ReturnsFalse()
        {
            var rule = new HeaderRule(string.Empty, string.Empty);

            var          request = Substitute.For <IStumpsHttpRequest>();
            IHttpHeaders dict    = null;

            request.Headers.Returns(dict);

            Assert.IsFalse(rule.IsMatch(request));
        }
Esempio n. 7
0
        public void IsMatch_HeadersAreNull_ReturnsFalse()
        {
            var rule = new HeaderRule(string.Empty, string.Empty);

            var request = Substitute.For<IStumpsHttpRequest>();
            IHttpHeaders dict = null;

            request.Headers.Returns(dict);

            Assert.IsFalse(rule.IsMatch(request));
        }
Esempio n. 8
0
        public void InitializeFromSettings_WithValidSettings_InitializesCorrectly(string headerName, string headerValue, string expectedName, string expectedValue)
        {
            var settings = new[]
            {
                new RuleSetting { Name = "header.name", Value = headerName },
                new RuleSetting { Name = "header.value", Value = headerValue }
            };

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

            Assert.IsTrue(rule.IsInitialized);
            Assert.AreEqual(expectedName, rule.HeaderNameTextMatch);
            Assert.AreEqual(expectedValue, rule.HeaderValueTextMatch);
        }
Esempio n. 9
0
        public void InitializeFromSettings_WithValidSettings_InitializesCorrectly(string headerName, string headerValue, string expectedName, string expectedValue)
        {
            var settings = new[]
            {
                new RuleSetting {
                    Name = "header.name", Value = headerName
                },
                new RuleSetting {
                    Name = "header.value", Value = headerValue
                }
            };

            var rule = new HeaderRule();

            rule.InitializeFromSettings(settings);

            Assert.IsTrue(rule.IsInitialized);
            Assert.AreEqual(expectedName, rule.HeaderNameTextMatch);
            Assert.AreEqual(expectedValue, rule.HeaderValueTextMatch);
        }
Esempio n. 10
0
        public void IsMatch_RequestIsNull_ReturnsFalse()
        {
            var rule = new HeaderRule(string.Empty, string.Empty);

            Assert.IsFalse(rule.IsMatch(null));
        }
Esempio n. 11
0
        public void Constructor_Default_NotInitialized()
        {
            var rule = new HeaderRule();

            Assert.IsFalse(rule.IsInitialized);
        }
Esempio n. 12
0
 public void IsMatch_RequestIsNull_ReturnsFalse()
 {
     var rule = new HeaderRule(string.Empty, string.Empty);
     Assert.IsFalse(rule.IsMatch(null));
 }
Esempio n. 13
0
 public void GetRuleSettings_WhenCalled_ReturnsList()
 {
     var rule = new HeaderRule("a", "b");
     var list = new List<RuleSetting>(rule.GetRuleSettings());
     Assert.AreEqual(2, list.Count);
 }
Esempio n. 14
0
        public void IsMatch_WithRegexNameInversedAndExactValue_ReturnsExpected(
            string headerName, string headerValue, bool expectedResult)
        {
            var rule = new HeaderRule("not:regex:he.*me", "headervalue");

            var request = CreateWithHeaders(headerName, headerValue);
            Assert.AreEqual(expectedResult, rule.IsMatch(request));
        }
Esempio n. 15
0
        public void IsMatch_WithExactNameAndRegexValue_ReturnsExpected(
            string headerName, string headerValue, bool expectedResult)
        {
            var rule = new HeaderRule("headername", "regex:he.*ue");

            var request = CreateWithHeaders(headerName, headerValue);
            Assert.AreEqual(expectedResult, rule.IsMatch(request));
        }
Esempio n. 16
0
 public void Constructor_Default_NotInitialized()
 {
     var rule = new HeaderRule();
     Assert.IsFalse(rule.IsInitialized);
 }