public void RemoveTakesHeadersOutOfDictionary() { IDictionary <string, StringValues> headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); StringValues value; Assert.Equal(2, headers.Count); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); Assert.True(headers.Remove("host")); Assert.False(headers.Remove("host")); Assert.Equal(1, headers.Count); Assert.False(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); Assert.True(headers.Remove("custom")); Assert.False(headers.Remove("custom")); Assert.Equal(0, headers.Count); Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); }
public void CopyToMovesDataIntoArray() { IDictionary <string, StringValues> headers = new FrameRequestHeaders(); headers.Add("host", new[] { "localhost" }); headers.Add("Content-Length", new[] { "0" }); headers.Add("custom", new[] { "value" }); var entries = new KeyValuePair <string, StringValues> [5]; headers.CopyTo(entries, 1); Assert.Null(entries[0].Key); Assert.Equal(new StringValues(), entries[0].Value); Assert.Equal("Host", entries[1].Key); Assert.Equal(new[] { "localhost" }, entries[1].Value); Assert.Equal("Content-Length", entries[2].Key); Assert.Equal(new[] { "0" }, entries[2].Value); Assert.Equal("custom", entries[3].Key); Assert.Equal(new[] { "value" }, entries[3].Value); Assert.Null(entries[4].Key); Assert.Equal(new StringValues(), entries[4].Value); }
public void AddWorksLikeSetAndThrowsIfKeyExists() { IDictionary <string, StringValues> headers = new FrameRequestHeaders(); StringValues value; Assert.False(headers.TryGetValue("host", out value)); Assert.False(headers.TryGetValue("custom", out value)); headers.Add("host", new[] { "localhost" }); headers.Add("custom", new[] { "value" }); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); Assert.Throws <ArgumentException>(() => headers.Add("host", new[] { "localhost" })); Assert.Throws <ArgumentException>(() => headers.Add("custom", new[] { "value" })); Assert.True(headers.TryGetValue("host", out value)); Assert.True(headers.TryGetValue("custom", out value)); }
public void ClearRemovesAllHeaders() { IDictionary <string, StringValues> headers = new FrameRequestHeaders(); 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)); }