Esempio n. 1
0
        [Test] 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");
        }
Esempio n. 2
0
        [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();
        }
Esempio n. 3
0
        [Admin][Test] public void set_Path_XmlDatabase()
        {
            admin.assert();
            var custom_WebRoot = TM_FileStorage.Custom_WebRoot = "Custom_WebRoot".tempDir().assert_Folder_Exists();

            var tmFileStorage = new TM_FileStorage(loadData: false)
                                .set_WebRoot()
                                .set_Path_XmlDatabase();

            var path_XmlDatabase = tmFileStorage.path_XmlDatabase().assert_Folder_Exists()
                                   .assert_Contains(custom_WebRoot);


            // check use of TM_FileStorage.Custom_Path_TM_Xml_Database

            TM_FileStorage.Custom_Path_XmlDatabase.assert_Null();

            TM_FileStorage.Custom_Path_XmlDatabase = 10.randomLetters();                       // with a random value
            tmFileStorage.set_Path_XmlDatabase()
            .path_XmlDatabase().assert_Is_Equal_To(path_XmlDatabase);                          // this value should not be changed

            var custom_Path_TM_Xml_Database = "Custom_Path_TM_Xml_Database".add_5_RandomLetters()
                                              .inTempDir()
                                              .assert_Folder_Doesnt_Exist();

            TM_FileStorage.Custom_Path_XmlDatabase = custom_Path_TM_Xml_Database;              // with a folder that doesn't exist

            tmFileStorage.set_Path_XmlDatabase()
            .path_XmlDatabase().assert_Is_Equal_To(path_XmlDatabase);                          // should still be unchanged

            custom_Path_TM_Xml_Database.createDir().assert_Folder_Exists();                    // create the folder
            tmFileStorage.set_Path_XmlDatabase()
            .path_XmlDatabase().assert_Is_Equal_To(custom_Path_TM_Xml_Database);               // and the value should be set

            Files.delete_Folder_Recursively(custom_Path_TM_Xml_Database).assert_True();
            Files.delete_Folder_Recursively(custom_WebRoot).assert_True();

            none.assert();
        }
Esempio n. 4
0
        [Test] 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();
        }
Esempio n. 5
0
        [Test] public void set_Path_XmlDatabase__In_Memory()
        {
            var tmFileStorage = new TM_FileStorage(false);
            var tmXmlDatabase = tmFileStorage.TMXmlDatabase;

            Assert.AreEqual(tmFileStorage, tmFileStorage.set_Path_XmlDatabase());
            Assert.AreEqual(tmXmlDatabase, TM_Xml_Database.Current);
            Assert.IsNull(tmFileStorage.path_XmlDatabase());
            Assert.IsFalse(tmXmlDatabase.usingFileStorage());

            var tmXmlDatabase2 = new TM_Xml_Database();

            Assert.AreNotEqual(tmXmlDatabase, tmXmlDatabase2, "A new tmXmlDatabase1 should had been created");
            Assert.AreEqual(tmXmlDatabase2, TM_Xml_Database.Current);
        }
Esempio n. 6
0
        [Test][Assert_Admin] public void set_Path_XmlDatabase__UsingFileStorage_On_Custom_WebRoot_without_Read_Privs()
        {
            admin.assert();

            var tmFileStorage = new TM_FileStorage(false);
            var tmXmlDatabase = tmFileStorage.TMXmlDatabase;

            var baseReadOnlyDir   = "_tmp_webRoot".tempDir();
            var webRootVirualPath = @"virtual/path";

            tmFileStorage.WebRoot = baseReadOnlyDir.pathCombine(webRootVirualPath).createDir();

            //Check that ensure we can write to baseReadOnlyDir
            Assert.IsTrue(baseReadOnlyDir.dirExists());
            Assert.IsTrue(tmFileStorage.WebRoot.dirExists());
            Assert.IsTrue(tmFileStorage.WebRoot.contains(baseReadOnlyDir));
            Assert.IsTrue(baseReadOnlyDir.canWriteToPath());
            Assert.AreEqual(tmFileStorage.WebRoot.parentFolder().parentFolder(), baseReadOnlyDir);

            //Now remote the write privileges for all users (on baseReadOnlyDir) while keeping  TM_Server.WebRoot writeable

            baseReadOnlyDir.directoryInfo().deny_Write_Users();
            tmFileStorage.WebRoot.directoryInfo().allow_Write_Users();

            Assert.IsFalse(baseReadOnlyDir.canWriteToPath());
            Assert.IsTrue(tmFileStorage.WebRoot.canWriteToPath());

            //Since baseReadOnlyDir can be written, creating an TM_Xml_Database should now default to the App_Data folder (which is on webRootVirualPath )

//            var tmXmlDatabase = new TM_Xml_Database().useFileStorage();

            tmFileStorage.set_Path_XmlDatabase();

            Assert.IsNotNull(tmFileStorage.path_XmlDatabase());

            none.assert();

            Assert.Ignore("TO FIX (Refactor Side Effect");
            Assert.IsTrue(tmFileStorage.path_XmlDatabase().contains("App_Data"));
            Assert.IsTrue(tmFileStorage.path_XmlDatabase().contains(tmFileStorage.WebRoot));
            Assert.IsTrue(tmFileStorage.path_XmlDatabase().contains(PublicDI.config.O2TempDir));

            //Finally re enable write so that we can delete the folder
            baseReadOnlyDir.directoryInfo().allow_Write_Users();
            Assert.IsTrue(baseReadOnlyDir.canWriteToPath());
            Files.deleteFolder(baseReadOnlyDir, true);
            Assert.IsFalse(baseReadOnlyDir.dirExists());
        }
