示例#1
0
        private void CheckInvalidParse(string input)
        {
            Assert.Throws <FormatException>(() => { WarningHeaderValue.Parse(input); });

            Assert.False(WarningHeaderValue.TryParse(input, out WarningHeaderValue result));
            Assert.Null(result);
        }
        public void Parse_Invalid()
        {
            try {
                WarningHeaderValue.Parse(null);
                Assert.Fail("#1");
            } catch (FormatException) {
            }

            try {
                WarningHeaderValue.Parse("  ");
                Assert.Fail("#2");
            } catch (FormatException) {
            }

            try {
                WarningHeaderValue.Parse("a");
                Assert.Fail("#3");
            } catch (FormatException) {
            }

            try {
                WarningHeaderValue.Parse("5555 foo:8080 \"\"");
                Assert.Fail("#4");
            } catch (FormatException) {
            }
        }
示例#3
0
        private void CheckInvalidTryParse(string input)
        {
            WarningHeaderValue result = null;

            Assert.False(WarningHeaderValue.TryParse(input, out result));
            Assert.Null(result);
        }
示例#4
0
        private static void CheckInvalidWarningViaLength(string input, int startIndex)
        {
            object result = null;

            Assert.Equal(0, WarningHeaderValue.GetWarningLength(input, startIndex, out result));
            Assert.Null(result);
        }
示例#5
0
        public void TryParse_Invalid()
        {
            WarningHeaderValue res;

            Assert.IsFalse(WarningHeaderValue.TryParse("", out res), "#1");
            Assert.IsNull(res, "#2");
        }
示例#6
0
        public void Ctor_3ParamsOverload_AllFieldsInitializedCorrectly()
        {
            WarningHeaderValue warning = new WarningHeaderValue(111, ".host", "\"Revalidation failed\"");

            Assert.Equal(111, warning.Code);
            Assert.Equal(".host", warning.Agent);
            Assert.Equal("\"Revalidation failed\"", warning.Text);
            Assert.Null(warning.Date);

            warning = new WarningHeaderValue(112, "[::1]", "\"Disconnected operation\"");
            Assert.Equal(112, warning.Code);
            Assert.Equal("[::1]", warning.Agent);
            Assert.Equal("\"Disconnected operation\"", warning.Text);
            Assert.Null(warning.Date);

            Assert.Throws <ArgumentOutOfRangeException>(() => { new WarningHeaderValue(-1, "host", "\"\""); });
            Assert.Throws <ArgumentOutOfRangeException>(() => { new WarningHeaderValue(1000, "host", "\"\""); });

            Assert.Throws <ArgumentException>(() => { new WarningHeaderValue(100, null, "\"\""); });
            Assert.Throws <ArgumentException>(() => { new WarningHeaderValue(100, "", "\"\""); });
            Assert.Throws <FormatException>(() => { new WarningHeaderValue(100, "x y", "\"\""); });
            Assert.Throws <FormatException>(() => { new WarningHeaderValue(100, "x ", "\"\""); });
            Assert.Throws <FormatException>(() => { new WarningHeaderValue(100, " x", "\"\""); });

            Assert.Throws <ArgumentException>(() => { new WarningHeaderValue(100, null, "\"\""); });
            Assert.Throws <ArgumentException>(() => { new WarningHeaderValue(100, "", "\"\""); });
            Assert.Throws <FormatException>(() => { new WarningHeaderValue(100, "h", "x"); });
            Assert.Throws <FormatException>(() => { new WarningHeaderValue(100, "h", "\"x"); });
        }
示例#7
0
        private void CheckValidTryParse(string input, WarningHeaderValue expectedResult)
        {
            WarningHeaderValue result = null;

            Assert.True(WarningHeaderValue.TryParse(input, out result));
            Assert.Equal(expectedResult, result);
        }
示例#8
0
        private static void CheckGetWarningLength(string input, int startIndex, int expectedLength,
                                                  WarningHeaderValue expectedResult)
        {
            object result = null;

            Assert.Equal(expectedLength, WarningHeaderValue.GetWarningLength(input, startIndex, out result));
            Assert.Equal(expectedResult, result);
        }
示例#9
0
        public void Parse()
        {
            var res = WarningHeaderValue.Parse("1 n \"\"");

            Assert.IsNull(res.Date, "#1");
            Assert.AreEqual(1, res.Code, "#2");
            Assert.AreEqual("n", res.Agent, "#3");
            Assert.AreEqual("\"\"", res.Text, "#4");
        }
