public void TestUnsuccessfulLoadFile() { IFactory factory = new TestingFactory(PASSWORD, IV, SALT); ActionList actionList = factory.GetActionList(); IStorage storage = factory.GetStorage(); AccountCollection collection = TestObjectBuilder.GetAccountCollection(); string serialized = actionList.DoActions(collection); storage.StoreData("test", serialized); string fromStorage = storage.RetrieveData("test"); IFactory factory2 = new TestingFactory("wrong", IV, SALT); ActionList actionList2 = factory2.GetActionList(); try { AccountCollection deserialized = actionList2.ReverseActions <AccountCollection>(fromStorage); } catch (DeserializationException) { // Success return; } Assert.Fail("Exception should have been thrown because wrong password was used."); }
private void SaveAccountCollection() { IFactory factory = FormFactory.GetFactory(_password, _appSettings.Value.IV, _appSettings.Value.Salt); IStorage storage = factory.GetStorage(); ActionList actionList = factory.GetActionList(); string serialized = actionList.DoActions(_accountCollection); storage.StoreData(_fileName, serialized); }
public void TestSerializeAndDeserialize() { IFactory factory = new TestingFactory(PASSWORD, IV, SALT); ActionList actionList = factory.GetActionList(); IStorage storage = factory.GetStorage(); AccountCollection collection = TestObjectBuilder.GetAccountCollection(); string serialized = actionList.DoActions(collection); storage.StoreData("test", serialized); string fromStorage = storage.RetrieveData("test"); AccountCollection deserialized = actionList.ReverseActions <AccountCollection>(fromStorage); Assert.AreEqual(collection, deserialized); }
//private static void TestSerialization() //{ // AccountCollection collection = GetTestCollection(); // Console.WriteLine(collection); // ActionList actionList = new ActionList(new BitSerializer(), new ActionBase[0]); // string serialized = actionList.DoActions(collection); // AccountCollection collection1 = actionList.ReverseActions<AccountCollection>(serialized); // Console.WriteLine(collection1); //} //private static void TestEncryption() //{ // AccountCollection collection = GetTestCollection(); // Console.WriteLine(collection); // ConfigurationSettings configSettings = new ConfigurationSettings(); // DataCryptoBase crypto = new RijndaelDataCrypto(configSettings.Password, configSettings.Salt, configSettings.IV); // EncryptionAction encryptionAction = new EncryptionAction(crypto); // ActionList actionList = new ActionList(new BitSerializer(), encryptionAction); // string serialized = actionList.DoActions(collection); // AccountCollection collection1 = actionList.ReverseActions<AccountCollection>(serialized); // Console.WriteLine(collection1); //} //private static void TestEncryptionAndCompression() //{ // AccountCollection collection = GetTestCollection(); // Console.WriteLine(collection); // ConfigurationSettings configSettings = new ConfigurationSettings(); // DataCryptoBase crypto = new RijndaelDataCrypto(configSettings.Password, configSettings.Salt, configSettings.IV); // EncryptionAction encryptionAction = new EncryptionAction(crypto); // ActionList actionList = new ActionList(new BitSerializer(), encryptionAction, new CompressionAction()); // string serialized = actionList.DoActions(collection); // AccountCollection collection1 = actionList.ReverseActions<AccountCollection>(serialized); // Console.WriteLine(collection1); //} private static void TestFileSave() { AccountCollection collection = GetTestCollection(); Console.WriteLine(collection); IFactory factory = new DefaultFactory("smellyourbeans", "FartedInPublic69", "jfdg8jlFJH89lkJsdf9jm8n*y6(*^jlkfdj"); ActionList actionList = factory.GetActionList(); IStorage storage = factory.GetStorage(); string serialized = actionList.DoActions(collection); storage.StoreData("file.dat", serialized); string fromFile = storage.RetrieveData("file.dat"); AccountCollection collection1 = actionList.ReverseActions <AccountCollection>(fromFile); Console.WriteLine(collection1); }