Esempio n. 7
0
        [Test] public void set_WebRoot()
        {
            TM_FileStorage.Custom_WebRoot = null;
            var custom_WebRoot            = "Custom_WebRoot".tempDir().assert_Folder_Exists();
            var expected_Path_XmlDatabase = custom_WebRoot.pathCombine(@"App_Data\TeamMentor");

            UserRole.Admin.assert();

            TM_FileStorage.Custom_WebRoot.assert_Null();
            var tmFileStorage = new TM_FileStorage(loadData: false);

            tmFileStorage.webRoot().assert_Null();
            tmFileStorage.set_WebRoot();
            tmFileStorage.webRoot().assert_Not_Null()
            .assert_Equal(AppDomain.CurrentDomain.BaseDirectory);


            TM_FileStorage.Custom_WebRoot = custom_WebRoot;
            tmFileStorage.webRoot().assert_Equal(AppDomain.CurrentDomain.BaseDirectory)     // should still point to the AppDomain base directory
            .assert_Not_Equal(custom_WebRoot);

            tmFileStorage.using_Custom_WebRoot().assert_False();                            // this should only be true when the values match

            tmFileStorage.set_WebRoot()                                                     // set WebRoot
            .webRoot().assert_Equals(custom_WebRoot);                                       // and confirm its location

            tmFileStorage.using_Custom_WebRoot().assert_True();                             // now it should be true
            tmFileStorage.path_XmlDatabase().assert_Null();                                 // confirm that not set
            tmFileStorage.set_Path_XmlDatabase();                                           // this should set the TM_Xml_Database inside the Web_Root
            tmFileStorage.path_XmlDatabase().contains(custom_WebRoot);
            tmFileStorage.path_XmlDatabase().assert_Is_Equal_To(expected_Path_XmlDatabase); // check that the current Path_XmlDatabase matches the expected location


            //reset values
            TM_FileStorage.Custom_WebRoot = null;

            tmFileStorage.set_WebRoot()
            .webRoot().assert_Not_Equals(custom_WebRoot);

            Files.delete_Folder_Recursively(custom_WebRoot).assert_True();
            custom_WebRoot.assert_Folder_Doesnt_Exist();
        }
Esempio n. 8
0
        [Test] public void set_Path_XmlDatabase__UsingFileStorage_On_AppData__without_Read_Privs()
        {
            var tmFileStorage = new TM_FileStorage(false);
            var tmXmlDatabase = tmFileStorage.TMXmlDatabase;

            var baseReadOnlyDir   = "_tmp_webRoot".tempDir();
            var webRootVirualPath = @"site\wwwroot";        // simulates use of AppData

            tmFileStorage.WebRoot = baseReadOnlyDir.pathCombine(webRootVirualPath).createDir();

            tmFileStorage.WebRoot.directoryInfo().deny_CreateDirectories_Users();

            //var tmXmlDatabase = new TM_Xml_Database().useFileStorage();       // usually a true paramater will set UsingFileStorage to true

            tmFileStorage.set_Path_XmlDatabase();

            Assert.IsNull(tmFileStorage.path_XmlDatabase());       // if we can't write to the AppData folder then this value can't be set automatically
            Assert.IsFalse(tmXmlDatabase.usingFileStorage());      // and the offline mode (i.e. UsingFileStorage = false) should be activated
            Files.deleteFolder(baseReadOnlyDir, true);
            Assert.IsFalse(baseReadOnlyDir.dirExists());
        }