示例#10
0
        public void ToString_UseDifferentRanges_AllSerializedCorrectly()
        {
            WarningHeaderValue warning = new WarningHeaderValue(113, "host:80", "\"Heuristic expiration\"");

            Assert.Equal("113 host:80 \"Heuristic expiration\"", warning.ToString());

            warning = new WarningHeaderValue(199, "[::1]", "\"Miscellaneous warning\"",
                                             new DateTimeOffset(2010, 7, 19, 18, 31, 27, TimeSpan.Zero));
            Assert.Equal("199 [::1] \"Miscellaneous warning\" \"Mon, 19 Jul 2010 18:31:27 GMT\"", warning.ToString());
        }
示例#11
0
        public void TryParse()
        {
            WarningHeaderValue res;

            Assert.IsTrue(WarningHeaderValue.TryParse("22 a \"b\"", out res), "#1");
            Assert.IsNull(res.Date, "#2");
            Assert.AreEqual(22, res.Code, "#3");
            Assert.AreEqual("a", res.Agent, "#4");
            Assert.AreEqual("\"b\"", res.Text, "#5");
        }
示例#12
0
        private void CheckValidParsedValue(string input, int startIndex, WarningHeaderValue expectedResult,
                                           int expectedIndex)
        {
            HttpHeaderParser parser = GenericHeaderParser.MultipleValueWarningParser;
            object           result = null;

            Assert.True(parser.TryParseValue(input, null, ref startIndex, out result),
                        string.Format("TryParse returned false: {0}", input));
            Assert.Equal(expectedIndex, startIndex);
            Assert.Equal(result, expectedResult);
        }
示例#13
0
        public void Equals()
        {
            var value = new WarningHeaderValue(13, "x", "\"v\"");

            Assert.AreEqual(value, new WarningHeaderValue(13, "X", "\"v\""), "#1");
            Assert.AreNotEqual(value, new WarningHeaderValue(13, "x", "\"V\""), "#2");
            Assert.AreNotEqual(value, new WarningHeaderValue(13, "y", "\"V\""), "#3");
            Assert.AreNotEqual(value, new WarningHeaderValue(1, "x", "\"V\""), "#4");

            value = new WarningHeaderValue(6, "DD", "\"c\"", DateTimeOffset.MaxValue);
            Assert.AreEqual(value, new WarningHeaderValue(6, "DD", "\"c\"", DateTimeOffset.MaxValue), "#5");
            Assert.AreNotEqual(value, new WarningHeaderValue(6, "y", "\"V\""), "#6");
        }
示例#14
0
        public void Properties()
        {
            var value = new WarningHeaderValue(5, "ag", "\"tt\"");

            Assert.IsNull(value.Date, "#1");
            Assert.AreEqual(5, value.Code, "#2");
            Assert.AreEqual("ag", value.Agent, "#3");
            Assert.AreEqual("\"tt\"", value.Text, "#4");

            value = new WarningHeaderValue(5, "ag", "\"tt\"", DateTimeOffset.MinValue);
            Assert.AreEqual(DateTimeOffset.MinValue, value.Date, "#5");
            Assert.AreEqual(5, value.Code, "#6");
            Assert.AreEqual("ag", value.Agent, "#7");
            Assert.AreEqual("\"tt\"", value.Text, "#8");
        }
        public void Parse()
        {
            var res = WarningHeaderValue.Parse("1 n \"\"");

            Assert.IsNull(res.Date, "#1");
            Assert.AreEqual(1, res.Code, "#2");
            Assert.AreEqual("n", res.Agent, "#3");
            Assert.AreEqual("\"\"", res.Text, "#4");
            Assert.AreEqual("001 n \"\"", res.ToString(), "#5");

            res = WarningHeaderValue.Parse("155 foo:8080 \"tttext \" \"Sunday, 06-Nov-94 08:49:37 GMT\" ");
            Assert.AreEqual(new DateTimeOffset(1994, 11, 6, 8, 49, 37, TimeSpan.Zero), res.Date, "#11");
            Assert.AreEqual(155, res.Code, "#12");
            Assert.AreEqual("foo:8080", res.Agent, "#13");
            Assert.AreEqual("\"tttext \"", res.Text, "#14");
            Assert.AreEqual("155 foo:8080 \"tttext \" \"Sun, 06 Nov 1994 08:49:37 GMT\"", res.ToString(), "#5");
        }
