A class representing a Stump rule that evaluates the headers of an HTTP request.
Inheritance: IStumpRule
Exemplo 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);
        }
Exemplo 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"));
        }
Exemplo 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"));
        }
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo 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);
        }
Exemplo 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);
        }
Exemplo n.º 10
0
        public void IsMatch_RequestIsNull_ReturnsFalse()
        {
            var rule = new HeaderRule(string.Empty, string.Empty);

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

            Assert.IsFalse(rule.IsInitialized);
        }
Exemplo n.º 12
0
 public void IsMatch_RequestIsNull_ReturnsFalse()
 {
     var rule = new HeaderRule(string.Empty, string.Empty);
     Assert.IsFalse(rule.IsMatch(null));
 }
Exemplo 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);
 }
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo n.º 16
0
 public void Constructor_Default_NotInitialized()
 {
     var rule = new HeaderRule();
     Assert.IsFalse(rule.IsInitialized);
 }