public void AddWorksLikeSetAndThrowsIfKeyExists() { IDictionary<string, StringValues> headers = new HttpRequestHeaders(); StringValues value; Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); Assert.False(headers.TryGetValue("Content-Length", out value)); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); headers.Add("Content-Length", new[] { "0" }); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); Assert.True(headers.TryGetValue("Content-Length", out value)); Assert.Throws<ArgumentException>(() => headers.Add("host", new[] { "localhost" })); Assert.Throws<ArgumentException>(() => headers.Add("custom", new[] { "value" })); Assert.Throws<ArgumentException>(() => headers.Add("Content-Length", new[] { "0" })); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); Assert.True(headers.TryGetValue("Content-Length", out value)); }
public void ClearRemovesAllHeaders() { IDictionary<string, StringValues> headers = new HttpRequestHeaders(); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); headers.Add("Content-Length", new[] { "0" }); StringValues value; Assert.Equal(3, headers.Count); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); Assert.True(headers.TryGetValue("Content-Length", out value)); headers.Clear(); Assert.Equal(0, headers.Count); Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); Assert.False(headers.TryGetValue("Content-Length", out value)); }
public void TryGetValueWorksForKnownAndUnknownHeaders() { IDictionary <string, StringValues> headers = new HttpRequestHeaders(); StringValues value; Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); Assert.False(headers.TryGetValue("Content-Length", out value)); headers["host"] = new[] { "value" }; Assert.True(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); Assert.False(headers.TryGetValue("Content-Length", out value)); headers["custom"] = new[] { "value" }; Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); Assert.False(headers.TryGetValue("Content-Length", out value)); headers["Content-Length"] = new[] { "0" }; Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); Assert.True(headers.TryGetValue("Content-Length", out value)); }