public void UsesCryptoToLoad() { string id = "id"; 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); MemoryStream stream = new MemoryStream(); stream.Write(cipherData, 0, cipherData.Length); WorkItem host = new TestableRootWorkItem(); DataProtectionCryptographyService cryptoSvc = new DataProtectionCryptographyService(); MemoryStreamPersistence perSvc = new MemoryStreamPersistence(); perSvc.Stream = stream; host.Services.Add(typeof(ICryptographyService), cryptoSvc); 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"]); }
public void CanSaveAndLoadState() { State state = new State(stateID); state["somekey"] = "somevalue"; MemoryStreamPersistence svc = new MemoryStreamPersistence(); svc.Save(state); State state2 = svc.Load(stateID); Assert.AreEqual(state["somekey"], state2["somekey"]); }
public void UsesCryptoToLoad() { string id = "id"; State testState = new State(id); testState["someValue"] = "value"; #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 MemoryStream ms = new MemoryStream(); fmt.WriteObject(ms, testState); byte[] cipherData = ProtectedData.Protect(ms.GetBuffer(), null, DataProtectionScope.CurrentUser); MemoryStream stream = new MemoryStream(); stream.Write(cipherData, 0, cipherData.Length); WorkItem host = new TestableRootWorkItem(); DataProtectionCryptographyService cryptoSvc = new DataProtectionCryptographyService(); MemoryStreamPersistence perSvc = new MemoryStreamPersistence(); perSvc.Stream = stream; host.Services.Add(typeof(ICryptographyService), cryptoSvc); 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"]); }