コード例 #1
0
        private MFTestResults SetCommonHttpResponseHeaders_1_0(ref System.Net.WebHeaderCollection wrs)
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("Set Response Headers Properties");
                wrs.Set(HttpKnownHeaderNames.Allow.ToString(), "GET");
                wrs.Set(HttpKnownHeaderNames.ContentEncoding.ToString(), "gzip");
                wrs.Set(HttpKnownHeaderNames.ContentLength.ToString(), "26012");
                wrs.Set(HttpKnownHeaderNames.ContentType.ToString(), "text/plain, image/gif");
                wrs.Set(HttpKnownHeaderNames.Expires.ToString(), "Thu, 01 Dec 1994 16:00:00 GMT");  //always force client cache validate on the request
                wrs.Set(HttpKnownHeaderNames.KeepAlive.ToString(), "");
                wrs.Set(HttpKnownHeaderNames.LastModified.ToString(), "Fri, 22 May 2009 12:43:31 GMT");
                wrs.Set(HttpKnownHeaderNames.Location.ToString(), "http://www.w3.org/pub/WWW/People.html");
                wrs.Set(HttpKnownHeaderNames.WWWAuthenticate.ToString(), "BASIC realm=\"executives\"");
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                {
                    result = MFTestResults.Fail;
                }
            }

            return(result);
        }
コード例 #2
0
        private bool VerifyAddHeaderIsIllegal(WebHeaderCollection wrc, string header, string content, Type exceptionType)
        {
            bool res = true;

            try
            {
                Log.Comment("Set Headers Properties for header: '" + header + "', with value: '" + content + "'");

                if (null == content)
                {
                    wrc.Add(header);
                }
                else
                {
                    wrc.Add(header, content);
                }

                Log.Comment("Illegal header was set:  Failed.");
                res = false;
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, exceptionType))
                {
                    res = false;
                }
            }

            return(res);
        }
コード例 #3
0
        public MFTestResults ConstructorTestsEmptyArgs()
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("Create string request");
                string URL = "";
                try
                {
                    HttpWebRequest strRequest = (HttpWebRequest)HttpWebRequest.Create(URL);
                    Log.Exception("Expected ArgumentException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.KnownFailure;
            }
            return(result);
        }
コード例 #4
0
        private MFTestResults VerifyHttpResponseHeaders(System.Net.WebHeaderCollection wrc, System.Net.WebHeaderCollection wrs)
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                string[] headers = wrc.AllKeys;
                string   sValue  = String.Empty;

                for (int i = 0; i < wrc.Count; i++)
                {
                    sValue = wrc[headers[i]];
                    if (sValue != wrs[headers[i]])
                    {
                        Log.Exception(headers[i] + "property value is incorrect.");
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                {
                    result = MFTestResults.Fail;
                }
            }

            return(result);
        }
