public void Headers_TransferEncodingChunked() { HttpResponseMessage message = new HttpResponseMessage(); HttpResponseHeaders headers = message.Headers; Assert.IsNull(headers.TransferEncodingChunked, "#1"); headers.TransferEncodingChunked = false; Assert.IsFalse(headers.TransferEncodingChunked.Value, "#2"); headers.Clear(); headers.TransferEncodingChunked = true; Assert.IsTrue(headers.TransferEncodingChunked.Value, "#3"); Assert.AreEqual(1, headers.TransferEncoding.Count, "#3b"); headers.Clear(); headers.AddWithoutValidation("Transfer-Encoding", "value"); Assert.AreEqual(false, headers.TransferEncodingChunked, "#4"); headers.Clear(); headers.AddWithoutValidation("Transfer-Encoding", "chunked"); Assert.AreEqual(true, headers.TransferEncodingChunked, "#5"); message = new HttpResponseMessage(); headers = message.Headers; headers.AddWithoutValidation("Transfer-Encoding", "ß"); Assert.IsNull(headers.TransferEncodingChunked, "#6"); }
public void Headers_TransferEncoding() { HttpResponseMessage message = new HttpResponseMessage(); HttpResponseHeaders headers = message.Headers; headers.AddWithoutValidation("Transfer-Encoding", "mmm"); headers.AddWithoutValidation("Transfer-Encoding", "▀"); headers.AddWithoutValidation("Transfer-Encoding", "zz"); var a = headers.TransferEncoding; Assert.AreEqual(2, a.Count, "#1"); Assert.AreEqual("mmm, zz, ▀", a.ToString()); }
public void Headers_Location() { HttpResponseMessage message = new HttpResponseMessage(); HttpResponseHeaders headers = message.Headers; headers.AddWithoutValidation("location", "http://w3.org"); Assert.AreEqual(new Uri("http://w3.org"), headers.Location); }
public void Headers_Request() { HttpResponseMessage message = new HttpResponseMessage(); HttpResponseHeaders headers = message.Headers; headers.Add("accept", "audio"); Assert.AreEqual("audio", headers.GetValues("Accept").First(), "#1"); headers.Clear(); headers.AddWithoutValidation("accept", "audio"); Assert.AreEqual("audio", headers.GetValues("Accept").First(), "#2"); }
public void Header_BaseImplementation() { HttpResponseMessage message = new HttpResponseMessage(); HttpResponseHeaders headers = message.Headers; headers.Add("a", "a-value"); headers.Add("b", new List <string> { "v1", "v2" }); headers.Add("c", null as string); headers.Add("d", new string[0]); headers.AddWithoutValidation("cache-control", "audio"); Assert.IsFalse(headers.Contains("nn"), "#1a"); Assert.IsTrue(headers.Contains("b"), "#1b"); var values = headers.GetValues("b").ToList(); Assert.AreEqual("v1", values[0], "#2a"); Assert.AreEqual("v2", values[1], "#2b"); Assert.IsFalse(headers.Remove("p"), "#3a"); Assert.IsTrue(headers.Remove("b"), "#3b"); Assert.IsFalse(headers.Contains("b"), "#3b-c"); IEnumerable <string> values2; Assert.IsTrue(headers.TryGetValues("c", out values2)); values = values2.ToList(); Assert.AreEqual("", values[0], "#4a"); int counter = 0; foreach (var i in headers) { ++counter; } Assert.AreEqual(3, counter, "#5"); headers.Clear(); }
public void Headers_Invalid() { HttpResponseMessage message = new HttpResponseMessage(); HttpResponseHeaders headers = message.Headers; try { headers.Add("age", ""); Assert.Fail("#1"); } catch (FormatException) { } try { headers.Add(null, ""); Assert.Fail("#2"); } catch (ArgumentException) { } try { headers.Add("mm", null as IEnumerable <string>); Assert.Fail("#2b"); } catch (ArgumentNullException) { } try { headers.Add("accept", "audio"); Assert.Fail("#2c"); } catch (InvalidOperationException) { } try { headers.AddWithoutValidation("Max-Forwards", ""); Assert.Fail("#3"); } catch (InvalidOperationException) { } try { headers.AddWithoutValidation(null, ""); Assert.Fail("#4"); } catch (ArgumentException) { } try { headers.Contains(null); Assert.Fail("#5"); } catch (ArgumentException) { } try { headers.GetValues(null); Assert.Fail("#6a"); } catch (ArgumentException) { } try { headers.GetValues("bbbb"); Assert.Fail("#6b"); } catch (InvalidOperationException) { } try { headers.Add("location", new[] { "google.com", "xamarin.com" }); Assert.Fail("#7a"); } catch (FormatException) { } headers.AddWithoutValidation("location", "*****@*****.**"); try { headers.Add("location", "w3.org"); Assert.Fail("#7b"); } catch (FormatException) { } }