public MFTestResults FunctionalChunkTests()
        {
            MFTestResults result = MFTestResults.Pass;
            string currentPort = HttpTestServer.s_CurrentPort.ToString();
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://"+ Utilities.GetLocalIpAddress() + ":" + currentPort + "/");
            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://" + Utilities.GetLocalIpAddress() + ":" + currentPort + "/");
                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;
        }
        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);
        }
        public MFTestResults SetHeadersAfterRequest()
        {
            MFTestResults result = MFTestResults.Pass;
            HttpWebRequest wr = (HttpWebRequest)WebRequest.Create("http://" + Utilities.GetLocalIpAddress() + ":" + 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;
        }
        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);
        }