Skip to content

Instantly share code, notes, and snippets.

@csainty
Created May 15, 2012 11:09
Show Gist options
  • Save csainty/2700887 to your computer and use it in GitHub Desktop.
Save csainty/2700887 to your computer and use it in GitHub Desktop.
public class Bootstrapper : DefaultNancyBootstrapper
{
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
CookieBasedSessions.Enable(pipelines);
}
}
public static class BootstrapperExtensions
{
public static void WithSession(this IPipelines pipeline, IDictionary<string, object> session)
{
pipeline.BeforeRequest.AddItemToEndOfPipeline(ctx =>
{
ctx.Request.Session = new Session(session);
return null;
});
}
}
[Fact]
public void TestSession()
{
var boot = new ConfigurableBootstrapper(with => { with.Module<PagesModule>(); });
boot.WithSession(new Dictionary<string, object>() { { "key", "value" }, { "number", 2 } });
var browser = new Browser(boot);
var response = browser.Get("/Test");
Assert.NotNull(response.Context.Request.Session);
Assert.Equal(response.Context.Request.Session["key"], "value");
Assert.Equal(response.Context.Request.Session["number"], 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment