[Test] public void Render_Request()
        {
            var fileInRoot = apiCassini.create_Random_File_Aspx().assert_File_Exists()
                                                                 .assert_File_Extension_Is(".aspx");
            var fileName   = fileInRoot.fileName();
            var url        = apiCassini.url_From_File(fileInRoot).assert_Equal(apiCassini.url(fileName));


            var server           = new Server(apiCassini.webRoot());
            var host             = server.GetHost();            
            
            url .GET()                   .assert_Valid().assert_Equals(fileInRoot.fileContents());  // check that we can get the file via a normal GET Request
            host.Render_Request(fileName).assert_Valid().assert_Equals(fileInRoot.fileContents());  // check that direct rendering of request produces the same value

            // check 404
            apiCassini.host().Render_Request("a.html").assert_Contains("The resource cannot be found.");
            apiCassini.host().Render_Request("a.img" ).assert_Contains("The resource cannot be found.");
            
            // check that HTML returns an empty value
            var htmlInRoot = apiCassini.create_Random_File_Html().assert_File_Exists()
                                                                 .assert_File_Extension_Is(".html")
                                                                 .assert_File_Extension_Is_Not(".aspx");

            host.Render_Request(      htmlInRoot.fileName()).assert_Is("");
            host.Render_Request("a" + htmlInRoot.fileName()).assert_Contains("The resource cannot be found.");;
        }
        public void GET_Request_Using_GetHost_And_TcpClient()
        {            
            var server = new Server("_temp_CassiniSite".tempDir());

            var socket = Server.CreateSocketBindAndListen(AddressFamily.InterNetwork, server.IPAddress, server.Port);            
            
            var thread = O2Thread.mtaThread(
                ()=>{
                        Socket acceptedSocket = socket.Accept();
                        var connection = new Connection(server,acceptedSocket);
                        //var host = new Host();                    // we can't get the host directly, it needs to be created using the technique coded in  
                        var host =server.GetHost();                 // CreateWorkerAppDomainWithHost 
                        
                        host.Configure(server, server.Port, server.VirtualPath, server.PhysicalPath);
                        host.ProcessRequest(connection);            
                    });
            
            var request1 = "GET / HTTP/1.1".line().line();
                
            var tcpClient1 = server.Port.tcpClient();
            tcpClient1.write(request1);            
            var response1 = tcpClient1.read_Response();
            Assert.IsTrue(response1.valid());                     

            server.PhysicalPath.delete_Folder();
        }
 public void GET_Request_Using_GetHost_And_SimpleWorkerRequest()
 {
     var server           = new Server("_temp_CassiniSite".tempDir());
     var host             = server.GetHost();
     //host.Configure(server, server.Port, server.VirtualPath, server.PhysicalPath);
     var fileName         = "test.aspx";
     var query1            = "name=John Smith";
     var query2            = "name=OWASP";
     var query3            = "name=42";
     var query4            = "";
     var fileContents     = "<%=\"Hello \" + Request(\"name\") %>";
     var expectedResponse1 = "Hello John Smith";
     var expectedResponse2 = "Hello OWASP";
     var expectedResponse3 = "Hello 42";
     var expectedResponse4 = "Hello ";
     var filePath         = server.PhysicalPath.pathCombine(fileName);
     fileContents.saveAs(filePath);            
     
     
     var response1 = host.Render_Request(fileName, query1);            
     var response2 = host.Render_Request(fileName, query2);            
     var response3 = host.Render_Request(fileName, query3);                        
     var response4 = host.Render_Request(fileName, query4);                        
     Assert.AreEqual(response1, expectedResponse1);
     Assert.AreEqual(response2, expectedResponse2);
     Assert.AreEqual(response3, expectedResponse3);
     Assert.AreEqual(response4, expectedResponse4);            
     
     server.ShutDown();
     //delete temp server.PhysicalPath
     server.PhysicalPath.delete_Folder();
 }