public void opImplicit_HttpHeaderCollection_stringEmpty()
        {
            var expected = new HttpHeaderCollection();
            HttpHeaderCollection actual = string.Empty;

            Assert.Equal(expected, actual);
        }
        public void op_FromString_stringEmpty()
        {
            var expected = new HttpHeaderCollection();
            var actual   = HttpHeaderCollection.FromString(string.Empty);

            Assert.Equal(expected, actual);
        }
Ejemplo n.º 3
0
        public static HttpHeaderCollection FromString(string value)
        {
            if (null == value)
            {
                throw new ArgumentNullException("value");
            }

            var result = new HttpHeaderCollection();

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Write(value);
                    writer.Flush();
                    stream.Position = 0;
                    using (var reader = new StreamReader(stream))
                    {
                        result.Read(reader);
                    }
                }
            }

            return(result);
        }
        public void op_Equals_object()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "value")
            };

            Assert.True(HttpHeaderCollection.FromString("name: value").Equals(obj));
        }
        public void op_Contains_IHttpHeader_whenFalse()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "foo")
            };

            Assert.False(obj.Contains(new HttpHeader("name", "bar")));
        }
        public void op_Contains_IHttpHeaderNull()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "value")
            };

            Assert.False(obj.Contains(null));
        }
        public void op_ContainsName_Token_whenFalse()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("foo", "value")
            };

            Assert.False(obj.ContainsName("bar"));
        }
        public void op_ContainsName_TokenNull()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "foo")
            };

            Assert.Throws <ArgumentNullException>(() => obj.ContainsName(null as string));
        }
        public void opIndexer_string()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "value")
            };

            Assert.Equal("value", obj["name"]);
        }
        public void prop_ContentType_get()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("Content-Type", "text/plain")
            };

            Assert.Equal("text/plain", obj.ContentType.MediaType);
        }
        public void op_Contains_IHttpHeader_whenTrue()
        {
            var item = new HttpHeader("name", "value");
            var obj  = new HttpHeaderCollection
            {
                item
            };

            Assert.True(obj.Contains(item));
        }
        public void op_Equals_object_whenMultiple()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "foo"),
                new HttpHeader("name", "bar")
            };

            Assert.True(HttpHeaderCollection.FromString("name: foo, bar").Equals(obj));
        }
        public void opImplicit_HttpHeaderCollection_string()
        {
            var expected = new HttpHeaderCollection
            {
                new HttpHeader("name", "value")
            };
            HttpHeaderCollection actual = "name: value";

            Assert.Equal(expected, actual);
        }
        public void op_FromString_string_withLeadingWhiteSpace()
        {
            var expected = new HttpHeaderCollection
            {
                new HttpHeader("name", "value")
            };
            var actual = HttpHeaderCollection.FromString("name:         value");

            Assert.Equal(expected, actual);
        }
        public void opIndexer_string_whenMultiple()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "foo"),
                new HttpHeader("name", "bar")
            };

            Assert.Equal("foo, bar", obj["name"]);
        }
        public void op_Add_IHttpHeader()
        {
            var obj  = new HttpHeaderCollection();
            var item = new HttpHeader("name", "value");

            Assert.Equal(0, obj.Count);

            obj.Add(item);

            Assert.Equal(1, obj.Count);
        }
        public void op_Remove_IHttpHeader()
        {
            var item = new HttpHeader("name", "value");
            var obj  = new HttpHeaderCollection
            {
                item
            };

            obj.Remove(item);

            Assert.Equal(0, obj.Count);
        }
        public void op_GetHashCode()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "value")
            };

            var expected = obj.ToString().GetHashCode();
            var actual   = obj.GetHashCode();

            Assert.Equal(expected, actual);
        }
        public void op_Clear()
        {
            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "value")
            };

            Assert.Equal(1, obj.Count);

            obj.Clear();

            Assert.Equal(0, obj.Count);
        }
        public void IEnumerable_op_GetEnumerator()
        {
            var item = new HttpHeader("name", "value");
            var obj  = new HttpHeaderCollection
            {
                item
            };

            var enumerator = (obj as IEnumerable).GetEnumerator();

            enumerator.MoveNext();
            Assert.Same(item, enumerator.Current);
        }
        public void op_GetEnumerator()
        {
            var item = new HttpHeader("name", "value");
            var obj  = new HttpHeaderCollection
            {
                item
            };

            using (var enumerator = obj.GetEnumerator())
            {
                enumerator.MoveNext();
                Assert.Same(item, enumerator.Current);
            }
        }
        public void op_CopyTo_IHttpHeader_int()
        {
            var item = new HttpHeader("name", "value");
            var obj  = new HttpHeaderCollection
            {
                item
            };

            var array = new IHttpHeader[1];

            obj.CopyTo(array, 0);

            Assert.Equal(item, (HttpHeader)array[0]);
        }
        public void op_FromString_string_whenMultipleLines()
        {
            var value =
                "a" + Environment.NewLine +
                ' ' + "b" + Environment.NewLine +
                '\t' + "c";

            var expected = new HttpHeaderCollection
            {
                new HttpHeader("name", value)
            };
            var actual = HttpHeaderCollection.FromString("name: " + value);

            Assert.Equal(expected, actual);
        }
        public void op_ToString()
        {
            var expected = new StringBuilder();

            expected.AppendLine("name: value");

            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "value")
            };

            var actual = obj.ToString();

            Assert.Equal(expected.ToString(), actual);
        }
        public void op_ToString_whenMultiple()
        {
            var expected = new StringBuilder();

            expected.AppendLine("name: foo, bar");

            var obj = new HttpHeaderCollection
            {
                new HttpHeader("name", "foo"),
                new HttpHeader("name", "bar")
            };

            var actual = obj.ToString();

            Assert.Equal(expected.ToString(), actual);
        }
Ejemplo n.º 26
0
        public void prop_Headers_get()
        {
            var expected = new HttpHeaderCollection();

            var mock = new Mock <IHttpMessage>();

            mock
            .SetupGet(x => x.Headers)
            .Returns(expected)
            .Verifiable();

            var actual = mock.Object.Headers;

            Assert.Same(expected, actual);

            mock.VerifyAll();
        }
        public void op_Read_TextReaderEmpty()
        {
            var obj = new HttpHeaderCollection();

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    writer.Flush();
                    stream.Position = 0;
                    using (var reader = new StreamReader(stream))
                    {
                        obj.Read(reader);
                    }
                }
            }

            Assert.Empty(obj);
        }
Ejemplo n.º 28
0
        public virtual void Read(TextReader reader)
        {
            if (null == reader)
            {
                throw new ArgumentNullException("reader");
            }

            var headers = new HttpHeaderCollection();

            headers.Read(reader);
            Headers = headers;

            var contentType = headers.ContentType;

            if (null != contentType)
            {
                Body = ToContent(
                    reader,
                    ServiceLocator.Current.GetInstance <IMediaType>(contentType.MediaType));
            }
        }
        public void op_Write_TextWriter()
        {
            var headers = new HttpHeaderCollection
            {
                new HttpHeader("Connection", "close")
            };

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    headers.Write(writer);
                    writer.Flush();
                    stream.Position = 0;
                    using (var reader = new StreamReader(stream))
                    {
                        Assert.Equal("Connection: close" + Environment.NewLine, reader.ReadToEnd());
                    }
                }
            }
        }
 public void op_FromString_stringNull()
 {
     Assert.Throws <ArgumentNullException>(() => HttpHeaderCollection.FromString(null));
 }