public void ToStringShouldReturnExpectedString() { HttpHeaderValueElement e1 = new HttpHeaderValueElement("e1", null, new KeyValuePair <string, string> [0]); HttpHeaderValueElement e2 = new HttpHeaderValueElement("e2", "token", new KeyValuePair <string, string> [0]); HttpHeaderValueElement e3 = new HttpHeaderValueElement("e3", "\"quoted-string\"", new KeyValuePair <string, string> [0]); HttpHeaderValueElement e4 = new HttpHeaderValueElement("e4", null, new[] { new KeyValuePair <string, string>("p1", "v1"), new KeyValuePair <string, string>("p2", null) }); HttpHeaderValueElement e5 = new HttpHeaderValueElement("e5", "token", new[] { new KeyValuePair <string, string>("p1", null), new KeyValuePair <string, string>("p2", "\"v2\"") }); HttpHeaderValueElement e6 = new HttpHeaderValueElement("e6", "\"quoted-string\"", new[] { new KeyValuePair <string, string>("p1", null), new KeyValuePair <string, string>("p2", null), new KeyValuePair <string, string>("p3", "v3"), new KeyValuePair <string, string>("p4", "\"v4\"") }); const string eStr1 = "e1"; const string eStr2 = "e2=token"; const string eStr3 = "e3=\"quoted-string\""; const string eStr4 = "e4;p1=v1;p2"; const string eStr5 = "e5=token;p1;p2=\"v2\""; const string eStr6 = "e6=\"quoted-string\";p1;p2;p3=v3;p4=\"v4\""; var testCases = new[] { new KeyValuePair <HttpHeaderValueElement, string>(e1, eStr1), new KeyValuePair <HttpHeaderValueElement, string>(e2, eStr2), new KeyValuePair <HttpHeaderValueElement, string>(e3, eStr3), new KeyValuePair <HttpHeaderValueElement, string>(e4, eStr4), new KeyValuePair <HttpHeaderValueElement, string>(e5, eStr5), new KeyValuePair <HttpHeaderValueElement, string>(e6, eStr6), }; foreach (KeyValuePair <HttpHeaderValueElement, string> test in testCases) { test.Key.ToString().Should().Be(test.Value); } }
public void ToHttpHeaderValueElementsShouldReturnDictionaryContainingAllElements() { HttpHeaderValueElement e1 = new HttpHeaderValueElement("e1", null, new KeyValuePair <string, string> [0]); HttpHeaderValueElement e2 = new HttpHeaderValueElement("e2", "token", new KeyValuePair <string, string> [0]); HttpHeaderValueElement e3 = new HttpHeaderValueElement("e3", "\"quoted-string\"", new KeyValuePair <string, string> [0]); HttpHeaderValueElement e4 = new HttpHeaderValueElement("e4", null, new[] { new KeyValuePair <string, string>("p1", "v1"), new KeyValuePair <string, string>("p2", null) }); HttpHeaderValueElement e5 = new HttpHeaderValueElement("e5", "token", new[] { new KeyValuePair <string, string>("p1", null), new KeyValuePair <string, string>("p2", "\"v2\"") }); HttpHeaderValueElement e6 = new HttpHeaderValueElement("e6", "\"quoted-string\"", new[] { new KeyValuePair <string, string>("p1", null), new KeyValuePair <string, string>("p2", null), new KeyValuePair <string, string>("p3", "v3"), new KeyValuePair <string, string>("p4", "\"v4\"") }); const string eStr1 = "e1"; const string eStr2 = "e2=token"; const string eStr3 = "e3=\"quoted-string\""; const string eStr4 = "e4;p1=v1;p2"; const string eStr5 = "e5=token;p1;p2=\"v2\""; const string eStr6 = "e6=\"quoted-string\";p1;p2;p3=v3;p4=\"v4\""; string headerValue = string.Join(",", eStr1, eStr2, eStr3, eStr4, eStr5, eStr6); var lexer = HttpHeaderValueLexer.Create("header", headerValue); var elements = lexer.ToHttpHeaderValue(); elements.Count.Should().Be(6); AssertEqual(e1, elements["e1"]); AssertEqual(e2, elements["e2"]); AssertEqual(e3, elements["e3"]); AssertEqual(e4, elements["e4"]); AssertEqual(e5, elements["e5"]); AssertEqual(e6, elements["e6"]); }
public void ToStringShouldReturnExpectedString() { HttpHeaderValueElement e1 = new HttpHeaderValueElement("e1", null, new KeyValuePair<string, string>[0]); HttpHeaderValueElement e2 = new HttpHeaderValueElement("e2", "token", new KeyValuePair<string, string>[0]); HttpHeaderValueElement e3 = new HttpHeaderValueElement("e3", "\"quoted-string\"", new KeyValuePair<string, string>[0]); HttpHeaderValueElement e4 = new HttpHeaderValueElement("e4", null, new[] { new KeyValuePair<string, string>("p1", "v1"), new KeyValuePair<string, string>("p2", null) }); HttpHeaderValueElement e5 = new HttpHeaderValueElement("e5", "token", new[] { new KeyValuePair<string, string>("p1", null), new KeyValuePair<string, string>("p2", "\"v2\"") }); HttpHeaderValueElement e6 = new HttpHeaderValueElement("e6", "\"quoted-string\"", new[] { new KeyValuePair<string, string>("p1", null), new KeyValuePair<string, string>("p2", null), new KeyValuePair<string, string>("p3", "v3"), new KeyValuePair<string, string>("p4", "\"v4\"") }); const string eStr1 = "e1"; const string eStr2 = "e2=token"; const string eStr3 = "e3=\"quoted-string\""; const string eStr4 = "e4;p1=v1;p2"; const string eStr5 = "e5=token;p1;p2=\"v2\""; const string eStr6 = "e6=\"quoted-string\";p1;p2;p3=v3;p4=\"v4\""; var testCases = new[] { new KeyValuePair<HttpHeaderValueElement, string>(e1, eStr1), new KeyValuePair<HttpHeaderValueElement, string>(e2, eStr2), new KeyValuePair<HttpHeaderValueElement, string>(e3, eStr3), new KeyValuePair<HttpHeaderValueElement, string>(e4, eStr4), new KeyValuePair<HttpHeaderValueElement, string>(e5, eStr5), new KeyValuePair<HttpHeaderValueElement, string>(e6, eStr6), }; foreach(KeyValuePair<HttpHeaderValueElement, string> test in testCases) { test.Key.ToString().Should().Be(test.Value); } }
public void HttpHeaderValueToStringShouldPutAllHttpHeaderValueElementsInString() { HttpHeaderValueElement e1 = new HttpHeaderValueElement("e1", null, new KeyValuePair <string, string> [0]); HttpHeaderValueElement e2 = new HttpHeaderValueElement("e2", "token", new KeyValuePair <string, string> [0]); HttpHeaderValueElement e3 = new HttpHeaderValueElement("e3", "\"quoted-string\"", new KeyValuePair <string, string> [0]); HttpHeaderValueElement e4 = new HttpHeaderValueElement("e4", null, new[] { new KeyValuePair <string, string>("p1", "v1"), new KeyValuePair <string, string>("p2", null) }); HttpHeaderValueElement e5 = new HttpHeaderValueElement("e5", "token", new[] { new KeyValuePair <string, string>("p1", null), new KeyValuePair <string, string>("p2", "\"v2\"") }); HttpHeaderValueElement e6 = new HttpHeaderValueElement("e6", "\"quoted-string\"", new[] { new KeyValuePair <string, string>("p1", null), new KeyValuePair <string, string>("p2", null), new KeyValuePair <string, string>("p3", "v3"), new KeyValuePair <string, string>("p4", "\"v4\"") }); const string eStr1 = "e1"; const string eStr2 = "e2=token"; const string eStr3 = "e3=\"quoted-string\""; const string eStr4 = "e4;p1=v1;p2"; const string eStr5 = "e5=token;p1;p2=\"v2\""; const string eStr6 = "e6=\"quoted-string\";p1;p2;p3=v3;p4=\"v4\""; HttpHeaderValue elements = new HttpHeaderValue { { "e1", e1 }, { "e2", e2 }, { "e3", e3 }, { "e4", e4 }, { "e5", e5 }, { "e6", e6 }, }; var items = elements.ToString().Split(new[] { ',' }); Assert.Contains(eStr1, items); Assert.Contains(eStr2, items); Assert.Contains(eStr3, items); Assert.Contains(eStr4, items); Assert.Contains(eStr5, items); Assert.Contains(eStr6, items); }
private static void AssertEqual(HttpHeaderValueElement element1, HttpHeaderValueElement element2) { Assert.Equal(element1.Name, element2.Name); Assert.Equal(element1.Value, element2.Value); Assert.Equal(element1.Parameters.Count(), element2.Parameters.Count()); var parameters1 = element1.Parameters.ToArray(); var parameters2 = element2.Parameters.ToArray(); for (int i = 0; i < parameters1.Length; i++) { Assert.Equal(parameters1[i], parameters2[i]); } }
public void HttpHeaderValueToStringShouldPutAllHttpHeaderValueElementsInString() { HttpHeaderValueElement e1 = new HttpHeaderValueElement("e1", null, new KeyValuePair<string, string>[0]); HttpHeaderValueElement e2 = new HttpHeaderValueElement("e2", "token", new KeyValuePair<string, string>[0]); HttpHeaderValueElement e3 = new HttpHeaderValueElement("e3", "\"quoted-string\"", new KeyValuePair<string, string>[0]); HttpHeaderValueElement e4 = new HttpHeaderValueElement("e4", null, new[] { new KeyValuePair<string, string>("p1", "v1"), new KeyValuePair<string, string>("p2", null) }); HttpHeaderValueElement e5 = new HttpHeaderValueElement("e5", "token", new[] { new KeyValuePair<string, string>("p1", null), new KeyValuePair<string, string>("p2", "\"v2\"") }); HttpHeaderValueElement e6 = new HttpHeaderValueElement("e6", "\"quoted-string\"", new[] { new KeyValuePair<string, string>("p1", null), new KeyValuePair<string, string>("p2", null), new KeyValuePair<string, string>("p3", "v3"), new KeyValuePair<string, string>("p4", "\"v4\"") }); const string eStr1 = "e1"; const string eStr2 = "e2=token"; const string eStr3 = "e3=\"quoted-string\""; const string eStr4 = "e4;p1=v1;p2"; const string eStr5 = "e5=token;p1;p2=\"v2\""; const string eStr6 = "e6=\"quoted-string\";p1;p2;p3=v3;p4=\"v4\""; HttpHeaderValue elements = new HttpHeaderValue {{"e1", e1}, {"e2", e2}, {"e3", e3}, {"e4", e4}, {"e5", e5}, {"e6", e6},}; elements.ToString().Split(new[] {','}).Should().Contain(eStr1).And.Contain(eStr2).And.Contain(eStr3).And.Contain(eStr4).And.Contain(eStr5).And.Contain(eStr6); }
public void ToHttpHeaderValueElementsShouldReturnDictionaryContainingAllElements() { HttpHeaderValueElement e1 = new HttpHeaderValueElement("e1", null, new KeyValuePair<string, string>[0]); HttpHeaderValueElement e2 = new HttpHeaderValueElement("e2", "token", new KeyValuePair<string, string>[0]); HttpHeaderValueElement e3 = new HttpHeaderValueElement("e3", "\"quoted-string\"", new KeyValuePair<string, string>[0]); HttpHeaderValueElement e4 = new HttpHeaderValueElement("e4", null, new[] { new KeyValuePair<string, string>("p1", "v1"), new KeyValuePair<string, string>("p2", null) }); HttpHeaderValueElement e5 = new HttpHeaderValueElement("e5", "token", new[] {new KeyValuePair<string, string>("p1", null), new KeyValuePair<string, string>("p2", "\"v2\"")}); HttpHeaderValueElement e6 = new HttpHeaderValueElement("e6", "\"quoted-string\"", new[] {new KeyValuePair<string, string>("p1", null), new KeyValuePair<string, string>("p2", null), new KeyValuePair<string, string>("p3", "v3"), new KeyValuePair<string, string>("p4", "\"v4\"")}); const string eStr1 = "e1"; const string eStr2 = "e2=token"; const string eStr3 = "e3=\"quoted-string\""; const string eStr4 = "e4;p1=v1;p2"; const string eStr5 = "e5=token;p1;p2=\"v2\""; const string eStr6 = "e6=\"quoted-string\";p1;p2;p3=v3;p4=\"v4\""; string headerValue = string.Join(",", eStr1, eStr2, eStr3, eStr4, eStr5, eStr6); var lexer = HttpHeaderValueLexer.Create("header", headerValue); var elements = lexer.ToHttpHeaderValue(); elements.Count.Should().Be(6); AssertEqual(e1, elements["e1"]); AssertEqual(e2, elements["e2"]); AssertEqual(e3, elements["e3"]); AssertEqual(e4, elements["e4"]); AssertEqual(e5, elements["e5"]); AssertEqual(e6, elements["e6"]); }