/WCFWebApi/test/cit/unit/System.Net.Http.Test.Unit/Headers/HttpRequestHeadersTest.cs
C# | 1503 lines | 1200 code | 277 blank | 26 comment | 17 complexity | e657b1ecb3fc390b8c85736090d3afce MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0
Large files files are truncated, but you can click here to view the full file
- using System;
- using System.Text;
- using System.Collections.Generic;
- using System.Linq;
- using Microsoft.VisualStudio.TestTools.UnitTesting;
- using System.Net.Http.Headers;
- using System.Net.Test.Common;
- using System.Net.Mail;
- using System.Net.Test.Common.Logging;
-
- namespace System.Net.Http.Test.Headers
- {
- [TestClass]
- public class HttpRequestHeadersTest
- {
- private HttpRequestHeaders headers;
-
- [TestInitialize]
- public void TestInitialize()
- {
- headers = new HttpRequestHeaders();
- }
-
- #region Request headers
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void Accept_AddInvalidValueUsingUnusualCasing_ParserRetrievedUsingCaseInsensitiveComparison()
- {
- // Use uppercase header name to make sure the parser gets retrieved using case-insensitive comparison.
- headers.Add("AcCePt", "this is invalid");
- }
-
- [TestMethod]
- public void Accept_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- MediaTypeWithQualityHeaderValue value1 = new MediaTypeWithQualityHeaderValue("text/plain");
- value1.CharSet = "utf-8";
- value1.Quality = 0.5;
- value1.Parameters.Add(new NameValueHeaderValue("custom", "value"));
- MediaTypeWithQualityHeaderValue value2 = new MediaTypeWithQualityHeaderValue("text/plain");
- value2.CharSet = "iso-8859-1";
- value2.Quality = 0.3868;
-
- Assert.AreEqual(0, headers.Accept.Count, "Collection expected to be empty on first call.");
-
- headers.Accept.Add(value1);
- headers.Accept.Add(value2);
-
- Assert.AreEqual(2, headers.Accept.Count, "Count");
- Assert.AreEqual(value1, headers.Accept.ElementAt(0), "Accept[0] expected to be value1.");
- Assert.AreEqual(value2, headers.Accept.ElementAt(1), "Accept[1] expected to be value2.");
-
- headers.Accept.Clear();
- Assert.AreEqual(0, headers.Accept.Count, "Count after Clear().");
- }
-
- [TestMethod]
- public void Accept_ReadEmptyProperty_EmptyCollection()
- {
- HttpRequestMessage request = new HttpRequestMessage();
-
- Assert.AreEqual(0, request.Headers.Accept.Count);
- // Copy to another list
- List<MediaTypeWithQualityHeaderValue> accepts = request.Headers.Accept.ToList();
- Assert.AreEqual(0, accepts.Count);
- accepts = new List<MediaTypeWithQualityHeaderValue>(request.Headers.Accept);
- Assert.AreEqual(0, accepts.Count);
- }
-
- [TestMethod]
- public void Accept_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Accept",
- ",, , ,,text/plain; charset=iso-8859-1; q=1.0,\r\n */xml; charset=utf-8; q=0.5,,,");
-
- MediaTypeWithQualityHeaderValue value1 = new MediaTypeWithQualityHeaderValue("text/plain");
- value1.CharSet = "iso-8859-1";
- value1.Quality = 1.0;
-
- MediaTypeWithQualityHeaderValue value2 = new MediaTypeWithQualityHeaderValue("*/xml");
- value2.CharSet = "utf-8";
- value2.Quality = 0.5;
-
- Assert.AreEqual(value1, headers.Accept.ElementAt(0), "Accept[0]");
- Assert.AreEqual(value2, headers.Accept.ElementAt(1), "Accept[1]");
- }
-
- [TestMethod]
- public void Accept_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- // Add a valid media-type with an invalid quality value
- headers.AddWithoutValidation("Accept", "text/plain; q=a"); // invalid quality
- Assert.IsNotNull(headers.Accept.First(), "Accept first value");
- Assert.IsNull(headers.Accept.First().Quality, "Accept.Quality"); // No quality value shown
- Assert.AreEqual("text/plain; q=a", headers.Accept.First().ToString(), "ToString()");
-
- headers.Clear();
- headers.AddWithoutValidation("Accept", "text/plain application/xml"); // no separator
-
- Assert.AreEqual(0, headers.Accept.Count, "Accept.Count");
- Assert.AreEqual(1, headers.GetValues("Accept").Count(), "Accept.Count");
- Assert.AreEqual("text/plain application/xml", headers.GetValues("Accept").First(), "Accept value");
- }
-
- [TestMethod]
- public void AcceptCharset_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.AreEqual(0, headers.AcceptCharset.Count, "Collection expected to be empty on first call.");
-
- headers.AcceptCharset.Add(new StringWithQualityHeaderValue("iso-8859-5"));
- headers.AcceptCharset.Add(new StringWithQualityHeaderValue("unicode-1-1", 0.8));
-
- Assert.AreEqual(2, headers.AcceptCharset.Count, "Count");
- Assert.AreEqual(new StringWithQualityHeaderValue("iso-8859-5"), headers.AcceptCharset.ElementAt(0),
- "AcceptCharset[0]");
- Assert.AreEqual(new StringWithQualityHeaderValue("unicode-1-1", 0.8), headers.AcceptCharset.ElementAt(1),
- "AcceptCharset[1]");
-
- headers.AcceptCharset.Clear();
- Assert.AreEqual(0, headers.AcceptCharset.Count, "Count after Clear().");
- }
-
- [TestMethod]
- public void AcceptCharset_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Accept-Charset", ", ,,iso-8859-5 , \r\n utf-8 ; q=0.300 ,,,");
-
- Assert.AreEqual(new StringWithQualityHeaderValue("iso-8859-5"),
- headers.AcceptCharset.ElementAt(0), "AcceptCharset[0]");
- Assert.AreEqual(new StringWithQualityHeaderValue("utf-8", 0.3),
- headers.AcceptCharset.ElementAt(1), "AcceptCharset[1]");
- }
-
- [TestMethod]
- public void AcceptCharset_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("Accept-Charset", "iso-8859-5 utf-8"); // no separator
- Assert.AreEqual(0, headers.AcceptCharset.Count, "Accept.Count");
- Assert.AreEqual(1, headers.GetValues("Accept-Charset").Count(), "Accept-Charset.Count");
- Assert.AreEqual("iso-8859-5 utf-8", headers.GetValues("Accept-Charset").First(), "Accept-Charset value");
-
- headers.Clear();
- headers.AddWithoutValidation("Accept-Charset", "utf-8; q=1; q=0.3");
- Assert.AreEqual(0, headers.AcceptCharset.Count, "AcceptCharset.Count");
- Assert.AreEqual(1, headers.GetValues("Accept-Charset").Count(), "Accept-Charset.Count");
- Assert.AreEqual("utf-8; q=1; q=0.3", headers.GetValues("Accept-Charset").First(), "Accept-Charset value");
- }
-
- [TestMethod]
- public void AcceptCharset_AddMultipleValuesAndGetValueString_AllValuesAddedUsingTheCorrectDelimiter()
- {
- headers.AddWithoutValidation("Accept-Charset", "invalid value");
- headers.Add("Accept-Charset", "utf-8");
- headers.AcceptCharset.Add(new StringWithQualityHeaderValue("iso-8859-5", 0.5));
-
- foreach (var header in headers.GetHeaderStrings())
- {
- Assert.AreEqual("Accept-Charset", header.Key);
- Assert.AreEqual("utf-8, iso-8859-5; q=0.5, invalid value", header.Value);
- }
- }
-
- [TestMethod]
- public void AcceptEncoding_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.AreEqual(0, headers.AcceptEncoding.Count, "Collection expected to be empty on first call.");
-
- headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("compress", 0.9));
- headers.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip"));
-
- Assert.AreEqual(2, headers.AcceptEncoding.Count, "Count");
- Assert.AreEqual(new StringWithQualityHeaderValue("compress", 0.9), headers.AcceptEncoding.ElementAt(0),
- "AcceptEncoding[0]");
- Assert.AreEqual(new StringWithQualityHeaderValue("gzip"), headers.AcceptEncoding.ElementAt(1),
- "AcceptEncoding[1]");
-
- headers.AcceptEncoding.Clear();
- Assert.AreEqual(0, headers.AcceptEncoding.Count, "Count after Clear().");
- }
-
- [TestMethod]
- public void AcceptEncoding_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Accept-Encoding", ", gzip; q=1.0, identity; q=0.5, *;q=0, ");
-
- Assert.AreEqual(new StringWithQualityHeaderValue("gzip", 1),
- headers.AcceptEncoding.ElementAt(0), "AcceptEncoding[0]");
- Assert.AreEqual(new StringWithQualityHeaderValue("identity", 0.5),
- headers.AcceptEncoding.ElementAt(1), "AcceptEncoding[1]");
- Assert.AreEqual(new StringWithQualityHeaderValue("*", 0),
- headers.AcceptEncoding.ElementAt(2), "AcceptEncoding[2]");
-
- headers.AcceptEncoding.Clear();
- headers.AddWithoutValidation("Accept-Encoding", "");
- Assert.AreEqual(0, headers.AcceptEncoding.Count, "Count after Clear().");
- Assert.IsFalse(headers.Contains("Accept-Encoding"));
- }
-
- [TestMethod]
- public void AcceptEncoding_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("Accept-Encoding", "gzip deflate"); // no separator
- Assert.AreEqual(0, headers.AcceptEncoding.Count, "AcceptEncoding.Count");
- Assert.AreEqual(1, headers.GetValues("Accept-Encoding").Count(), "Accept-Encoding.Count");
- Assert.AreEqual("gzip deflate", headers.GetValues("Accept-Encoding").First(), "Accept-Encoding value");
-
- headers.Clear();
- headers.AddWithoutValidation("Accept-Encoding", "compress; q=1; gzip");
- Assert.AreEqual(0, headers.AcceptEncoding.Count, "AcceptEncoding.Count");
- Assert.AreEqual(1, headers.GetValues("Accept-Encoding").Count(), "Accept-Encoding.Count");
- Assert.AreEqual("compress; q=1; gzip", headers.GetValues("Accept-Encoding").First(), "Accept-Encoding value");
- }
-
- [TestMethod]
- public void AcceptLanguage_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.AreEqual(0, headers.AcceptLanguage.Count, "Collection expected to be empty on first call.");
-
- headers.AcceptLanguage.Add(new StringWithQualityHeaderValue("da"));
- headers.AcceptLanguage.Add(new StringWithQualityHeaderValue("en-GB", 0.8));
- headers.AcceptLanguage.Add(new StringWithQualityHeaderValue("en", 0.7));
-
- Assert.AreEqual(3, headers.AcceptLanguage.Count, "Count");
- Assert.AreEqual(new StringWithQualityHeaderValue("da"), headers.AcceptLanguage.ElementAt(0),
- "AcceptLanguage[0]");
- Assert.AreEqual(new StringWithQualityHeaderValue("en-GB", 0.8), headers.AcceptLanguage.ElementAt(1),
- "AcceptLanguage[1]");
- Assert.AreEqual(new StringWithQualityHeaderValue("en", 0.7), headers.AcceptLanguage.ElementAt(2),
- "AcceptLanguage[2]");
-
- headers.AcceptLanguage.Clear();
- Assert.AreEqual(0, headers.AcceptLanguage.Count, "Count after Clear().");
- }
-
- [TestMethod]
- public void AcceptLanguage_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Accept-Language", " , de-DE;q=0.9,de-AT;q=0.5,*;q=0.010 , ");
-
- Assert.AreEqual(new StringWithQualityHeaderValue("de-DE", 0.9),
- headers.AcceptLanguage.ElementAt(0), "AcceptLanguage[0]");
- Assert.AreEqual(new StringWithQualityHeaderValue("de-AT", 0.5),
- headers.AcceptLanguage.ElementAt(1), "AcceptLanguage[1]");
- Assert.AreEqual(new StringWithQualityHeaderValue("*", 0.01),
- headers.AcceptLanguage.ElementAt(2), "AcceptLanguage[2]");
-
- headers.AcceptLanguage.Clear();
- headers.AddWithoutValidation("Accept-Language", "");
- Assert.AreEqual(0, headers.AcceptLanguage.Count, "Count after Clear().");
- Assert.IsFalse(headers.Contains("Accept-Language"));
- }
-
- [TestMethod]
- public void AcceptLanguage_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("Accept-Language", "de -DE"); // no separator
- Assert.AreEqual(0, headers.AcceptLanguage.Count, "AcceptLanguage.Count");
- Assert.AreEqual(1, headers.GetValues("Accept-Language").Count(), "Accept-Language.Count");
- Assert.AreEqual("de -DE", headers.GetValues("Accept-Language").First(), "Accept-Language value");
-
- headers.Clear();
- headers.AddWithoutValidation("Accept-Language", "en; q=0.4,[");
- Assert.AreEqual(0, headers.AcceptLanguage.Count, "AcceptLanguage.Count");
- Assert.AreEqual(1, headers.GetValues("Accept-Language").Count(), "Accept-Language.Count");
- Assert.AreEqual("en; q=0.4,[", headers.GetValues("Accept-Language").First(), "Accept-Language value");
- }
-
- [TestMethod]
- public void Expect_Add100Continue_Success()
- {
- // use non-default casing to make sure we do case-insensitive comparison.
- headers.Expect.Add(new NameValueWithParametersHeaderValue("100-CONTINUE"));
- Assert.IsTrue(headers.ExpectContinue == true);
- Assert.AreEqual(1, headers.Expect.Count);
- }
-
- [TestMethod]
- public void Expect_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.AreEqual(0, headers.Expect.Count, "Expect expected to be empty on first call.");
- Assert.IsNull(headers.ExpectContinue, "ExpectContinue should be null by default.");
-
- headers.Expect.Add(new NameValueWithParametersHeaderValue("custom1"));
- headers.Expect.Add(new NameValueWithParametersHeaderValue("custom2"));
- headers.ExpectContinue = true;
-
- // Connection collection has 2 values plus '100-Continue'
- Assert.AreEqual(3, headers.Expect.Count, "Expect.Count");
- Assert.AreEqual(3, headers.GetValues("Expect").Count(), "Expect header value count.");
- Assert.IsTrue(headers.ExpectContinue == true, "ExpectContinue == true");
- Assert.AreEqual(new NameValueWithParametersHeaderValue("custom1"), headers.Expect.ElementAt(0),
- "Expect[0]");
- Assert.AreEqual(new NameValueWithParametersHeaderValue("custom2"), headers.Expect.ElementAt(1),
- "Expect[1]");
-
- // Remove '100-continue' value from store. But leave other 'Expect' values.
- headers.ExpectContinue = false;
- Assert.IsTrue(headers.ExpectContinue == false, "ExpectContinue == false");
- Assert.AreEqual(2, headers.Expect.Count, "Expect.Count");
- Assert.AreEqual(new NameValueWithParametersHeaderValue("custom1"), headers.Expect.ElementAt(0),
- "Expect[0]");
- Assert.AreEqual(new NameValueWithParametersHeaderValue("custom2"), headers.Expect.ElementAt(1),
- "Expect[1]");
-
- headers.ExpectContinue = true;
- headers.Expect.Clear();
- Assert.IsTrue(headers.ExpectContinue == false, "ExpectContinue should be modified by Expect.Clear().");
- Assert.AreEqual(0, headers.Expect.Count, "Count after Clear().");
- IEnumerable<string> dummyArray;
- Assert.IsFalse(headers.TryGetValues("Expect", out dummyArray), "Expect header count after Expect.Clear().");
-
- // Remove '100-continue' value from store. Since there are no other 'Expect' values, remove whole header.
- headers.ExpectContinue = false;
- Assert.IsTrue(headers.ExpectContinue == false, "ExpectContinue == false");
- Assert.AreEqual(0, headers.Expect.Count, "Expect.Count");
- Assert.IsFalse(headers.Contains("Expect"));
-
- headers.ExpectContinue = null;
- Assert.IsNull(headers.ExpectContinue, "ExpectContinue");
- }
-
- [TestMethod]
- public void Expect_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Expect",
- ", , 100-continue, name1 = value1, name2; param2=paramValue2, name3=value3; param3 ,");
-
- // Connection collection has 3 values plus '100-continue'
- Assert.AreEqual(4, headers.Expect.Count, "Expect.Count");
- Assert.AreEqual(4, headers.GetValues("Expect").Count(), "Expect header value count.");
- Assert.IsTrue(headers.ExpectContinue == true, "ExpectContinue expected to be true.");
-
- Assert.AreEqual(new NameValueWithParametersHeaderValue("100-continue"),
- headers.Expect.ElementAt(0), "Expect[0]");
-
- Assert.AreEqual(new NameValueWithParametersHeaderValue("name1", "value1"),
- headers.Expect.ElementAt(1), "Expect[1]");
-
- NameValueWithParametersHeaderValue expected2 = new NameValueWithParametersHeaderValue("name2");
- expected2.Parameters.Add(new NameValueHeaderValue("param2", "paramValue2"));
- Assert.AreEqual(expected2, headers.Expect.ElementAt(2), "Expect[2]");
-
- NameValueWithParametersHeaderValue expected3 = new NameValueWithParametersHeaderValue("name3", "value3");
- expected3.Parameters.Add(new NameValueHeaderValue("param3"));
- Assert.AreEqual(expected3, headers.Expect.ElementAt(3), "Expect[3]");
-
- headers.Expect.Clear();
- Assert.IsNull(headers.ExpectContinue, "ExpectContinue should be modified by Expect.Clear().");
- Assert.AreEqual(0, headers.Expect.Count, "Count after Clear().");
- IEnumerable<string> dummyArray;
- Assert.IsFalse(headers.TryGetValues("Expect", out dummyArray), "Expect header count after Expect.Clear().");
- }
-
- [TestMethod]
- public void Expect_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("Expect", "100-continue other"); // no separator
-
- Assert.AreEqual(0, headers.Expect.Count, "Expect.Count");
- Assert.AreEqual(1, headers.GetValues("Expect").Count(), "Expect.Count");
- Assert.AreEqual("100-continue other", headers.GetValues("Expect").First(), "Expect value");
- }
-
- [TestMethod]
- public void Host_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.IsNull(headers.Host, "Host should be null by default.");
-
- headers.Host = "host";
- Assert.AreEqual("host", headers.Host);
-
- headers.Host = null;
- Assert.IsNull(headers.Host, "Host should be null after setting it to null.");
- Assert.IsFalse(headers.Contains("Host"),
- "Header store should not contain a header 'Host' after setting it to null.");
-
- ExceptionAssert.ThrowsFormat(() => headers.Host = "invalid host", "Setting invalid Host value should throw.");
- }
-
- [TestMethod]
- public void Host_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Host", "host:80");
-
- Assert.AreEqual("host:80", headers.Host);
- }
-
- [TestMethod]
- public void IfMatch_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.AreEqual(0, headers.IfMatch.Count, "IfMatch expected to be empty on first call.");
-
- headers.IfMatch.Add(new EntityTagHeaderValue("\"custom1\""));
- headers.IfMatch.Add(new EntityTagHeaderValue("\"custom2\"", true));
-
- Assert.AreEqual(2, headers.IfMatch.Count, "IfMatch.Count");
- Assert.AreEqual(2, headers.GetValues("If-Match").Count(), "If-Match header value count.");
- Assert.AreEqual(new EntityTagHeaderValue("\"custom1\""), headers.IfMatch.ElementAt(0),
- "IfMatch[0]");
- Assert.AreEqual(new EntityTagHeaderValue("\"custom2\"", true), headers.IfMatch.ElementAt(1),
- "IfMatch[1]");
-
- headers.IfMatch.Clear();
- Assert.AreEqual(0, headers.IfMatch.Count, "Count after Clear().");
- Assert.IsFalse(headers.Contains("If-Match"), "Header store should not contain 'If-Match'");
- }
-
- [TestMethod]
- public void IfMatch_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("If-Match", ", , W/\"tag1\", \"tag2\", W/\"tag3\" ,");
-
- Assert.AreEqual(3, headers.IfMatch.Count, "IfMatch.Count");
- Assert.AreEqual(3, headers.GetValues("If-Match").Count(), "If-Match header value count.");
-
- Assert.AreEqual(new EntityTagHeaderValue("\"tag1\"", true), headers.IfMatch.ElementAt(0),
- "IfMatch[0]");
- Assert.AreEqual(new EntityTagHeaderValue("\"tag2\"", false), headers.IfMatch.ElementAt(1),
- "IfMatch[1]");
- Assert.AreEqual(new EntityTagHeaderValue("\"tag3\"", true), headers.IfMatch.ElementAt(2),
- "IfMatch[2]");
-
- headers.IfMatch.Clear();
- headers.Add("If-Match", "*");
- Assert.AreEqual(1, headers.IfMatch.Count, "Count after Clear().");
- Assert.AreSame(EntityTagHeaderValue.Any, headers.IfMatch.ElementAt(0), "IfMatch[0]");
- }
-
- [TestMethod]
- public void IfMatch_UseAddMethodWithInvalidInput_PropertyNotUpdated()
- {
-
- headers.AddWithoutValidation("If-Match", "W/\"tag1\" \"tag2\""); // no separator
- Assert.AreEqual(0, headers.IfMatch.Count, "IfMatch.Count");
- Assert.AreEqual(1, headers.GetValues("If-Match").Count(), "If-Match header value count.");
- }
-
- [TestMethod]
- public void IfNoneMatch_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.AreEqual(0, headers.IfNoneMatch.Count, "IfNoneMatch expected to be empty on first call.");
-
- headers.IfNoneMatch.Add(new EntityTagHeaderValue("\"custom1\""));
- headers.IfNoneMatch.Add(new EntityTagHeaderValue("\"custom2\"", true));
-
- Assert.AreEqual(2, headers.IfNoneMatch.Count, "IfNoneMatch.Count");
- Assert.AreEqual(2, headers.GetValues("If-None-Match").Count(), "If-None-Match header value count.");
- Assert.AreEqual(new EntityTagHeaderValue("\"custom1\""), headers.IfNoneMatch.ElementAt(0),
- "IfNoneMatch[0]");
- Assert.AreEqual(new EntityTagHeaderValue("\"custom2\"", true), headers.IfNoneMatch.ElementAt(1),
- "IfNoneMatch[1]");
-
- headers.IfNoneMatch.Clear();
- Assert.AreEqual(0, headers.IfNoneMatch.Count, "Count after Clear().");
- Assert.IsFalse(headers.Contains("If-None-Match"), "Header store should not contain 'If-None-Match'");
- }
-
- [TestMethod]
- public void IfNoneMatch_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("If-None-Match", "W/\"tag1\", \"tag2\", W/\"tag3\"");
-
- Assert.AreEqual(3, headers.IfNoneMatch.Count, "IfNoneMatch.Count");
- Assert.AreEqual(3, headers.GetValues("If-None-Match").Count(), "If-None-Match header value count.");
-
- Assert.AreEqual(new EntityTagHeaderValue("\"tag1\"", true), headers.IfNoneMatch.ElementAt(0),
- "IfNoneMatch[0]");
- Assert.AreEqual(new EntityTagHeaderValue("\"tag2\"", false), headers.IfNoneMatch.ElementAt(1),
- "IfNoneMatch[1]");
- Assert.AreEqual(new EntityTagHeaderValue("\"tag3\"", true), headers.IfNoneMatch.ElementAt(2),
- "IfNoneMatch[2]");
-
- headers.IfNoneMatch.Clear();
- headers.Add("If-None-Match", "*");
- Assert.AreEqual(1, headers.IfNoneMatch.Count, "Count after Clear().");
- Assert.AreSame(EntityTagHeaderValue.Any, headers.IfNoneMatch.ElementAt(0), "IfNoneMatch[0]");
- }
-
- [TestMethod]
- public void TE_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- TransferCodingWithQualityHeaderValue value1 = new TransferCodingWithQualityHeaderValue("custom");
- value1.Quality = 0.5;
- value1.Parameters.Add(new NameValueHeaderValue("name", "value"));
- TransferCodingWithQualityHeaderValue value2 = new TransferCodingWithQualityHeaderValue("custom");
- value2.Quality = 0.3868;
-
- Assert.AreEqual(0, headers.TE.Count, "Collection expected to be empty on first call.");
-
- headers.TE.Add(value1);
- headers.TE.Add(value2);
-
- Assert.AreEqual(2, headers.TE.Count, "Count");
- Assert.AreEqual(value1, headers.TE.ElementAt(0), "TE[0] expected to be value1.");
- Assert.AreEqual(value2, headers.TE.ElementAt(1), "TE[1] expected to be value2.");
-
- headers.TE.Clear();
- Assert.AreEqual(0, headers.TE.Count, "Count after Clear().");
- }
-
- [TestMethod]
- public void TE_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("TE",
- ",custom1; param1=value1; q=1.0,,\r\n custom2; param2=value2; q=0.5 ,");
-
- TransferCodingWithQualityHeaderValue value1 = new TransferCodingWithQualityHeaderValue("custom1");
- value1.Parameters.Add(new NameValueHeaderValue("param1", "value1"));
- value1.Quality = 1.0;
-
- TransferCodingWithQualityHeaderValue value2 = new TransferCodingWithQualityHeaderValue("custom2");
- value2.Parameters.Add(new NameValueHeaderValue("param2", "value2"));
- value2.Quality = 0.5;
-
- Assert.AreEqual(value1, headers.TE.ElementAt(0), "TE[0]");
- Assert.AreEqual(value2, headers.TE.ElementAt(1), "TE[1]");
-
- headers.Clear();
- headers.AddWithoutValidation("TE", "");
- Assert.IsFalse(headers.Contains("TE"), "'TE' header should not be added if it just has empty values.");
- }
-
- [TestMethod]
- public void Range_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.IsNull(headers.Range, "Uninitialized Range");
- RangeHeaderValue value = new RangeHeaderValue(1, 2);
-
- headers.Range = value;
- Assert.AreEqual(value, headers.Range, "Initialized Range");
-
- headers.Range = null;
- Assert.IsNull(headers.Range, "Range after setting it to null.");
- }
-
- [TestMethod]
- public void Range_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Range", "custom= , ,1-2, -4 , ");
-
- RangeHeaderValue value = new RangeHeaderValue();
- value.Unit = "custom";
- value.Ranges.Add(new RangeItemHeaderValue(1, 2));
- value.Ranges.Add(new RangeItemHeaderValue(null, 4));
-
- Assert.AreEqual(value, headers.Range, "Initialized ContentRange");
- }
-
- [TestMethod]
- public void Authorization_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.IsNull(headers.Authorization, "Authorization should be null by default.");
-
- headers.Authorization = new AuthenticationHeaderValue("Basic", "QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
- Assert.AreEqual(new AuthenticationHeaderValue("Basic", "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="), headers.Authorization);
-
- headers.Authorization = null;
- Assert.IsNull(headers.Authorization, "Authorization should be null after setting it to null.");
- Assert.IsFalse(headers.Contains("Authorization"),
- "Header store should not contain a header 'Authorization' after setting it to null.");
- }
-
- [TestMethod]
- public void Authorization_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Authorization", "NTLM blob");
-
- Assert.AreEqual(new AuthenticationHeaderValue("NTLM", "blob"), headers.Authorization);
- }
-
- [TestMethod]
- public void ProxyAuthorization_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.IsNull(headers.ProxyAuthorization, "ProxyAuthorization should be null by default.");
-
- headers.ProxyAuthorization = new AuthenticationHeaderValue("Basic", "QWxhZGRpbjpvcGVuIHNlc2FtZQ==");
- Assert.AreEqual(new AuthenticationHeaderValue("Basic", "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="),
- headers.ProxyAuthorization);
-
- headers.ProxyAuthorization = null;
- Assert.IsNull(headers.ProxyAuthorization, "ProxyAuthorization should be null after setting it to null.");
- Assert.IsFalse(headers.Contains("ProxyAuthorization"),
- "Header store should not contain a header 'ProxyAuthorization' after setting it to null.");
- }
-
- [TestMethod]
- public void ProxyAuthorization_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Proxy-Authorization", "NTLM blob");
-
- Assert.AreEqual(new AuthenticationHeaderValue("NTLM", "blob"), headers.ProxyAuthorization);
- }
-
- [TestMethod]
- public void UserAgent_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.AreEqual(0, headers.UserAgent.Count, "UserAgent expected to be empty on first call.");
-
- headers.UserAgent.Add(new ProductInfoHeaderValue("(custom1)"));
- headers.UserAgent.Add(new ProductInfoHeaderValue("custom2", "1.1"));
-
- Assert.AreEqual(2, headers.UserAgent.Count, "UserAgent.Count");
- Assert.AreEqual(2, headers.GetValues("User-Agent").Count(), "User-Agent header value count.");
- Assert.AreEqual(new ProductInfoHeaderValue("(custom1)"), headers.UserAgent.ElementAt(0), "UserAgent[0]");
- Assert.AreEqual(new ProductInfoHeaderValue("custom2", "1.1"), headers.UserAgent.ElementAt(1), "UserAgent[1]");
-
- headers.UserAgent.Clear();
- Assert.AreEqual(0, headers.UserAgent.Count, "Count after Clear().");
- Assert.IsFalse(headers.Contains("User-Agent"), "User-Agent header should be removed after calling Clear().");
-
- headers.UserAgent.Add(new ProductInfoHeaderValue("(comment)"));
- headers.UserAgent.Remove(new ProductInfoHeaderValue("(comment)"));
- Assert.AreEqual(0, headers.UserAgent.Count, "Count after Remove().");
- Assert.IsFalse(headers.Contains("User-Agent"), "User-Agent header should be removed after removing last value.");
- }
-
- [TestMethod]
- public void UserAgent_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("User-Agent", "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.6.30 Version/10.63");
-
- Assert.AreEqual(4, headers.UserAgent.Count, "UserAgent.Count");
- Assert.AreEqual(4, headers.GetValues("User-Agent").Count(), "User-Agent header value count.");
-
- Assert.AreEqual(new ProductInfoHeaderValue("Opera", "9.80"), headers.UserAgent.ElementAt(0), "UserAgent[0]");
- Assert.AreEqual(new ProductInfoHeaderValue("(Windows NT 6.1; U; en)"), headers.UserAgent.ElementAt(1), "UserAgent[1]");
- Assert.AreEqual(new ProductInfoHeaderValue("Presto", "2.6.30"), headers.UserAgent.ElementAt(2), "UserAgent[2]");
- Assert.AreEqual(new ProductInfoHeaderValue("Version", "10.63"), headers.UserAgent.ElementAt(3), "UserAgent[3]");
-
- headers.UserAgent.Clear();
- Assert.AreEqual(0, headers.UserAgent.Count, "Count after Clear().");
- Assert.IsFalse(headers.Contains("User-Agent"), "User-Agent header should be removed after calling Clear().");
- }
-
- [TestMethod]
- public void UserAgent_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("User-Agent", "custom会");
- Assert.IsNull(headers.GetParsedValues("User-Agent"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("User-Agent").Count(), "Store value count");
- Assert.AreEqual("custom会", headers.GetValues("User-Agent").First(), "Store value");
-
- headers.Clear();
- // Note that "User-Agent" uses whitespaces as separators, so the following is an invalid value
- headers.AddWithoutValidation("User-Agent", "custom1, custom2");
- Assert.IsNull(headers.GetParsedValues("User-Agent"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("User-Agent").Count(), "Store value count");
- Assert.AreEqual("custom1, custom2", headers.GetValues("User-Agent").First(), "Store value");
-
- headers.Clear();
- headers.AddWithoutValidation("User-Agent", "custom1, ");
- Assert.IsNull(headers.GetParsedValues("User-Agent"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("User-Agent").Count(), "Store value count");
- Assert.AreEqual("custom1, ", headers.GetValues("User-Agent").First(), "Store value");
-
- headers.Clear();
- headers.AddWithoutValidation("User-Agent", ",custom1");
- Assert.IsNull(headers.GetParsedValues("User-Agent"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("User-Agent").Count(), "Store value count");
- Assert.AreEqual(",custom1", headers.GetValues("User-Agent").First(), "Store value");
- }
-
- [TestMethod]
- public void UserAgent_AddMultipleValuesAndGetValueString_AllValuesAddedUsingTheCorrectDelimiter()
- {
- headers.AddWithoutValidation("User-Agent", "custom会");
- headers.Add("User-Agent", "custom2/1.1");
- headers.UserAgent.Add(new ProductInfoHeaderValue("(comment)"));
-
- foreach (var header in headers.GetHeaderStrings())
- {
- Assert.AreEqual("User-Agent", header.Key);
- Assert.AreEqual("custom2/1.1 (comment) custom会", header.Value);
- }
- }
-
- [TestMethod]
- public void IfRange_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.IsNull(headers.IfRange, "IfRange expected to be null on first call.");
-
- headers.IfRange = new RangeConditionHeaderValue("\"x\"");
-
- Assert.AreEqual(1, headers.GetValues("If-Range").Count(), "If-Range header value count.");
- Assert.AreEqual(new RangeConditionHeaderValue("\"x\""), headers.IfRange, "IfRange value after setting it.");
-
- headers.IfRange = null;
- Assert.IsNull(headers.IfRange, "IfRange value after setting it to null.");
- Assert.IsFalse(headers.Contains("If-Range"), "If-Range header should be removed after calling Clear().");
- }
-
- [TestMethod]
- public void IfRange_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("If-Range", " W/\"tag\" ");
-
- Assert.AreEqual(new RangeConditionHeaderValue(new EntityTagHeaderValue("\"tag\"", true)),
- headers.IfRange, "IfRange");
- Assert.AreEqual(1, headers.GetValues("If-Range").Count(), "If-Range header value count.");
-
- headers.IfRange = null;
- Assert.IsNull(headers.IfRange, "IfRange value after setting it to null.");
- Assert.IsFalse(headers.Contains("If-Range"), "If-Range header should be removed after calling Clear().");
- }
-
- [TestMethod]
- public void IfRange_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("If-Range", "\"tag\"会");
- Assert.IsNull(headers.GetParsedValues("If-Range"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("If-Range").Count(), "Store value count");
- Assert.AreEqual("\"tag\"会", headers.GetValues("If-Range").First(), "Store value");
-
- headers.Clear();
- headers.AddWithoutValidation("If-Range", " \"tag\", ");
- Assert.IsNull(headers.GetParsedValues("If-Range"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("If-Range").Count(), "Store value count");
- Assert.AreEqual(" \"tag\", ", headers.GetValues("If-Range").First(), "Store value");
- }
-
- [TestMethod]
- public void From_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.IsNull(headers.From, "Host should be null by default.");
-
- headers.From = "info@example.com";
- Assert.AreEqual("info@example.com", headers.From);
-
- headers.From = null;
- Assert.IsNull(headers.From, "From should be null after setting it to null.");
- Assert.IsFalse(headers.Contains("From"),
- "Header store should not contain a header 'From' after setting it to null.");
-
- ExceptionAssert.ThrowsFormat(() => headers.From = " ", "' '");
- ExceptionAssert.ThrowsFormat(() => headers.From = "invalid email address", "invalid email address");
- }
-
- [TestMethod]
- public void From_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("From", " \"My Name\" info@example.com ");
- Assert.AreEqual("\"My Name\" info@example.com ", headers.From);
-
- // The following encoded string represents the character sequence "会员服务".
- headers.Clear();
- headers.AddWithoutValidation("From", "=?utf-8?Q?=E4=BC=9A=E5=91=98=E6=9C=8D=E5=8A=A1?= <info@example.com>");
- Assert.AreEqual("=?utf-8?Q?=E4=BC=9A=E5=91=98=E6=9C=8D=E5=8A=A1?= <info@example.com>", headers.From);
- }
-
- [TestMethod]
- public void From_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("From", " info@example.com ,");
- Assert.IsNull(headers.GetParsedValues("From"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("From").Count(), "Store value count");
- Assert.AreEqual(" info@example.com ,", headers.GetValues("From").First(), "Store value");
-
- headers.Clear();
- headers.AddWithoutValidation("From", "info@");
- Assert.IsNull(headers.GetParsedValues("From"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("From").Count(), "Store value count");
- Assert.AreEqual("info@", headers.GetValues("From").First(), "Store value");
- }
-
- [TestMethod]
- public void IfModifiedSince_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.IsNull(headers.IfModifiedSince, "Host should be null by default.");
-
- DateTimeOffset expected = DateTimeOffset.Now;
- headers.IfModifiedSince = expected;
- Assert.AreEqual(expected, headers.IfModifiedSince);
-
- headers.IfModifiedSince = null;
- Assert.IsNull(headers.IfModifiedSince, "IfModifiedSince should be null after setting it to null.");
- Assert.IsFalse(headers.Contains("If-Modified-Since"),
- "Header store should not contain a header 'IfModifiedSince' after setting it to null.");
- }
-
- [TestMethod]
- public void IfModifiedSince_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("If-Modified-Since", " Sun, 06 Nov 1994 08:49:37 GMT ");
- Assert.AreEqual(new DateTimeOffset(1994, 11, 6, 8, 49, 37, TimeSpan.Zero), headers.IfModifiedSince);
-
- headers.Clear();
- headers.AddWithoutValidation("If-Modified-Since", "Sun, 06 Nov 1994 08:49:37 GMT");
- Assert.AreEqual(new DateTimeOffset(1994, 11, 6, 8, 49, 37, TimeSpan.Zero), headers.IfModifiedSince);
- }
-
- [TestMethod]
- public void IfModifiedSince_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("If-Modified-Since", " Sun, 06 Nov 1994 08:49:37 GMT ,");
- Assert.IsNull(headers.GetParsedValues("If-Modified-Since"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("If-Modified-Since").Count(), "Store value count");
- Assert.AreEqual(" Sun, 06 Nov 1994 08:49:37 GMT ,", headers.GetValues("If-Modified-Since").First(),
- "Store value");
-
- headers.Clear();
- headers.AddWithoutValidation("If-Modified-Since", " Sun, 06 Nov ");
- Assert.IsNull(headers.GetParsedValues("If-Modified-Since"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("If-Modified-Since").Count(), "Store value count");
- Assert.AreEqual(" Sun, 06 Nov ", headers.GetValues("If-Modified-Since").First(), "Store value");
- }
-
- [TestMethod]
- public void IfUnmodifiedSince_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.IsNull(headers.IfUnmodifiedSince, "Host should be null by default.");
-
- DateTimeOffset expected = DateTimeOffset.Now;
- headers.IfUnmodifiedSince = expected;
- Assert.AreEqual(expected, headers.IfUnmodifiedSince);
-
- headers.IfUnmodifiedSince = null;
- Assert.IsNull(headers.IfUnmodifiedSince, "IfUnmodifiedSince should be null after setting it to null.");
- Assert.IsFalse(headers.Contains("If-Unmodified-Since"),
- "Header store should not contain a header 'IfUnmodifiedSince' after setting it to null.");
- }
-
- [TestMethod]
- public void IfUnmodifiedSince_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("If-Unmodified-Since", " Sun, 06 Nov 1994 08:49:37 GMT ");
- Assert.AreEqual(new DateTimeOffset(1994, 11, 6, 8, 49, 37, TimeSpan.Zero), headers.IfUnmodifiedSince);
-
- headers.Clear();
- headers.AddWithoutValidation("If-Unmodified-Since", "Sun, 06 Nov 1994 08:49:37 GMT");
- Assert.AreEqual(new DateTimeOffset(1994, 11, 6, 8, 49, 37, TimeSpan.Zero), headers.IfUnmodifiedSince);
- }
-
- [TestMethod]
- public void IfUnmodifiedSince_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("If-Unmodified-Since", " Sun, 06 Nov 1994 08:49:37 GMT ,");
- Assert.IsNull(headers.GetParsedValues("If-Unmodified-Since"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("If-Unmodified-Since").Count(), "Store value count");
- Assert.AreEqual(" Sun, 06 Nov 1994 08:49:37 GMT ,", headers.GetValues("If-Unmodified-Since").First(),
- "Store value");
-
- headers.Clear();
- headers.AddWithoutValidation("If-Unmodified-Since", " Sun, 06 Nov ");
- Assert.IsNull(headers.GetParsedValues("If-Unmodified-Since"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("If-Unmodified-Since").Count(), "Store value count");
- Assert.AreEqual(" Sun, 06 Nov ", headers.GetValues("If-Unmodified-Since").First(), "Store value");
- }
-
- [TestMethod]
- public void Referrer_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.IsNull(headers.Referrer, "Host should be null by default.");
-
- Uri expected = new Uri("http://example.com/path/");
- headers.Referrer = expected;
- Assert.AreEqual(expected, headers.Referrer);
-
- headers.Referrer = null;
- Assert.IsNull(headers.Referrer, "Referrer should be null after setting it to null.");
- Assert.IsFalse(headers.Contains("Referer"),
- "Header store should not contain a header 'Referrer' after setting it to null.");
- }
-
- [TestMethod]
- public void Referrer_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Referer", " http://www.example.com/path/?q=v ");
- Assert.AreEqual(new Uri("http://www.example.com/path/?q=v"), headers.Referrer);
-
- headers.Clear();
- headers.AddWithoutValidation("Referer", "/relative/uri/");
- Assert.AreEqual(new Uri("/relative/uri/", UriKind.Relative), headers.Referrer);
- }
-
- [TestMethod]
- public void Referrer_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("Referer", " http://example.com http://other");
- Assert.IsNull(headers.GetParsedValues("Referer"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("Referer").Count(), "Store value count");
- Assert.AreEqual(" http://example.com http://other", headers.GetValues("Referer").First(), "Store value");
-
- headers.Clear();
- headers.AddWithoutValidation("Referer", "http://host /other");
- Assert.IsNull(headers.GetParsedValues("Referer"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("Referer").Count(), "Store value count");
- Assert.AreEqual("http://host /other", headers.GetValues("Referer").First(), "Store value");
- }
-
- [TestMethod]
- public void MaxForwards_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.IsNull(headers.MaxForwards, "Host should be null by default.");
-
- headers.MaxForwards = 15;
- Assert.AreEqual(15, headers.MaxForwards);
-
- headers.MaxForwards = null;
- Assert.IsNull(headers.MaxForwards, "MaxForwards should be null after setting it to null.");
- Assert.IsFalse(headers.Contains("Max-Forwards"),
- "Header store should not contain a header 'MaxForwards' after setting it to null.");
-
- // Make sure the header gets serialized correctly
- headers.MaxForwards = 12345;
- Assert.AreEqual("12345", headers.GetValues("Max-Forwards").First(), "Serialized header");
- }
-
- [TestMethod]
- public void MaxForwards_UseAddMethod_AddedValueCanBeRetrievedUsingProperty()
- {
- headers.AddWithoutValidation("Max-Forwards", " 00123 ");
- Assert.AreEqual(123, headers.MaxForwards);
-
- headers.Clear();
- headers.AddWithoutValidation("Max-Forwards", "0");
- Assert.AreEqual(0, headers.MaxForwards);
- }
-
- [TestMethod]
- public void MaxForwards_UseAddMethodWithInvalidValue_InvalidValueRecognized()
- {
- headers.AddWithoutValidation("Max-Forwards", "15,");
- Assert.IsNull(headers.GetParsedValues("Max-Forwards"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("Max-Forwards").Count(), "Store value count");
- Assert.AreEqual("15,", headers.GetValues("Max-Forwards").First(), "Store value");
-
- headers.Clear();
- headers.AddWithoutValidation("Max-Forwards", "1.0");
- Assert.IsNull(headers.GetParsedValues("Max-Forwards"), "Parsed value.");
- Assert.AreEqual(1, headers.GetValues("Max-Forwards").Count(), "Store value count");
- Assert.AreEqual("1.0", headers.GetValues("Max-Forwards").First(), "Store value");
- }
-
- #endregion
-
- #region General headers
-
- [TestMethod]
- public void Connection_AddClose_Success()
- {
- headers.Connection.Add("CLOSE"); // use non-default casing to make sure we do case-insensitive comparison.
- Assert.IsTrue(headers.ConnectionClose == true);
- Assert.AreEqual(1, headers.Connection.Count);
- }
-
- [TestMethod]
- public void Connection_ReadAndWriteProperty_ValueMatchesPriorSetValue()
- {
- Assert.AreEqual(0, headers.Connection.Count, "Collection expected to be empty on first call.");
- Assert.IsNull(headers.ConnectionClose, "ConnectionClose should be null by default.");
-
- headers.Connection.Add("custom1");
- headers.Connection.Add("custom2");
- headers.ConnectionClose = true;
-
- // Connection collection has 2 values plus 'close'
- Assert.AreEqual(3, headers.Connection.Count, "Connection.Count");
- Assert.AreEqual(3, headers.GetValues("Connection").Count(), "Connection header value count.");
- Assert.IsTrue(headers.ConnectionClose == true, "ConnectionClose");
-
- Assert.AreEqual("custom1", headers.Connection.ElementAt(0), "Connection[0]");
- Assert.AreEqual("custom2", headers.Connection.ElementAt(1), "Connection[1]");
-
- // Remove 'close' value from store. But leave other 'Connection' values.
- headers.ConnectionClose = false;
- Assert.IsTrue(headers.ConnectionClose == false, "ConnectionClose == false");
- …
Large files files are truncated, but you can click here to view the full file