public async Task SaveCookie(string filename, CookieContainer rcookie, Uri uri) { StorageFolder localFolder = ApplicationData.Current.LocalFolder; StorageFile sampleFile = await localFolder.CreateFileAsync(filename, CreationCollisionOption.ReplaceExisting); using (StorageStreamTransaction transaction = await sampleFile.OpenTransactedWriteAsync()) { CookieSerializer.Serialize(rcookie.GetCookies(uri), uri, transaction.Stream.AsStream()); await transaction.CommitAsync(); } }
public void A_Cookie_Collection_Can_Be_Serialized() { //Arrange var cookies = new CookieCollection { new Cookie("foo", "bar") }; var cookieStream = new MemoryStream(); //Act CookieSerializer.Serialize(cookies, new Uri("http://foo.com"), cookieStream); //Assert Assert.IsTrue(cookieStream.Length > 0); }
public void A_Cookie_Collection_Can_Be_Deserialized() { //Arrange var uri = new Uri("http://foo.com"); var cookies = new CookieCollection { new Cookie("foo", "bar") }; var cookieStream = new MemoryStream(); //Act CookieSerializer.Serialize(cookies, uri, cookieStream); cookieStream.Seek(0, SeekOrigin.Begin); var deserialized = CookieSerializer.Deserialize(uri, cookieStream); //Assert Assert.AreEqual(1, deserialized.Count); Assert.IsNotNull(deserialized.GetCookies(uri)["foo"]); }