コード例 #1
0
        public void SimpleHttpRequestObjectWellFormed()
        {
            IHttpRequest request = new SimpleHttpRequest(
                "http://host1?a=1",
                "POST",
                "HTTP/1.1",
                "content",
                new HttpHeaders
            {
                new KeyValuePair <string, string>("User-Agent", "user agent value 1"),
                new KeyValuePair <string, string>("Cookie", "key=value"),
                new KeyValuePair <string, string>("Content-Type", "*/*"),
                new KeyValuePair <string, string>("Host", "http://host1"),
                new KeyValuePair <string, string>("header1", "value1"),
                new KeyValuePair <string, string>("header2", string.Empty)
            });

            request.RequestContent.ShouldEqual("content");
            request.RequestContentType.ShouldEqual("*/*");
            request.RequestCookies.ShouldEqual("key=value");
            request.RequestHost.ShouldEqual("http://host1");
            request.RequestHttpMethod.ShouldEqual("POST");
            request.RequestHttpVersion.ShouldEqual("HTTP/1.1");
            request.RequestUrl.ShouldEqual("http://host1?a=1");
            request.RequestUserAgent.ShouldEqual("user agent value 1");
            request.RequestHeaders.Distinct().Count().ShouldEqual(6);
            request.RequestHeaders.Single(h => h.Key.Equals("header1")).Value.ShouldEqual("value1");
            request.RequestHeaders.Single(h => h.Key.Equals("header2")).Value.ShouldEqual(string.Empty);
        }
コード例 #2
0
        public void SimpleHttpRequestObjectWithMissingHeaders()
        {
            IHttpRequest request = new SimpleHttpRequest(
                "http://host1?a=1",
                "POST",
                "HTTP/1.1",
                null,
                new HttpHeaders());

            request.RequestContent.ShouldBeNull();
            request.RequestContentType.ShouldEqual(string.Empty);
            request.RequestCookies.ShouldEqual(string.Empty);
            request.RequestHost.ShouldEqual(string.Empty);
            request.RequestHttpMethod.ShouldEqual("POST");
            request.RequestHttpVersion.ShouldEqual("HTTP/1.1");
            request.RequestUrl.ShouldEqual("http://host1?a=1");
            request.RequestUserAgent.ShouldEqual(string.Empty);
            request.RequestHeaders.Count().ShouldEqual(0);
        }