public void CanLoadState() { CanSaveState(); FileStatePersistenceService svc = new FileStatePersistenceService(); State state = svc.Load(stateID); Assert.AreEqual(stateID, state.ID); Assert.AreEqual("somevalue", state["somekey"]); }
public void UsesCryptoToLoad() { string id = Guid.NewGuid().ToString(); State testState = new State(id); testState["someValue"] = "value"; MemoryStream ms = new MemoryStream(); //BinaryFormatter fmt = new BinaryFormatter(); //fmt.Serialize(ms, testState); #pragma warning disable CS0618 // Type or member is obsolete System.Runtime.Serialization.DataContractSerializer fmt = new System.Runtime.Serialization.DataContractSerializer(typeof(State), new System.Collections.Generic.List <Type>() { typeof(System.Collections.CaseInsensitiveHashCodeProvider), typeof(System.Collections.CaseInsensitiveComparer), typeof(System.String[]), typeof(System.Object[]) }); #pragma warning restore CS0618 // Type or member is obsolete fmt.WriteObject(ms, testState); byte[] cipherData = ProtectedData.Protect(ms.GetBuffer(), null, DataProtectionScope.CurrentUser); string filename = string.Format(CultureInfo.InvariantCulture, "{0}.state", id); using (FileStream stream = File.OpenWrite(filename)) { stream.Write(cipherData, 0, cipherData.Length); } WorkItem host = container; ICryptographyService cryptoSvc = new DataProtectionCryptographyService(); host.Services.Add(typeof(ICryptographyService), cryptoSvc); FileStatePersistenceService perSvc = new FileStatePersistenceService(); host.Services.Add(typeof(IStatePersistenceService), perSvc); NameValueCollection settings = new NameValueCollection(); settings["UseCryptography"] = "True"; perSvc.Configure(settings); State recovered = perSvc.Load(id); Assert.AreEqual(id, recovered.ID, "The state id is different."); Assert.AreEqual("value", recovered["someValue"]); if (File.Exists(filename)) { File.Delete(filename); } }
public void UsesCryptoToLoad() { string id = Guid.NewGuid().ToString(); State testState = new State(id); testState["someValue"] = "value"; BinaryFormatter fmt = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); fmt.Serialize(ms, testState); byte[] cipherData = ProtectedData.Protect(ms.GetBuffer(), null, DataProtectionScope.CurrentUser); string filename = string.Format(CultureInfo.InvariantCulture, "{0}.state", id); using (FileStream stream = File.OpenWrite(filename)) { stream.Write(cipherData, 0, cipherData.Length); } WorkItem host = container; ICryptographyService cryptoSvc = new DataProtectionCryptographyService(); host.Services.Add(typeof(ICryptographyService), cryptoSvc); FileStatePersistenceService perSvc = new FileStatePersistenceService(); host.Services.Add(typeof(IStatePersistenceService), perSvc); NameValueCollection settings = new NameValueCollection(); settings["UseCryptography"] = "True"; perSvc.Configure(settings); State recovered = perSvc.Load(id); Assert.AreEqual(id, recovered.ID, "The state id is different."); Assert.AreEqual("value", recovered["someValue"]); if (File.Exists(filename)) { File.Delete(filename); } }
public void LoadingInexistentState() { FileStatePersistenceService svc = new FileStatePersistenceService(); State state = svc.Load("junk"); }