本文整理汇总了C#中Nancy.Session.CookieBasedSessions.Save方法的典型用法代码示例。如果您正苦于以下问题:C# CookieBasedSessions.Save方法的具体用法?C# CookieBasedSessions.Save怎么用?C# CookieBasedSessions.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.Session.CookieBasedSessions
的用法示例。
在下文中一共展示了CookieBasedSessions.Save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_set_Path_when_config_provides_path_value
public void Should_set_Path_when_config_provides_path_value()
{
//Given
var cryptoConfig = new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider);
var storeConfig = new CookieBasedSessionsConfiguration(cryptoConfig)
{
Path = "/",
Serializer = this.fakeObjectSerializer
};
var store = new CookieBasedSessions(storeConfig);
//When
var response = new Response();
var session = new Session(new Dictionary<string, object>
{
{"key1", "val1"},
});
session["key2"] = "val2";
store.Save(session, response);
//Then
var cookie = response.Cookies.First(c => c.Name == storeConfig.CookieName);
cookie.Path.ShouldEqual(storeConfig.Path);
}
示例2: Should_use_CookieName_when_config_provides_cookiename_value
public void Should_use_CookieName_when_config_provides_cookiename_value()
{
//Given
var cryptoConfig = new CryptographyConfiguration(this.fakeEncryptionProvider, this.fakeHmacProvider);
var storeConfig = new CookieBasedSessionsConfiguration(cryptoConfig)
{
CookieName = "NamedCookie",
Serializer = this.fakeObjectSerializer
};
var store = new CookieBasedSessions(storeConfig);
//When
var response = new Response();
var session = new Session(new Dictionary<string, object>
{
{"key1", "val1"},
});
session["key2"] = "val2";
store.Save(session, response);
//Then
response.Cookies.ShouldHave(c => c.Name == storeConfig.CookieName);
}
示例3: Should_be_able_to_load_an_object_previously_saved_to_session
public void Should_be_able_to_load_an_object_previously_saved_to_session()
{
var response = new Response();
var session = new Session(new Dictionary<string, object>());
var payload = new DefaultSessionObjectFormatterFixture.Payload(27, true, "Test string");
var store = new CookieBasedSessions(this.rijndaelEncryptionProvider, this.defaultHmacProvider, this.defaultObjectSerializer);
session["testObject"] = payload;
store.Save(session, response);
var request = new Request("GET", "/", "http");
request.Cookies.Add(Helpers.HttpUtility.UrlEncode(response.Cookies.First().Name), Helpers.HttpUtility.UrlEncode(response.Cookies.First().Value));
var result = store.Load(request);
result["testObject"].ShouldEqual(payload);
}
示例4: Should_be_able_to_save_a_complex_object_to_session
public void Should_be_able_to_save_a_complex_object_to_session()
{
var response = new Response();
var session = new Session(new Dictionary<string, object>());
var payload = new DefaultSessionObjectFormatterFixture.Payload(27, true, "Test string");
var store = new CookieBasedSessions(this.rijndaelEncryptionProvider, this.defaultHmacProvider, this.defaultObjectSerializer);
session["testObject"] = payload;
store.Save(session, response);
response.Cookies.Count.ShouldEqual(1);
var cookie = response.Cookies.First();
cookie.Name.ShouldEqual(store.CookieName);
cookie.Value.ShouldNotBeNull();
cookie.Value.ShouldNotBeEmpty();
}
示例5: Should_call_the_formatter_on_save
public void Should_call_the_formatter_on_save()
{
var response = new Response();
var session = new Session(new Dictionary<string, object>());
session["key1"] = "value1";
var fakeFormatter = A.Fake<IObjectSerializer>();
var store = new CookieBasedSessions(this.fakeEncryptionProvider, this.fakeHmacProvider, fakeFormatter);
store.Save(session, response);
A.CallTo(() => fakeFormatter.Serialize("value1")).MustHaveHappened(Repeated.Exactly.Once);
}
示例6: SaveSession
/// <summary>
/// Saves the request session into the response
/// </summary>
/// <param name="context">Nancy context</param>
/// <param name="sessionStore">Session store</param>
private static void SaveSession(NancyContext context, CookieBasedSessions sessionStore)
{
sessionStore.Save(context.Request.Session, context.Response);
}