示例#16
0
        public void Clone_Call_CloneFieldsMatchSourceFields()
        {
            WarningHeaderValue source = new WarningHeaderValue(299, "host", "\"Miscellaneous persistent warning\"");
            WarningHeaderValue clone  = (WarningHeaderValue)((ICloneable)source).Clone();

            Assert.Equal(source.Code, clone.Code);
            Assert.Equal(source.Agent, clone.Agent);
            Assert.Equal(source.Text, clone.Text);
            Assert.Equal(source.Date, clone.Date);

            source = new WarningHeaderValue(110, "host", "\"Response is stale\"",
                                            new DateTimeOffset(2010, 7, 31, 15, 37, 05, TimeSpan.Zero));
            clone = (WarningHeaderValue)((ICloneable)source).Clone();
            Assert.Equal(source.Code, clone.Code);
            Assert.Equal(source.Agent, clone.Agent);
            Assert.Equal(source.Text, clone.Text);
            Assert.Equal(source.Date, clone.Date);
        }
示例#17
0
        public void GetHashCode_UseSameAndDifferentRanges_SameOrDifferentHashCodes()
        {
            WarningHeaderValue warning1 = new WarningHeaderValue(214, "host", "\"Transformation applied\"");
            WarningHeaderValue warning2 = new WarningHeaderValue(214, "HOST", "\"Transformation applied\"");
            WarningHeaderValue warning3 = new WarningHeaderValue(215, "host", "\"Transformation applied\"");
            WarningHeaderValue warning4 = new WarningHeaderValue(214, "other", "\"Transformation applied\"");
            WarningHeaderValue warning5 = new WarningHeaderValue(214, "host", "\"TRANSFORMATION APPLIED\"");
            WarningHeaderValue warning6 = new WarningHeaderValue(214, "host", "\"Transformation applied\"",
                                                                 new DateTimeOffset(2010, 7, 19, 18, 31, 27, TimeSpan.Zero));
            WarningHeaderValue warning7 = new WarningHeaderValue(214, "host", "\"Transformation applied\"",
                                                                 new DateTimeOffset(2011, 7, 19, 18, 31, 27, TimeSpan.Zero));
            WarningHeaderValue warning8 = new WarningHeaderValue(214, "host", "\"Transformation applied\"",
                                                                 new DateTimeOffset(2010, 7, 19, 18, 31, 27, TimeSpan.Zero));

            Assert.Equal(warning1.GetHashCode(), warning2.GetHashCode());
            Assert.NotEqual(warning1.GetHashCode(), warning3.GetHashCode());
            Assert.NotEqual(warning1.GetHashCode(), warning4.GetHashCode());
            Assert.NotEqual(warning1.GetHashCode(), warning6.GetHashCode());
            Assert.NotEqual(warning1.GetHashCode(), warning7.GetHashCode());
            Assert.NotEqual(warning6.GetHashCode(), warning7.GetHashCode());
            Assert.Equal(warning6.GetHashCode(), warning8.GetHashCode());
        }
示例#18
0
        public void Ctor_4ParamsOverload_AllFieldsInitializedCorrectly()
        {
            WarningHeaderValue warning = new WarningHeaderValue(111, "host", "\"Revalidation failed\"",
                                                                new DateTimeOffset(2010, 7, 19, 17, 9, 15, TimeSpan.Zero));

            Assert.Equal(111, warning.Code);
            Assert.Equal("host", warning.Agent);
            Assert.Equal("\"Revalidation failed\"", warning.Text);
            Assert.Equal(new DateTimeOffset(2010, 7, 19, 17, 9, 15, TimeSpan.Zero), warning.Date);

            Assert.Throws <ArgumentOutOfRangeException>(() => { new WarningHeaderValue(-1, "host", "\"\""); });
            Assert.Throws <ArgumentOutOfRangeException>(() => { new WarningHeaderValue(1000, "host", "\"\""); });

            Assert.Throws <ArgumentException>(() => { new WarningHeaderValue(100, null, "\"\""); });
            Assert.Throws <ArgumentException>(() => { new WarningHeaderValue(100, "", "\"\""); });
            Assert.Throws <FormatException>(() => { new WarningHeaderValue(100, "[::1]:80(x)", "\"\""); });
            Assert.Throws <FormatException>(() => { new WarningHeaderValue(100, "host::80", "\"\""); });
            Assert.Throws <FormatException>(() => { new WarningHeaderValue(100, "192.168.0.1=", "\"\""); });

            Assert.Throws <ArgumentException>(() => { new WarningHeaderValue(100, null, "\"\""); });
            Assert.Throws <ArgumentException>(() => { new WarningHeaderValue(100, "", "\"\""); });
            Assert.Throws <FormatException>(() => { new WarningHeaderValue(100, "h", "(x)"); });
            Assert.Throws <FormatException>(() => { new WarningHeaderValue(100, "h", "\"x\"y"); });
        }
