public void set_Path_UserData()
        {
            var tmFileStorage = new TM_FileStorage();

            var expectedPath  = tmFileStorage.path_XmlDatabase().pathCombine(TMConsts.TM_SERVER_DEFAULT_NAME_USERDATA);

            tmFileStorage.set_Path_UserData();
            var userData = tmFileStorage.UserData;

            //Assert.NotNull (tmServer);
            Assert.NotNull (userData);
            Assert.AreEqual(tmFileStorage.Path_UserData, expectedPath);
            Assert.True    (tmFileStorage.Path_UserData.dirExists());

            // try with a different Name value
            var tempName = 10.randomLetters();
            tmFileStorage.Server.userData_Config().Name = tempName;
            tmFileStorage.set_Path_UserData();
            Assert.IsTrue(tmFileStorage.Path_UserData.contains(tempName));

            tmFileStorage.delete_Database();
            Assert.False   (tmFileStorage.Path_UserData.dirExists());

            //check bad data handling
            tmFileStorage.Server.userData_Config().Name = null;
            tmFileStorage.set_Path_UserData();
            Assert.IsTrue(tmFileStorage.Path_UserData.contains(TMConsts.TM_SERVER_DEFAULT_NAME_USERDATA));

            tmFileStorage.Server.userData_Config().Name = "aaa:bbb"; // will fail to create the UserData folder and force memory mode
            tmFileStorage.set_Path_UserData();
            Assert.IsNotNull (tmFileStorage.UserData);
            Assert.IsNull    (tmFileStorage.Path_UserData);

            //test nulls
            tmFileStorage.Server         = null;
            tmFileStorage.UserData       = null;
            tmFileStorage.TMXmlDatabase  = null;
            tmFileStorage.set_Path_UserData();

            Assert.IsNull (tmFileStorage.Path_UserData);

            //Assert.IsNull (new TM_FileStorage(false).set_Path_UserData().Path_UserData);
        }
        public void set_Path_XmlDatabase__UsingFileStorage_On_Custom_WebRoot()
        {
            var tmFileStorage = new TM_FileStorage(false);

            //Assert.AreEqual(tmFileStorage.WebRoot, AppDomain.CurrentDomain.BaseDirectory);
            tmFileStorage.WebRoot = "_tmp_webRoot".tempDir().info();

            tmFileStorage.WebRoot.delete_Folder();
            Assert.IsFalse(tmFileStorage.WebRoot.dirExists());

            tmFileStorage.set_Path_XmlDatabase();

            Assert.IsTrue  (tmFileStorage.path_XmlDatabase().dirExists(), "db ctor should create a library folder");

            var usingAppDataFolder = TM_Status.Current.TM_Database_Location_Using_AppData;

            "*** DB path: {0}".info(tmFileStorage.path_XmlDatabase());
            "*** Lib path: {0}".info(tmFileStorage.Path_XmlLibraries);
            "*** Current WebRoot: {0}".debug(tmFileStorage.WebRoot);
            "*** Current WebRoot exists: {0}".debug(tmFileStorage.WebRoot.dirExists());
            "*** TM_Status.Current.TM_Database_Location_Using_AppData: {0}".debug(TM_Status.Current.TM_Database_Location_Using_AppData);

            Assert.AreEqual(usingAppDataFolder, tmFileStorage.WebRoot.dirExists()       , "db ctor should not create a Web Root (if it doesn't exist)");
            Assert.AreEqual(usingAppDataFolder, tmFileStorage.path_XmlDatabase().contains ("App_Data"));
            Assert.AreEqual(usingAppDataFolder, tmFileStorage.path_XmlDatabase().contains (tmFileStorage.WebRoot));
            Assert.AreEqual(usingAppDataFolder, tmFileStorage.path_XmlDatabase().contains (PublicDI.config.O2TempDir));

            tmFileStorage.delete_Database();

            Assert.AreEqual(usingAppDataFolder, tmFileStorage.WebRoot.dirExists()  , "if not usingAppDataFolder the TM_Server.WebRoot shouldn't exist");
            Assert.IsFalse(tmFileStorage.path_XmlDatabase().dirExists()          , "should had been deleted");
        }
        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());
        }
        public void set_Path_XmlDatabase__UsingFileStorage()
        {
            var tmFileStorage = new TM_FileStorage();
            var tmXmlDatabase = tmFileStorage.TMXmlDatabase;

            tmFileStorage.set_Path_XmlDatabase();

            Assert.AreEqual   (tmXmlDatabase, TM_Xml_Database.Current);
            Assert.IsTrue     (tmXmlDatabase.usingFileStorage());
            Assert.IsNotNull  (tmFileStorage.path_XmlDatabase());

            tmFileStorage.delete_Database();
        }