Created
May 15, 2012 11:09
-
-
Save csainty/2700887 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public class Bootstrapper : DefaultNancyBootstrapper | |
{ | |
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines) | |
{ | |
CookieBasedSessions.Enable(pipelines); | |
} | |
} |
This file contains hidden or 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
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