コード例 #5
0
        public MFTestResults ProtocolVersion()
        {
            MFTestResults  result = MFTestResults.Pass;
            HttpWebRequest wr     = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);

            try
            {
                Log.Comment("Initial version: " + wr.ProtocolVersion);

                Log.Comment("Set Version 1.0");
                wr.ProtocolVersion = new Version(1, 0);
                if (wr.ProtocolVersion.Major != 1 && wr.ProtocolVersion.Minor != 0)
                {
                    Log.Exception("Expected version 1.0, but got " + wr.ProtocolVersion.ToString());
                    result = MFTestResults.Fail;
                }

                Log.Comment("Set Version 1.1");
                wr.ProtocolVersion = new Version(1, 1);
                if (wr.ProtocolVersion.Major != 1 && wr.ProtocolVersion.Minor != 1)
                {
                    Log.Exception("Expected version 1.0, but got " + wr.ProtocolVersion.ToString());
                    result = MFTestResults.Fail;
                }

                Log.Comment("Set Invalid Version 3.7");
                try
                {
                    wr.ProtocolVersion = new Version(3, 7);
                    Log.Exception("Expected Argument Exception");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }
コード例 #6
0
        private MFTestResults SetCommonHttpResponseHeaders(ref System.Net.WebHeaderCollection wrs)
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("Set Response Headers Properties");
                wrs.Set(HttpKnownHeaderNames.AcceptRanges.ToString(), "bytes");
                wrs.Set(HttpKnownHeaderNames.Age.ToString(), "0");
                wrs.Set(HttpKnownHeaderNames.Allow.ToString(), "GET, PUT");
                wrs.Set(HttpKnownHeaderNames.CacheControl.ToString(), "no-cache"); //Force intermediate caches to validate their copies directly with the origin server.
                wrs.Set(HttpKnownHeaderNames.Connection.ToString(), "close");
                wrs.Set(HttpKnownHeaderNames.ContentEncoding.ToString(), "gzip");
                wrs.Set(HttpKnownHeaderNames.ContentLanguage.ToString(), "mi, en");
                wrs.Set(HttpKnownHeaderNames.ContentLength.ToString(), "26012");
                wrs.Set(HttpKnownHeaderNames.ContentLocation.ToString(), "");
                wrs.Set(HttpKnownHeaderNames.ContentMD5.ToString(), "60e985979f1d55ab7542440fbb9659e5");
                wrs.Set(HttpKnownHeaderNames.ContentRange.ToString(), "bytes 21010-47021/47022");
                wrs.Set(HttpKnownHeaderNames.ContentType.ToString(), "text/plain, image/gif");
                wrs.Set(HttpKnownHeaderNames.Date.ToString(), System.DateTime.Today.ToString());
                wrs.Set(HttpKnownHeaderNames.ETag.ToString(), "W/");
                wrs.Set(HttpKnownHeaderNames.Expires.ToString(), "Thu, 01 Dec 1994 16:00:00 GMT");  //always force client cache validate on the request
                wrs.Set(HttpKnownHeaderNames.KeepAlive.ToString(), "");
                wrs.Set(HttpKnownHeaderNames.LastModified.ToString(), "Fri, 22 May 2009 12:43:31 GMT");
                wrs.Set(HttpKnownHeaderNames.Location.ToString(), "http://www.w3.org/pub/WWW/People.html");
                wrs.Set(HttpKnownHeaderNames.Pragma.ToString(), "no-cache");
                wrs.Set(HttpKnownHeaderNames.ProxyAuthenticate.ToString(), "NNNNNNNNNNNNNNNNN==");
                wrs.Set(HttpKnownHeaderNames.RetryAfter.ToString(), "120");
                wrs.Set(HttpKnownHeaderNames.SetCookie.ToString(), "http://www.w3.org/hypertext/DataSources/Overview.html");
                wrs.Set(HttpKnownHeaderNames.Trailer.ToString(), "Test Code");
                wrs.Set(HttpKnownHeaderNames.TransferEncoding.ToString(), "8BIT");
                wrs.Set(HttpKnownHeaderNames.Upgrade.ToString(), "HTTP/2.0, SHTTP/1.3");
                wrs.Set(HttpKnownHeaderNames.Vary.ToString(), "TestVary");
                wrs.Set(HttpKnownHeaderNames.Via.ToString(), "1.0 fred, 1.1 nowhere.com (Apache/1.1)");
                wrs.Set(HttpKnownHeaderNames.Warning.ToString(), "TestWarning");
                wrs.Set(HttpKnownHeaderNames.WWWAuthenticate.ToString(), "BASIC realm=\"executives\"");
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                {
                    result = MFTestResults.Fail;
                }
            }

            return(result);
        }
