public void CanSave([Values] SerializationMethodType method) { var manager = CreateManager(method); var testObject = new SaveLoadTestObject() { listOfStrings = new List <string> { "one", "two" }, count = 10, }; const string filename = "Testfile"; manager.Save(testObject, filename); var filepath = $"{SaveLoadUtility.GetSavePath(SaveDirectory, BaseDirectory)}/{filename}"; Assert.IsTrue(File.Exists(filepath)); manager.DeleteSave(filename); Assert.IsFalse(File.Exists(filepath)); Object.Destroy(manager); }
public void CanSaveLoadUnityObject([Values] SerializationMethodType method) { const string filename = "Testfile"; var manager = CreateManager(method); var testObj = ScriptableObject.CreateInstance <SaveLoadTestUnityObject>(); var loadedTestObj = ScriptableObject.CreateInstance <SaveLoadTestUnityObject>(); testObj.textValue = "MyValue"; manager.SaveUnityObject(testObj, filename); var filepath = $"{SaveLoadUtility.GetSavePath(SaveDirectory, BaseDirectory)}/{filename}"; Assert.IsTrue(File.Exists(filepath)); //var loadedTestObj = manager.Load<SaveLoadTestUnityObject>(filename); //Assert.IsTrue(loadedTestObj != null); manager.LoadUnityObjectOverwrite(loadedTestObj, filename); Assert.IsTrue(loadedTestObj.textValue == testObj.textValue); manager.DeleteSave(filename); Assert.IsFalse(File.Exists(filepath)); Object.Destroy(testObj); Object.Destroy(loadedTestObj); Object.Destroy(manager); }
private static void CleanupFiles() { //Cleaning up some files that were made by tests const string filename = "Testfile"; var filepath = $"{SaveLoadUtility.GetSavePath(SaveDirectory, BaseDirectory)}/{filename}"; if (File.Exists(filepath)) { File.Delete(filepath); } }
public void TearDown() { var path = SaveLoadUtility.GetSavePath(); string[] files = { "TestSave.sav" }; foreach (var file in files) { var filename = path + file; if (File.Exists(filename)) { File.Delete(filename); } } }
public void CanSaveAndLoadDictionary([Values( SerializationMethodType.Binary, SerializationMethodType.BinaryEncrypted #if JSON_DOT_NET , SerializationMethodType.JsonDotNet, SerializationMethodType.JsonDotNetEncrypted #endif )] SerializationMethodType method) { var manager = CreateManager(method); var testObject = new SaveLoadDictionaryTestObject() { dict = new Dictionary <string, int> { { "one", 1 }, { "two", 2 } }, name = "Test", }; const string filename = "Testfile"; manager.Save(testObject, filename); var filepath = $"{SaveLoadUtility.GetSavePath(SaveDirectory, BaseDirectory)}/{filename}"; Assert.IsTrue(File.Exists(filepath)); var loadedObject = manager.Load <SaveLoadDictionaryTestObject>(filename); Assert.IsTrue(loadedObject.name == testObject.name); Assert.IsTrue(loadedObject.dict.Count == testObject.dict.Count); Assert.IsTrue(loadedObject.dict.ContainsKey("one")); Assert.IsTrue(loadedObject.dict.ContainsKey("two")); Assert.IsTrue(loadedObject.dict["one"] == 1); Assert.IsTrue(loadedObject.dict["two"] == 2); manager.DeleteSave(filename); Assert.IsFalse(File.Exists(filepath)); Object.Destroy(manager); }