public MFTestResults NotSupportExceptionTest()
        {
            MFTestResults result = MFTestResults.Pass;
            try
            {
                Log.Comment("WebResponse Test");
                HttpWebRequest wrStr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/");

                HttpServer server = new HttpServer("http", ref result)
                {
                    RequestUri = wrStr.RequestUri,
                    RequestHeaders = wrStr.Headers,
                    ResponseString = "<html><body>WebResponse Test</body></html>"
                };

                server.StartServer();

                WebRequest wr = wrStr;

                WebResponse wresp = wr.GetResponse();

                Log.Comment("Check ResponseUri property");
                if (wresp.ResponseUri.AbsoluteUri != wr.RequestUri.AbsoluteUri)
                {
                    Log.Exception("Expected " + HttpTests.MSUrl + ", but got " + wresp.ResponseUri.AbsoluteUri);
                    result = MFTestResults.Fail;
                }

                Log.Comment("Check ContentType property");
                if (wresp.ContentType != "")
                {
                    Log.Exception("Expected: " + wr.ContentType);
                    result = MFTestResults.Fail;
                }

                Log.Comment("Invoke WebResponse.Close()");
                try
                {
                    wresp.Close();
                }
                catch (System.NotSupportedException e)
                {
                    Log.Exception("Get exception when invoke WebResponse.Close(). " + e.Message.ToString());
                    result = MFTestResults.Fail;
                }
                finally
                {
                    //Stop server
                    server.StopServer();
                }

            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }

            return result;
        }
        public MFTestResults ValidDefaultTestHTTPStatusCodeHTTP1_1()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>ValidDefaultTestHTTPStatusCodeHTTP1_1</body></html>"
            };

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

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                Log.Comment("Expect StatusCode - OK");
                if (HttpStatusCode.OK != response.StatusCode)
                {
                    Log.Exception("Expect HttpStatusCode = OK but get " + response.StatusCode);
                    result = MFTestResults.Fail;

                }

                Log.Comment("Receive " + response.StatusDescription);

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
 private MFTestResults StopServerListener(ref HttpServer server)
 {
     MFTestResults result = MFTestResults.Pass;
     HttpListener mylistener = server.Listener;
     try
     {
         mylistener.Stop();
     }
     catch (Exception ex)
     {
         Log.Exception("Exception when stop listener: " + ex.Message.ToString());
         result = MFTestResults.Fail;
     }
     return result;
 }
        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;
        }
        public MFTestResults InvalidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_1_FTP()
        {
            MFTestResults result = MFTestResults.Pass;
            UriProperties props = new UriProperties("ftp", "//ftp.microsoft.com");
            Uri uri = new Uri(props.OriginalUri);

            Log.Comment("Negative Test case 2:");
            Log.Comment("Create WebRequest with FTP uri");
            try
            {
                HttpWebRequest wrftp = (HttpWebRequest)WebRequest.Create(uri);
            }
            catch (System.NotSupportedException)
            {
                Log.Comment("Create WebRequest with FTP uri - Expected System.NotSupportedException");
            }

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://ftp.microsoft.com");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
            };

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

                System.Net.WebHeaderCollection wrc = wr.Headers;

                // Tests
                Verify(wrc, server.RequestHeaders);
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                // Stop server
                server.StopServer();
            }

            return result;
        }