コード例 #7
0
        private bool TestCheckBadHeaders(string value)
        {
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);;

            try
            {
                wr.Headers.Add("Test", value);
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #8
0
        public MFTestResults InvalidConstructorTests()
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("null string");
                string nullString = null;
                try { WebRequest nsWR = WebRequest.Create(nullString); }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("null uri");
                Uri nullUri = null;
                try { WebRequest nuWr = WebRequest.Create(nullUri); }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("invalud URI type");
                try { WebRequest inWr = WebRequest.Create("ftp://ftp.microsoft.com"); }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(NotSupportedException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }
コード例 #9
0
        public MFTestResults RelativeURI()
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("relative url");
                uri = new Uri("/doc/text.html", UriKind.Relative);

                Log.Comment("absolute url");
                props = new UriProperties("https", "www.microsoft.com")
                {
                    Path = "/doc/text.html",
                    Port = 1443
                };
                uri = new Uri(props.OriginalUri, UriKind.Absolute);
                if (!ValidUri(uri, props))
                {
                    result = MFTestResults.Fail;
                }

                Log.Comment("RelativeOrAbsolute");
                try { uri = new Uri("/doc/text.html", UriKind.RelativeOrAbsolute); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }
コード例 #10
0
        private MFTestResults Verify(System.Net.WebHeaderCollection wrc, System.Net.WebHeaderCollection RequestHeaders)
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("Get Headers - User-Agent");
                if (wrc["User-Agent"] != RequestHeaders["User-Agent"])
                {
                    Log.Exception("User-Agent property value is incorrect.");
                    result = MFTestResults.Fail;
                }

                Log.Comment("Get Headers - Connection");
                if (wrc["Connection"] != RequestHeaders["Connection"])
                {
                    Log.Exception("Connection property value is incorrect.");
                    result = MFTestResults.Fail;
                }

                Log.Comment("Get Headers - Host");
                if (wrc["Host"] != RequestHeaders["Host"])
                {
                    Log.Exception("Host property value is incorrect.");
                    result = MFTestResults.Fail;
                }
            }
            catch (Exception ex)
            {
                if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                {
                    result = MFTestResults.Fail;
                }
            }

            return(result);
        }
