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},};
            elements.ToString().Split(new[] {','}).Should().Contain(eStr1).And.Contain(eStr2).And.Contain(eStr3).And.Contain(eStr4).And.Contain(eStr5).And.Contain(eStr6);
        }
 /// <summary>
 /// Sets the <paramref name="preference"/> to the "Prefer" header on the underlying IODataRequestMessage or
 /// the "Preference-Applied" header on the underlying IODataResponseMessage.
 /// </summary>
 /// <param name="preference">The preference to set.</param>
 /// <remarks>
 /// If <paramref name="preference"/> is already on the header, this method does a replace rather than adding another instance of the same preference.
 /// </remarks>
 private void Set(HttpHeaderValueElement preference)
 {
     Debug.Assert(preference != null, "preference != null");
     this.Preferences[preference.Name] = preference;
     this.SetPreferencesToMessageHeader();
 }
示例#4
0
 /// <summary>
 /// Sets the <paramref name="preference"/> to the "Prefer" header on the underlying IODataRequestMessage or
 /// the "Preference-Applied" header on the underlying IODataResponseMessage.
 /// </summary>
 /// <param name="preference">The preference to set.</param>
 /// <remarks>
 /// If <paramref name="preference"/> is already on the header, this method does a replace rather than adding another instance of the same preference.
 /// </remarks>
 private void Set(HttpHeaderValueElement preference)
 {
     Debug.Assert(preference != null, "preference != null");
     this.Preferences[preference.Name] = preference;
     this.SetPreferencesToMessageHeader();
 }
 private static void AssertAreEqual(HttpHeaderValueElement element1, HttpHeaderValueElement element2)
 {
     Assert.AreEqual(element1.Name, element2.Name);
     Assert.AreEqual(element1.Value, element2.Value);
     Assert.AreEqual(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.AreEqual(parameters1[i], parameters2[i]);
     }
 }
        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);
            AssertAreEqual(e1, elements["e1"]);
            AssertAreEqual(e2, elements["e2"]);
            AssertAreEqual(e3, elements["e3"]);
            AssertAreEqual(e4, elements["e4"]);
            AssertAreEqual(e5, elements["e5"]);
            AssertAreEqual(e6, elements["e6"]);
        }