예제 #6
0
        private static void ProcessException(HttpListenerContext context, HttpServer server)
        {
            HttpListenerRequest request = context.Request;
            HttpListenerResponse response = context.Response;

            string strFilePath = GetPathFromURL(request.RawUrl == null ? "" : request.RawUrl);
            // There is one particular URL that we process differently
            if (strFilePath == "\\webexception\\ConnClose.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ConnectionClosed", WebExceptionStatus.ConnectionClosed)).ToString();
            }

            if (strFilePath == "\\webexception\\KeepAliveFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("KeepAliveFailure", WebExceptionStatus.KeepAliveFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\Pending.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("Pending", WebExceptionStatus.Pending)).ToString();
            }

            if (strFilePath == "\\webexception\\PipelineFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("PipelineFailure", WebExceptionStatus.PipelineFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\ProxyNameResolutionFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ProxyNameResolutionFailure", WebExceptionStatus.ProxyNameResolutionFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\ReceiveFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ReceiveFailure", WebExceptionStatus.ReceiveFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\RequestCanceled.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("RequestCanceled", WebExceptionStatus.RequestCanceled)).ToString();
            }

            if (strFilePath == "\\webexception\\SecureChannelFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("SecureChannelFailure", WebExceptionStatus.SecureChannelFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\SendFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("SendFailure", WebExceptionStatus.SendFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\Success.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("Success", WebExceptionStatus.Success)).ToString();
            }

            if (strFilePath == "\\webexception\\Timeout.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("Timeout", WebExceptionStatus.Timeout)).ToString();
            }

            if (strFilePath == "\\webexception\\TrustFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("TrustFailure", WebExceptionStatus.TrustFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\ConnectFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ConnectFailure", WebExceptionStatus.ConnectFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\NameResolutionFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("NameResolutionFailure", WebExceptionStatus.NameResolutionFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\ProtocolError.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ProtocolError", WebExceptionStatus.ProtocolError)).ToString();
            }

            if (strFilePath == "\\webexception\\ServerProtocolViolation.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ServerProtocolViolation", WebExceptionStatus.ServerProtocolViolation)).ToString();
            }

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

            response.OutputStream.Write(buffer, 0, buffer.Length);
            return;
        }
        public MFTestResults TestWebExceptionHTTP1_1_ServerProtocolViolation()
        {
            MFTestResults result = MFTestResults.Pass;


            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://"+ Utilities.GetLocalIpAddress() + ":" + HttpServer.s_CurrentPort.ToString() + "/webexception/ServerProtocolViolation.html");  //expect ServerProtocolViolation
            wr.UserAgent = ".Net Micro Framwork Device/4.0";
            wr.Method = "HEAD";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = ""
            };

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

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                Log.Comment("Expect ServerProtocolViolation");

                VerifyStream(response, server);

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("Exception caught: ", ex);
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
        public MFTestResults TestHTTPStatusCodeHTTP1_1_RequestUriTooLong()
        {
            MFTestResults result = MFTestResults.Pass;


            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/local/webpages/mysubdir/index.html");  //expect 414 - RequestUriTooLong
            wr.UserAgent = ".Net Micro Framwork Device/4.0";
            wr.Method = "GET";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>TestHTTPStatusCodeHTTP1_1_RequestUriTooLong</body></html>"
            };

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

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                Log.Comment("Expect StatusCode - RequestUriTooLong");
                if ((int)HttpStatusCode.RequestUriTooLong != (int)response.StatusCode)
                {
                    Log.Exception("Expect HttpStatusCode = RequestUriTooLong but get " + response.StatusCode);
                    result = MFTestResults.Fail;

                }
                Log.Comment("Receive " + response.StatusDescription);
                response.Close();

            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {

                //Stop server
                server.StopServer();
            }

            return result;
        }
        public MFTestResults DefaultTestHTTPStatusCodeHTTP1_1_Unauthorized()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://"+ Utilities.GetLocalIpAddress() + ":" + HttpServer.s_CurrentPort.ToString() + "/webpages/Unauth.html");  //expect 401 - Unauthorized 
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>DefaultTestHTTPStatusCodeHTTP1_1_Unauthorized</body></html>"
            };

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

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                Log.Comment("Expect StatusCode - Unauthorized ");
                if (HttpStatusCode.Unauthorized != response.StatusCode)
                {
                    Log.Exception("Expect HttpStatusCode = Unauthorized but get " + response.StatusCode);
                    result = MFTestResults.Fail;

                }

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
        public MFTestResults DefaultTestHTTPStatusCodeHTTP1_1_NotExistUriPath()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/webpages/NotExistUriPath.html");      
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>DefaultTestHTTPStatusCodeHTTP1_1_NotExistUriPath</body></html>"
            };

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

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                Log.Comment("Expect StatusCode - NotFound  ");
                if (HttpStatusCode.NotFound != response.StatusCode)
                {
                    if ("0" == response.StatusCode.ToString())
                        Log.Exception("Known Issue::Bug 68085 - HttpStatusCode = 0 was returned");
                    else
                        Log.Exception("Expect HttpStatusCode = NotFound but get " + response.StatusCode);
                    result = MFTestResults.Fail;
                }

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
예제 #11
0
        private static void ProcessException(HttpListenerContext context, HttpServer server)
        {
            HttpListenerRequest  request  = context.Request;
            HttpListenerResponse response = context.Response;

            string strFilePath = GetPathFromURL(request.RawUrl == null ? "" : request.RawUrl);

            // There is one particular URL that we process differently
            if (strFilePath == "\\webexception\\ConnClose.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ConnectionClosed", WebExceptionStatus.ConnectionClosed)).ToString();
            }

            if (strFilePath == "\\webexception\\KeepAliveFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("KeepAliveFailure", WebExceptionStatus.KeepAliveFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\Pending.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("Pending", WebExceptionStatus.Pending)).ToString();
            }

            if (strFilePath == "\\webexception\\PipelineFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("PipelineFailure", WebExceptionStatus.PipelineFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\ProxyNameResolutionFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ProxyNameResolutionFailure", WebExceptionStatus.ProxyNameResolutionFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\ReceiveFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ReceiveFailure", WebExceptionStatus.ReceiveFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\RequestCanceled.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("RequestCanceled", WebExceptionStatus.RequestCanceled)).ToString();
            }

            if (strFilePath == "\\webexception\\SecureChannelFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("SecureChannelFailure", WebExceptionStatus.SecureChannelFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\SendFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("SendFailure", WebExceptionStatus.SendFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\Success.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("Success", WebExceptionStatus.Success)).ToString();
            }

            if (strFilePath == "\\webexception\\Timeout.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("Timeout", WebExceptionStatus.Timeout)).ToString();
            }

            if (strFilePath == "\\webexception\\TrustFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("TrustFailure", WebExceptionStatus.TrustFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\ConnectFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ConnectFailure", WebExceptionStatus.ConnectFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\NameResolutionFailure.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("NameResolutionFailure", WebExceptionStatus.NameResolutionFailure)).ToString();
            }

            if (strFilePath == "\\webexception\\ProtocolError.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ProtocolError", WebExceptionStatus.ProtocolError)).ToString();
            }

            if (strFilePath == "\\webexception\\ServerProtocolViolation.html")
            {
                // Throw the 'WebException' object with a message string, message status
                server.ResponseString = (new WebException("ServerProtocolViolation", WebExceptionStatus.ServerProtocolViolation)).ToString();
            }

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

            response.OutputStream.Write(buffer, 0, buffer.Length);
            return;
        }
        public MFTestResults InValidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_0_HTTPS()
        {
            MFTestResults result = MFTestResults.Pass;
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("https://"+ Utilities.GetLocalIpAddress() + ":443/");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Negative Test case 4:");
            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.0");
            wr.ProtocolVersion = new Version(1, 0);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
            };

            try
            {
                // Setup server
                server.StartServer();
                System.Net.WebHeaderCollection wrc = wr.Headers;

                // Tests
                Verify(wrc, server.RequestHeaders);
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                // Stop server
                server.StopServer();
            }

            return result;
        }
        public MFTestResults InValidDefaultTestGetHTTPResponseHeaderAfterCreateHTTP1_1_ftp1_0()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://ftp.microsoft.com");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.0");
            wr.ProtocolVersion = new Version(1, 0);

            HttpServer server = new HttpServer("http", 8080, ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
            };

            try
            {
                // Setup server
                server.StartServer();
                System.Net.WebHeaderCollection wrs = server.RequestHeaders;

                SetCommonHttpResponseHeaders_1_0(ref wrs);

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                WebHeaderCollection wrc = wr.Headers;

                VerifyHttpResponseHeaders(wrc, wrs);

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                StopServerListener(ref server);
                //Stop server
                server.StopServer();
            }

            return result;
        }
        //This test case get System.NotSupportedException
        public MFTestResults ValidDefaultTestGetHTTPResponseHeaderAfterCreateHTTP1_1_https()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("https://127.0.0.1:443/");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("https", 443, ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
            };

            try
            {
                // Setup server
                server.StartServer();
                System.Net.WebHeaderCollection wrs = server.RequestHeaders;

                SetCommonHttpResponseHeaders(ref wrs);

                //Get System.NotSupportedException when retrive response --  Need further investigation
                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                WebHeaderCollection wrc = wr.Headers;

                VerifyHttpResponseHeaders(wrc, wrs);

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                StopServerListener(ref server);
                //Stop server
                server.StopServer();
            }

            return result;
        }
        public MFTestResults ValidDefaultTestGetHTTPRequestHeaderAfterCreateHTTP1_1()
        {
            MFTestResults result = MFTestResults.Pass;
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
            };

            try
            {
                // Setup server
                server.StartServer();
                System.Net.WebHeaderCollection wrc = wr.Headers;
                
                // Tests
                Verify(wrc, server.RequestHeaders);
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
        public MFTestResults TestHTTPStatusCodeHTTP1_1_SendChunked_WithTransferEncoding()
        {
            MFTestResults result = MFTestResults.Pass;

            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://127.0.0.1:" + HttpServer.s_CurrentPort.ToString() + "/");
            wr.UserAgent = ".Net Micro Framwork Device/4.0";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);
            wr.SendChunked = true;
            wr.TransferEncoding = "Quoted-printable";

            string requestString = "ContentLength: " + wr.ContentLength
            + " ContentType:" + wr.ContentType + " KeepAlive:" + wr.KeepAlive
            + " ProtocolVersion:" + wr.ProtocolVersion + " TransferEncoding:" + wr.TransferEncoding
            + " SendChunked:" + wr.SendChunked + " Expect:" + wr.Expect
            + " Timeout:" + wr.Timeout;

            Log.Comment(requestString);
            
            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>TestHTTPStatusCodeHTTP1_1_SendChunked_WithTransferEncoding</body></html>"
            };

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

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();

                string ResponseString = "Server response: ContentEncoding:" + response.ContentEncoding + " ContentLength: " + response.ContentLength
                        + " ContentType:" + response.ContentType
                        + " ProtocolVersion:" + response.ProtocolVersion
                        + " StatusCode:" + response.StatusCode + " StatusDescription:" + response.StatusDescription;

                Log.Comment(ResponseString);

                Log.Comment("Expect StatusCode - OK");
                if (HttpStatusCode.OK != response.StatusCode)
                {
                    Log.Exception("Expect HttpStatusCode = OK but get " + response.StatusCode);
                    result = MFTestResults.Fail;

                }

                Log.Comment("Receive " + response.StatusDescription);

                response.Close();
            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {
                //Stop server
                server.StopServer();
            }

            return result;
        }
        public MFTestResults TestHTTPStatusCodeHTTP1_1_NonAuthoritativeInformation()
        {
            MFTestResults result = MFTestResults.Pass;


            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://"+ Utilities.GetLocalIpAddress() + ":" + HttpServer.s_CurrentPort.ToString() + "/webpages/nonauthInfo.html");  //expect 203 - NonAuthoritativeInformation
            wr.UserAgent = ".Net Micro Framwork Device/4.0";
            wr.Method = "GET";

            Log.Comment("Initial version: " + wr.ProtocolVersion);  //Default version is 1.1

            Log.Comment("Set Version 1.1");
            wr.ProtocolVersion = new Version(1, 1);

            HttpServer server = new HttpServer("http", ref result)
            {
                RequestUri = wr.RequestUri,
                RequestHeaders = wr.Headers,
                ResponseString = "<html><body>TestHTTPStatusCodeHTTP1_1_NonAuthoritativeInformation</body></html>"
            };

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

                HttpWebResponse response = (HttpWebResponse)wr.GetResponse();
                Log.Comment("Expect StatusCode - NonAuthoritativeInformation");
                if ((int)HttpStatusCode.NonAuthoritativeInformation != (int)response.StatusCode)
                {
                    Log.Exception("Expect HttpStatusCode = NonAuthoritativeInformation but get " + response.StatusCode);
                    result = MFTestResults.Fail;

                }
                Log.Comment("Receive " + response.StatusDescription);
                response.Close();

            }
            catch (Exception ex)
            {
                Log.Exception("[Client] Unexpected Exception", ex);
                result = MFTestResults.Fail;
            }
            finally
            {

                //Stop server
                server.StopServer();
            }

            return result;
        }