コード例 #11
0
        public MFTestResults ContentLengthHeader()
        {
            MFTestResults  result = MFTestResults.Pass;
            HttpWebRequest wr     = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);;

            try
            {
                Log.Comment("negative value should throw");
                try
                {
                    wr.ContentLength = -1;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentOutOfRangeException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                wr.ContentLength = 1234567;
                if (wr.ContentLength != 1234567)
                {
                    Log.Exception("Expected ContentLength 1234567, but got " + wr.ContentLength);
                    result = MFTestResults.Fail;
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }
コード例 #12
0
        private MFTestResults VerifyStream(HttpWebResponse response, HttpServer server)
        {
            MFTestResults result = MFTestResults.Pass;

            using (System.IO.Stream responseStream = response.GetResponseStream())
            {
                if (responseStream != null)
                {
                    string page = HttpTests.ReadStream("Client", responseStream);
                    if (page != server.ResponseString)
                    {
                        Log.Exception("Expect " + server.ResponseString + " but get " + responseStream.ToString());
                        result = MFTestResults.Fail;
                    }
                }
                else
                {
                    result = MFTestResults.Fail;
                    Log.Exception("[Client] Expected stream, but got null");
                }
            }

            return(result);
        }
コード例 #13
0
        public MFTestResults FunctionalChunkTests()
        {
            MFTestResults  result = MFTestResults.Pass;
            HttpWebRequest wr     = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpTestServer.s_CurrentPort.ToString() + "/");

            wr.UserAgent = ".Net Micro Framwork Device/4.0";
            wr.KeepAlive = true;
            HttpTestServer server = new HttpTestServer("http", ref result)
            {
                RequestUri     = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = MFUtilities.GetRandomSafeString(5000),
            };

            try
            {
                // Setup server
                server.StartServer();

                Log.Comment("Send UnChunked");
                wr.SendChunked = false;
                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                HttpTests.PrintHeaders("Client", response.Headers);
                using (Stream responseStream = response.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        string page = HttpTests.ReadStream("Client", responseStream);
                        if (page != server.ResponseString)
                        {
                            result = MFTestResults.Fail;
                            Log.Exception("[Client] Send UnChunked - Corrupt Page!");
                            Log.Exception("[Client] Expected: " + server.ResponseString);
                            Log.Exception("[Client] Received: " + page);
                        }
                    }
                    else
                    {
                        result = MFTestResults.Fail;
                        Log.Exception("[Client] Expected stream, but got null");
                    }
                }

                Log.Comment("Send Chunked");
                wr                    = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpTestServer.s_CurrentPort.ToString() + "/");
                wr.UserAgent          = ".Net Micro Framwork Device/4.0";
                wr.SendChunked        = true;
                server.SendChunked    = true;
                server.RequestHeaders = wr.Headers;
                response              = (HttpWebResponse)wr.GetResponse();
                HttpTests.PrintHeaders("Client", response.Headers);
                using (Stream responseStream = response.GetResponseStream())
                {
                    if (responseStream != null)
                    {
                        string page = HttpTests.ReadStream("Client", responseStream);
                        if (page != server.ResponseString)
                        {
                            result = MFTestResults.Fail;
                            Log.Exception("[Client] Send Chunked - Corrupt Page!");
                            Log.Exception("[Client] Expected: " + server.ResponseString);
                            Log.Exception("[Client] Received: " + page);
                        }
                    }
                    else
                    {
                        result = MFTestResults.Fail;
                        Log.Exception("[Client] Expected stream, but got null");
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                // Stop server
                server.StopServer();
            }
            return(result);
        }
コード例 #14
0
        private void RunServer()
        {
            try
            {
                running = true;

                if (serverPrefix == "https")
                {
                    if (Microsoft.SPOT.Hardware.SystemInfo.SystemID.SKU == 3)
                    {
                        listener.HttpsCert = new X509Certificate(m_emulatorCertData, "NetMF");
                    }
                    else
                    {
                        //string serverCertAsString = HttpServer.Resource1.GetString(HttpServer.Resource1.StringResources.cert_device_microsoft_com);
                        //byte[] serverCertAsArray = System.Text.Encoding.UTF8.GetBytes(serverCertAsString);
                        //listener.HttpsCert = new X509Certificate(serverCertAsArray);
                    }
                }

                listener.Start();
                Log.Comment("[Server] Starting listener...");

                evtStarted.Set();

                while (running)
                {
                    HttpListenerContext context = listener.GetContext();
                    if (context == null)
                    {
                        continue;
                    }

                    HttpListenerRequest request = context.Request;

                    HttpTests.PrintHeaders("Server Received request: ", request.Headers);

                    HttpListenerResponse listenerResponse = context.Response;
                    listenerResponse.KeepAlive = false;

                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(this.ResponseString);

                    switch (request.HttpMethod.ToUpper())
                    {
                    case "GET": ProcessClientGetRequest(context); break;

                    case "POST": ProcessClientPostRequest(context); break;

                    case "HEAD": ProcessException(context, this); break;
                    }

                    listenerResponse.OutputStream.Write(buffer, 0, buffer.Length);
                    listenerResponse.Close();
                }
            }
            catch (ThreadAbortException)
            {
            }
            catch (WebException wex)
            {
                Log.Exception("Server throw exception:  ", wex);
                return;
            }
            catch (Exception ex)
            {
                Log.Exception("[Server] Unexpected Server Exception", ex);
            }
            finally
            {
                if (running)
                {
                    listener.Stop();
                }
            }
        }
コード例 #15
0
        private void RunServer()
        {
            try
            {
                running = true;
                listener.Start();
                Log.Comment("[Server] Starting listener...");

                evtStarted.Set();

                while (running)
                {
                    HttpListenerContext context = listener.GetContext();
                    if (context == null)
                    {
                        continue;
                    }

                    HttpListenerRequest request = context.Request;

                    // request header validation
                    if (this.RequestHeaders != null)
                    {
                        foreach (string header in this.RequestHeaders.AllKeys)
                        {
                            if (this.RequestHeaders[header] != request.Headers[header])
                            {
                                this.result = MFTestResults.Fail;
                                Log.Exception("[Server] Expected " + header + ":" + this.RequestHeaders[header] +
                                              ", but got " + header + ":" + request.Headers[header]);
                            }
                        }
                    }

                    HttpTests.PrintHeaders("Server", request.Headers);
                    // BUGBUG: Check inbound stream once 54503 & 54507 are fixed
                    //HttpTests.ReadStream("Client", request.InputStream);

                    HttpListenerResponse response = context.Response;
                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(this.ResponseString);
                    response.Headers.Add("Server", ".Net Micro Framework Device/4.0");
                    response.SendChunked = this.SendChunked;
                    if (!this.SendChunked)
                    {
                        response.ContentLength64 = buffer.Length;
                    }

                    response.OutputStream.Write(buffer, 0, buffer.Length);
                    response.Close();
                }
                listener.Stop();
            }
            catch (Exception ex)
            {
                Log.Exception("[Server] Unexpected Server Exception", ex);
            }
            finally
            {
                if (listener.IsListening)
                {
                    listener.Abort();
                }

                running = false;
            }
        }
コード例 #16
0
        public MFTestResults InvalidConstructorTests()
        {
            MFTestResults result = MFTestResults.Pass;

            try
            {
                Log.Comment("null string constructor");
                try { uri = new Uri(null); }
                catch (ArgumentNullException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("no uri string");
                try { uri = new Uri("foo"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("uri, no address");
                try { uri = new Uri("http:"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("uri, starts with non-alpha");
                try { uri = new Uri("1ttp://foo.com"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("uri, includes numeric");
                try { uri = new Uri("h1tp://foo.com"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("uri, includes non-alpha");
                try { uri = new Uri("h@tp://foo.com"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("No ABSPath port URI");
                try { uri = new Uri(HttpTests.MSUrl + ":80"); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("Empty string constructor");
                try { uri = new Uri(""); }
                catch (ArgumentException ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }
コード例 #17
0
        public MFTestResults AddRangeInvalidTests()
        {
            MFTestResults  result = MFTestResults.Pass;
            HttpWebRequest wr;

            try
            {
                Log.Comment("invalid from - AddRange(-1, 500)");
                wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);
                try
                {
                    wr.AddRange(-1, 500);
                    Log.Exception("Expected ArgumentOutOfRangeException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentOutOfRangeException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("invalid from - AddRange(1, -500)");
                wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);
                try
                {
                    wr.AddRange(1, -500);
                    Log.Exception("Expected ArgumentOutOfRangeException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentOutOfRangeException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("invalid specifier - AddRange(null, 500)");
                wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);
                try
                {
                    wr.AddRange(null, 500);
                    Log.Exception("Expected ArgumentNullException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                Log.Comment("invalid specifier - AddRange(null, 1, 500)");
                wr = (HttpWebRequest)WebRequest.Create(HttpTests.MSUrl);
                try
                {
                    wr.AddRange(null, 1, 500);
                    Log.Exception("Expected ArgumentNullException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    /* pass case */
                    if (!HttpTests.ValidateException(ex, typeof(ArgumentNullException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return(result);
        }
コード例 #18
0
        public MFTestResults SetHeadersAfterRequest()
        {
            MFTestResults  result = MFTestResults.Pass;
            HttpWebRequest wr     = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpTestServer.s_CurrentPort.ToString() + "/");

            wr.UserAgent = ".Net Micro Framwork Device/4.0";
            HttpTestServer server = new HttpTestServer("http", ref result)
            {
                RequestUri     = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>SetHeadersAfterRequest</body></html>"
            };

            try
            {
                // Setup server
                server.StartServer();
                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                // Tests
                try
                {
                    Log.Comment("ReadWriteTimeout");
                    wr.ReadWriteTimeout = 10;
                    Log.Exception("[Client] Expected InvalidOperationException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                try
                {
                    Log.Comment("ContentLength");
                    wr.ContentLength = 10;
                    Log.Exception("[Client] Expected InvalidOperationException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                try
                {
                    Log.Comment("Headers");
                    wr.Headers = new WebHeaderCollection();
                    Log.Exception("[Client] Expected InvalidOperationException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                try
                {
                    Log.Comment("Proxy");
                    wr.Proxy = null;
                    Log.Exception("[Client] Expected InvalidOperationException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }

                try
                {
                    Log.Comment("SendChunked");
                    wr.SendChunked = true;
                    Log.Exception("[Client] Expected InvalidOperationException");
                    result = MFTestResults.Fail;
                }
                catch (Exception ex)
                {
                    if (!HttpTests.ValidateException(ex, typeof(InvalidOperationException)))
                    {
                        result = MFTestResults.Fail;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                // Stop server
                server.StopServer();
            }

            return(result);
        }