[Test] public void tm_Server_Save() { var tmFileStorage = new TM_FileStorage(); Assert.NotNull(tmFileStorage.path_XmlDatabase()); var tmServerLocation = tmFileStorage.tmServer_Location(); var tmServer_withDefaultData = new TM_Server().setDefaultData(); Assert.IsTrue(tmServerLocation.fileExists()); // Assert.Ignore("TO FIX (Refactor Side Effect"); Assert.AreEqual(tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml()); var tmpName1 = 10.randomLetters(); tmFileStorage.Server.UserData_Configs.first().Name = tmpName1; Assert.IsTrue(tmFileStorage.tmServer_Save()); Assert.AreEqual(tmServerLocation.load <TM_Server>().UserData_Configs.first().Name, tmpName1); //check that it was saved /* * // this works but makes the test run in 10s (and the test being done is if there is no exception) * * var tmpName2 = 10.randomLetters(); * tmServerLocation.fileInfo() * .setAccessControl("Users", FileSystemRights.Write, AccessControlType.Deny); * * tmXmlDatabase.Server.UserData_Configs.first().Name = tmpName2; * * Assert.IsFalse(tmXmlDatabase.tmServer_Save()); * * Assert.AreEqual(tmServerLocation.load<TM_Server>().UserData_Configs.first().Name, tmpName1); //check that it was not saved * * Assert.IsTrue(tmServerLocation.delete_File()); * Assert.IsFalse(tmServerLocation.fileExists()); */ tmFileStorage.delete_Database(); Assert.IsFalse(tmServerLocation.fileExists()); Assert.IsFalse(tmFileStorage.path_XmlDatabase().dirExists()); //check when not UsingFileStorage //check for nulls tmFileStorage.Path_XmlDatabase = null; Assert.IsFalse(tmFileStorage.tmServer_Save()); Assert.IsFalse(new TM_FileStorage(false).tmServer_Save()); }
[Test] public void tm_Server_Load_UsingFileStorage() { var tmFileStorage = new TM_FileStorage(false); var baseReadOnlyDir = "_tmp_webRoot".tempDir(); var webRootVirualPath = @"site\wwwroot"; // simulates use of AppData tmFileStorage.WebRoot = baseReadOnlyDir.pathCombine(webRootVirualPath).createDir(); tmFileStorage.set_Path_XmlDatabase() .set_Path_UserData() .tmServer_Load(); var tmServerFile = tmFileStorage.tmServer_Location(); var expectedLocation = tmFileStorage.Path_XmlDatabase.pathCombine(TMConsts.TM_SERVER_FILENAME); Assert.IsNotNull(tmFileStorage.path_XmlDatabase()); Assert.IsTrue(TM_Status.Current.TM_Database_Location_Using_AppData); Assert.NotNull(tmFileStorage.Server); Assert.IsTrue(tmServerFile.fileExists()); Assert.AreEqual(tmServerFile, expectedLocation); // Assert.Ignore("TO FIX (Refactor Side Effect"); // Assert.Ignore("TO FIX (Refactor Side Effect"); var tmServer_withDefaultData = new TM_Server().setDefaultData(); Assert.AreEqual(tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml()); //make a change, saved it and ensure it gets loaded ok var tmpName1 = 10.randomLetters(); var tmpName2 = 10.randomLetters(); tmFileStorage.Server.UserData_Configs.first().Name = tmpName1; tmFileStorage.tmServer_Save(); tmFileStorage.Server.UserData_Configs.first().Name = tmpName2; tmFileStorage.tmServer_Load(); Assert.AreEqual(tmFileStorage.Server.UserData_Configs.first().Name, tmpName1); Assert.AreNotEqual(tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml()); //Try loading up an corrupted tmServer (whcih will default to load a default TM_Server "aaaa".saveAs(tmServerFile); tmFileStorage.tmServer_Load(); Assert.AreNotEqual(tmFileStorage.Server.UserData_Configs.first().Name, tmpName1); Assert.AreEqual(tmFileStorage.Server.toXml(), tmServer_withDefaultData.toXml()); Files.deleteFolder(baseReadOnlyDir, true); Assert.IsFalse(baseReadOnlyDir.dirExists()); //tmXmlDatabase.delete_Database(); }