public void op_FromString_string() { HttpHeader expected = "name: value"; var obj = HttpHeaderDictionary.FromString(expected); var actual = obj.First <HttpHeader>(); Assert.Equal(expected, actual); }
public void op_FromString_string_whenMultiple() { HttpHeader host = "Host: example.com"; HttpHeader ua = "User-Agent: Example"; var buffer = new StringBuilder(); buffer.AppendLine(host); buffer.AppendLine(ua); var obj = HttpHeaderDictionary.FromString(buffer.ToString()); Assert.Equal(host, obj.First <HttpHeader>()); Assert.Equal(ua, obj.Last <HttpHeader>()); }
protected string Load(string value) { if (null == value) { throw new ArgumentNullException("value"); } if (0 == value.Length) { throw new ArgumentOutOfRangeException("value"); } string body = null; var index = value.IndexOf(_break, StringComparison.Ordinal); if (-1 == index) { index = value.Length; } else { body = value.Substring(index + _break.Length); } var headers = value.Substring(0, index); index = headers.IndexOf(Environment.NewLine, StringComparison.Ordinal); string line; if (-1 == index) { line = headers; headers = string.Empty; } else { line = headers.Substring(0, index); headers = headers.Substring(index + Environment.NewLine.Length); } Headers = HttpHeaderDictionary.FromString(headers); Body = null == body ? null : new TextBody(body); return(line); }
public void op_FromString_stringNull() { Assert.Throws <ArgumentNullException>(() => HttpHeaderDictionary.FromString(null)); }
public void op_FromString_stringEmpty() { Assert.Empty(HttpHeaderDictionary.FromString(string.Empty).ToList <HttpHeader>()); }