示例#19
0
        public void Equals_UseSameAndDifferentRanges_EqualOrNotEqualNoExceptions()
        {
            WarningHeaderValue warning1 = new WarningHeaderValue(214, "host", "\"Transformation applied\"");
            WarningHeaderValue warning2 = new WarningHeaderValue(214, "HOST", "\"Transformation applied\"");
            WarningHeaderValue warning3 = new WarningHeaderValue(215, "host", "\"Transformation applied\"");
            WarningHeaderValue warning4 = new WarningHeaderValue(214, "other", "\"Transformation applied\"");
            WarningHeaderValue warning5 = new WarningHeaderValue(214, "host", "\"TRANSFORMATION APPLIED\"");
            WarningHeaderValue warning6 = new WarningHeaderValue(214, "host", "\"Transformation applied\"",
                                                                 new DateTimeOffset(2010, 7, 19, 18, 31, 27, TimeSpan.Zero));
            WarningHeaderValue warning7 = new WarningHeaderValue(214, "host", "\"Transformation applied\"",
                                                                 new DateTimeOffset(2011, 7, 19, 18, 31, 27, TimeSpan.Zero));
            WarningHeaderValue warning8 = new WarningHeaderValue(214, "host", "\"Transformation applied\"",
                                                                 new DateTimeOffset(2010, 7, 19, 18, 31, 27, TimeSpan.Zero));

            Assert.False(warning1.Equals(null), "214 host \"t.a.\" vs. <null>");
            Assert.True(warning1.Equals(warning2), "214 host \"t.a.\" vs. 214 HOST \"t.a.\"");
            Assert.False(warning1.Equals(warning3), "214 host \"t.a.\" vs. 215 host \"t.a.\"");
            Assert.False(warning1.Equals(warning4), "214 host \"t.a.\" vs. 214 other \"t.a.\"");
            Assert.False(warning1.Equals(warning6), "214 host \"t.a.\" vs. 214 host \"T.A.\"");
            Assert.False(warning1.Equals(warning7), "214 host \"t.a.\" vs. 214 host \"t.a.\" \"D\"");
            Assert.False(warning7.Equals(warning1), "214 host \"t.a.\" \"D\" vs. 214 host \"t.a.\"");
            Assert.False(warning6.Equals(warning7), "214 host \"t.a.\" \"D\" vs. 214 host \"t.a.\" \"other D\"");
            Assert.True(warning6.Equals(warning8), "214 host \"t.a.\" \"D\" vs. 214 host \"t.a.\" \"D\"");
        }
示例#20
0
 /// <summary>
 /// Sets the Warning header of the request to the specified value.
 /// </summary>
 /// <param name="value">The Warning header value.</param>
 /// <returns>An <see cref="IRequest"/> object that represents the request.</returns>
 public static IRequest Warning(this IWith @this, WarningHeaderValue value)
 => @this.AddHeaderValue(headers => headers.Warning, value);
示例#21
0
 public static bool TryParse(string input, out WarningHeaderValue parsedValue)
 {
     throw new NotImplementedException();
 }
示例#22
0
		public static bool TryParse (string input, out WarningHeaderValue parsedValue)
		{
			throw new NotImplementedException ();
		}
示例#23
0
 public static bool TryParse(string input, out WarningHeaderValue parsedValue);
示例#24
0
 private void CheckInvalidParse(string input)
 {
     Assert.Throws <FormatException>(() => { WarningHeaderValue.Parse(input); });
 }
示例#25
0
        private void CheckValidParse(string input, WarningHeaderValue expectedResult)
        {
            WarningHeaderValue result = WarningHeaderValue.Parse(input);

            Assert.Equal(expectedResult, result);
        }