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"); }); }
public override bool Equals(object obj) { WarningHeaderValue other = obj as WarningHeaderValue; if (other == null) { return(false); } // 'agent' is a host/token, i.e. use case-insensitive comparison. Use case-sensitive comparison for 'text' // since it is a quoted string. if ((_code != other._code) || (!string.Equals(_agent, other._agent, StringComparison.OrdinalIgnoreCase)) || (!string.Equals(_text, other._text, StringComparison.Ordinal))) { return(false); } // We have a date set. Verify 'other' has also a date that matches our value. if (_date.HasValue) { return(other._date.HasValue && (_date.Value == other._date.Value)); } // We don't have a date. If 'other' has a date, we're not equal. return(!other._date.HasValue); }
private WarningHeaderValue(WarningHeaderValue source) { Contract.Requires(source != null); this.code = source.code; this.agent = source.agent; this.text = source.text; this.date = source.date; }
private WarningHeaderValue(WarningHeaderValue source) { Contract.Requires(source != null); _code = source._code; _agent = source._agent; _text = source._text; _date = source._date; }
private WarningHeaderValue(WarningHeaderValue source) { Debug.Assert(source != null); _code = source._code; _agent = source._agent; _text = source._text; _date = source._date; }
private WarningHeaderValue(WarningHeaderValue source) { Contract.Requires(source != null); this.code = source.code; this.agent = source.agent; this.text = source.text; this.date = source.date; }
internal static int GetWarningLength(string input, int startIndex, out object parsedValue) { Debug.Assert(startIndex >= 0); parsedValue = null; if (string.IsNullOrEmpty(input) || (startIndex >= input.Length)) { return(0); } // Read <code> in '<code> <agent> <text> ["<date>"]' int code; int current = startIndex; if (!TryReadCode(input, ref current, out code)) { return(0); } // Read <agent> in '<code> <agent> <text> ["<date>"]' string agent; if (!TryReadAgent(input, current, ref current, out agent)) { return(0); } // Read <text> in '<code> <agent> <text> ["<date>"]' int textLength = 0; int textStartIndex = current; if (HttpRuleParser.GetQuotedStringLength(input, current, out textLength) != HttpParseResult.Parsed) { return(0); } current = current + textLength; // Read <date> in '<code> <agent> <text> ["<date>"]' DateTimeOffset?date = null; if (!TryReadDate(input, ref current, out date)) { return(0); } WarningHeaderValue result = new WarningHeaderValue(); result._code = code; result._agent = agent; result._text = input.Substring(textStartIndex, textLength); result._date = date; parsedValue = result; return(current - startIndex); }
private WarningHeaderValue(WarningHeaderValue source) { Contract.Requires(source != null); _code = source._code; _agent = source._agent; _text = source._text; _date = source._date; }
private WarningHeaderValue(WarningHeaderValue source) { Debug.Assert(source != null); _code = source._code; _agent = source._agent; _text = source._text; _date = source._date; }
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()); }
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); }
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"); }
public static bool TryParse(string input, out WarningHeaderValue parsedValue) { var lexer = new Lexer(input); Token token; if (TryParseElement(lexer, out parsedValue, out token) && token == Token.Type.End) { return(true); } parsedValue = null; return(false); }
public static bool TryParse(string input, out WarningHeaderValue parsedValue) { int index = 0; object output; parsedValue = null; if (GenericHeaderParser.SingleValueWarningParser.TryParseValue(input, null, ref index, out output)) { parsedValue = (WarningHeaderValue)output; return(true); } return(false); }
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()); }
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"); }); }
public static bool TryParse(string input, out WarningHeaderValue parsedValue) { parsedValue = null; var lexer = new Lexer(input); var t = lexer.Scan(); if (t != Token.Type.Token) { return(false); } int code; if (!lexer.TryGetNumericValue(t, out code) || !IsCodeValid(code)) { return(false); } t = lexer.Scan(); if (t != Token.Type.Token) { return(false); } var next = t; if (lexer.PeekChar() == ':') { lexer.EatChar(); next = lexer.Scan(); if (next != Token.Type.Token) { return(false); } } var value = new WarningHeaderValue(); value.Code = code; value.Agent = lexer.GetStringValue(t, next); t = lexer.Scan(); if (t != Token.Type.QuotedString) { return(false); } value.Text = lexer.GetStringValue(t); t = lexer.Scan(); if (t == Token.Type.QuotedString) { DateTimeOffset date; if (!lexer.TryGetDateValue(t, out date)) { return(false); } value.Date = date; t = lexer.Scan(); } if (t != Token.Type.End) { return(false); } parsedValue = value; return(true); }
internal static int GetWarningLength(string input, int startIndex, out object parsedValue) { Contract.Requires(startIndex >= 0); parsedValue = null; if (string.IsNullOrEmpty(input) || (startIndex >= input.Length)) { return 0; } // Read <code> in '<code> <agent> <text> ["<date>"]' int code; int current = startIndex; if (!TryReadCode(input, ref current, out code)) { return 0; } // Read <agent> in '<code> <agent> <text> ["<date>"]' string agent; if (!TryReadAgent(input, current, ref current, out agent)) { return 0; } // Read <text> in '<code> <agent> <text> ["<date>"]' int textLength = 0; int textStartIndex = current; if (HttpRuleParser.GetQuotedStringLength(input, current, out textLength) != HttpParseResult.Parsed) { return 0; } current = current + textLength; // Read <date> in '<code> <agent> <text> ["<date>"]' DateTimeOffset? date = null; if (!TryReadDate(input, ref current, out date)) { return 0; } WarningHeaderValue result = new WarningHeaderValue(); result._code = code; result._agent = agent; result._text = input.Substring(textStartIndex, textLength); result._date = date; parsedValue = result; return current - startIndex; }
public static bool TryParse(string input, out WarningHeaderValue parsedValue) { int index = 0; object output; parsedValue = null; if (GenericHeaderParser.SingleValueWarningParser.TryParseValue(input, null, ref index, out output)) { parsedValue = (WarningHeaderValue)output; return true; } return false; }
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 static bool TryParse (string input, out WarningHeaderValue parsedValue) { parsedValue = null; var lexer = new Lexer (input); var t = lexer.Scan (); if (t != Token.Type.Token) return false; int code; if (!lexer.TryGetNumericValue (t, out code) || !IsCodeValid (code)) return false; t = lexer.Scan (); if (t != Token.Type.Token) return false; var next = t; if (lexer.PeekChar () == ':') { lexer.EatChar (); next = lexer.Scan (); if (next != Token.Type.Token) return false; } var value = new WarningHeaderValue (); value.Code = code; value.Agent = lexer.GetStringValue (t, next); t = lexer.Scan (); if (t != Token.Type.QuotedString) return false; value.Text = lexer.GetStringValue (t); t = lexer.Scan (); if (t == Token.Type.QuotedString) { DateTimeOffset date; if (!lexer.TryGetDateValue (t, out date)) return false; value.Date = date; t = lexer.Scan (); } if (t != Token.Type.End) return false; parsedValue = value; return true; }
private void CheckValidParse(string input, WarningHeaderValue expectedResult) { WarningHeaderValue result = WarningHeaderValue.Parse(input); Assert.Equal(expectedResult, result); }
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); }
private void CheckValidTryParse(string input, WarningHeaderValue expectedResult) { WarningHeaderValue result = null; Assert.True(WarningHeaderValue.TryParse(input, out result)); Assert.Equal(expectedResult, result); }
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); }
public static bool TryParse(string input, out WarningHeaderValue parsedValue) { var lexer = new Lexer (input); Token token; if (TryParseElement (lexer, out parsedValue, out token) && token == Token.Type.End) return true; parsedValue = null; return false; }
public static bool TryParse(string input, out WarningHeaderValue parsedValue) { }
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\""); }