public void StorageConstructorTest() { // Create storage. var storage = DataGenerator.CreateStorage(10, 25); Assert.IsNotNull(storage, "Failed creating Storage."); // Create writer. var streamWriter = new StreamWriter(XmlFileName); var xmlWriter = XmlWriter.Create(streamWriter); if (xmlWriter != null) { // Create serializer. var serializer = new DataContractSerializer(typeof(Storage)); // Serialize. serializer.WriteObject(xmlWriter, storage); xmlWriter.Close(); streamWriter.Close(); // Create reader. var streamReader = new StreamReader(XmlFileName); var xmlReader = XmlReader.Create(streamReader); // Deserialize. var deserializedStorage = (Storage)serializer.ReadObject(xmlReader); xmlReader.Close(); streamReader.Close(); Assert.IsNotNull(deserializedStorage, "Failed deserializing."); Assert.AreEqual(storage.ToString(), deserializedStorage.ToString(), "Failed serialize/deserialize."); } else { Assert.Fail("Failed creation xmlWriter"); } }
/// <summary> /// Tests save/restore /// </summary>[TestMethod] public void StorageSaveRestoreTest() { // Create storage. var storage = DataGenerator.CreateStorage(10, 25); Assert.IsNotNull(storage, "Failed creating Storage."); // Keep sourcestorage ToString var src = storage.ToString(); // Start edit. storage.BeginEdit(); // Edit storage.Version = "edited"; storage.Builds.RemoveAt(1); // Cancel edit. storage.CancelEdit(); // Check. Assert.AreEqual(src, storage.ToString(), "Failed save/edit"); }