Created
August 25, 2014 17:30
-
-
Save xinmyname/61af21f5761b6ab919b6 to your computer and use it in GitHub Desktop.
Render Nancy View to text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.IO; | |
using System.Text; | |
using Nancy; | |
using Nancy.Hosting.Self; | |
using Nancy.Testing; | |
using Nancy.ViewEngines; | |
namespace NancyTesting | |
{ | |
class Program | |
{ | |
static void Main() | |
{ | |
var hostConfig = new HostConfiguration | |
{ | |
UrlReservations = new UrlReservations { CreateAutomatically = true } | |
}; | |
var hostUri = new Uri("http://localhost:8089"); | |
using (var host = new NancyHost(hostConfig, hostUri)) | |
{ | |
host.Start(); | |
var bootstrapper = new DefaultNancyBootstrapper(); | |
bootstrapper.Initialise(); | |
INancyEngine engine = bootstrapper.GetEngine(); | |
var request = new Request("GET", "/", "http"); | |
NancyContext context = engine.HandleRequest(request); | |
Response response = context.Response; | |
var stream = new MemoryStream(); | |
response.Contents(stream); | |
string text = Encoding.Default.GetString(stream.ToArray()); | |
Console.WriteLine(text); | |
Console.WriteLine("Listening on {0}", hostUri.AbsoluteUri); | |
Process.Start(hostUri.AbsoluteUri); | |
Console.ReadLine(); | |
} | |
} | |
} | |
public class SampleModule : NancyModule | |
{ | |
public SampleModule() | |
{ | |
Get["/"] = _ => View["Index"]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment