public void TestSaveAndLoadApplicationFolderWithSubDirectory() { const string SubDir = "config"; const string FileName = "Test.json"; var filePath = JsonSerializable.GetApplicationDirectoryFilePath(FileName, SubDir); FileInfo fi = new FileInfo(filePath); if (fi.DirectoryName != null) { Directory.CreateDirectory(fi.DirectoryName); } // Ensure to delete before test try { File.Delete(filePath); } catch (Exception ex) { Debug.WriteLine(ex); } JsonSerialzableTestValues test = new JsonSerialzableTestValues(); try { // Assign Test Values AssignTestValues(test, _testValues); // Save to file test.SaveToApplicationDirectory(FileName, SubDir); } catch (Exception ex) { Debug.WriteLine(ex); } test = new JsonSerialzableTestValues(); // Create new class with different values try { test.LoadFromApplicationDirectory(FileName, SubDir); } catch (Exception ex) { Debug.WriteLine(ex); } // Test against test values CompareValues(test, _testValues); // cleanup test file try { File.Delete(filePath); } catch (Exception ex) { Debug.WriteLine(ex); } }
public void TestSaveAndLoadApplicationFolder() { const string SubDir = ""; const string FileName = "Test.json"; // Empty subdirectory (should point to the applications folder by the default behaviour of Path.Combine(a,b,c) when b is empty) var filePath = JsonSerializable.GetApplicationDirectoryFilePath(FileName, SubDir); FileInfo fi = new FileInfo(filePath); if (fi.DirectoryName != null) { Directory.CreateDirectory(fi.DirectoryName); } // Ensure to delete before test try { File.Delete(filePath); } catch (Exception ex) { Debug.WriteLine(ex); } JsonSerialzableTestValues test = new JsonSerialzableTestValues(); try { // Assign Test Values AssignTestValues(test, _testValues); // Save to file test.SaveToApplicationDirectory(FileName, SubDir); } catch (Exception ex) { Debug.WriteLine(ex); } test = new JsonSerialzableTestValues(); // Create new class with different values try { test.LoadFromApplicationDirectory(FileName, SubDir); } catch (Exception ex) { Debug.WriteLine(ex); } // Test against test values CompareValues(test, _testValues); // cleanup test file try { File.Delete(filePath); } catch (Exception ex) { Debug.WriteLine(ex); } }