コード例 #1
0
        public static List <AppHomeFolder.CreationResults> BootstrapWrapperForTests()
        {
            String v_PathToStandardFolder = Environment.GetFolderPath(
                Environment.SpecialFolder.ApplicationData)
                                            + Path.DirectorySeparatorChar
                                            + VersionWrapper.NameCalling
                                            + "Test"
                                            + Path.DirectorySeparatorChar;

            AppHomeFolder.CreationResults v_Result = AppHomeFolder.TestAndCreateHomeFolder(v_PathToStandardFolder);
            List <String> v_FilesToCopy            = new List <string>()
            {
                "log4netConfig", "TestEmptyDbPlayer.xml"
            };
            List <AppHomeFolder.CreationResults> v_ResultsFromResourceCopy = AppHomeFolder.CopyStaticResources(v_FilesToCopy, v_PathToStandardFolder);

            Console.WriteLine("BootstrapWrapperForTests results:");

            foreach (AppHomeFolder.CreationResults i_Result in v_ResultsFromResourceCopy)
            {
                Console.WriteLine("  * " + i_Result);
            }

            XmlConfigurator.Configure(new FileInfo(v_PathToStandardFolder + "log4netConfig"));
            LogManager.GetLogger("BootstrapWrapperForTests").Info("BootstrapWrapperForTests successfully started the logger.");


            return(new List <AppHomeFolder.CreationResults> {
                AppHomeFolder.CreationResults.Error
            });
        }
コード例 #2
0
        /// <summary>
        /// This function will create %APPDATA%\ProductName and copy the logging configuration if it does not exist.
        /// </summary>
        /// <returns>A AppHomeFolder.CreationResults element. Copied if the file was not in the expected folder,
        /// Exists if the file was already there and Error if something went wrong.</returns>
        public static List <AppHomeFolder.CreationResults> BootstrapWrapper()
        {
            String v_PathToStandardFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
                                            + Path.DirectorySeparatorChar
                                            + VersionWrapper.NameCalling
                                            + Path.DirectorySeparatorChar;

            AppHomeFolder.CreationResults v_Result = AppHomeFolder.TestAndCreateHomeFolder(v_PathToStandardFolder);
            List <String> v_FilesToCopy            = new List <string>()
            {
                "log4netConfig", "bgldb.xml", "DemoDB.xml"
            };
            List <AppHomeFolder.CreationResults> v_ResultsFromResourceCopy = AppHomeFolder.CopyStaticResources(v_FilesToCopy, v_PathToStandardFolder);

            Console.WriteLine("BootstrapWrapper result: " + v_ResultsFromResourceCopy[0]);
            XmlConfigurator.Configure(new FileInfo(v_PathToStandardFolder + "log4netConfig"));
            LogManager.GetLogger("StandardFileBootstrapper").Info("Bootstrapper successfully started the logger: " + v_ResultsFromResourceCopy[0]);

            return(v_ResultsFromResourceCopy);
        }
コード例 #3
0
        public void InitEnvironmentTest()
        {
            List <AppHomeFolder.CreationResults> v_BootStrapResult = StandardFileBootstrapper.BootstrapWrapper();
            bool v_IsCreatedOrCopied = true;

            foreach (AppHomeFolder.CreationResults i_Result in v_BootStrapResult)
            {
                v_IsCreatedOrCopied &= i_Result == AppHomeFolder.CreationResults.Exists || i_Result == AppHomeFolder.CreationResults.Copied;
            }

            Assert.IsTrue(v_IsCreatedOrCopied);
            m_Logger = LogManager.GetLogger("AppHomeFolderTests");

            // First delete all files and dirs from earlier test run (if there are any).
            if (Directory.Exists(m_TestFilePath))
            {
                Directory.Delete(m_TestFilePath, true);
                Console.WriteLine("DOES exist. " + m_TestFilePath);
            }
            else
            {
                Console.WriteLine("Does NOT exist.");
            }

            // First call creates the directory.
            AppHomeFolder.CreationResults v_Result = AppHomeFolder.TestAndCreateHomeFolder(m_TestFilePath);
            Assert.AreEqual(AppHomeFolder.CreationResults.Created, v_Result);

            // Second call reports existing directory.
            v_Result = AppHomeFolder.TestAndCreateHomeFolder(m_TestFilePath);
            Assert.AreEqual(AppHomeFolder.CreationResults.Exists, v_Result);

            m_Logger.Debug(VersionWrapper.NameExecuting);

            List <String> v_FilesToCopy = new List <string>()
            {
                "log4netConfig"
            };

            // Copy the file to the empty folder.
            List <AppHomeFolder.CreationResults> v_ResultsFromResourceCopy = AppHomeFolder.CopyStaticResources(v_FilesToCopy, m_TestFilePath);

            Assert.AreEqual(new List <AppHomeFolder.CreationResults>()
            {
                AppHomeFolder.CreationResults.Copied
            }, v_ResultsFromResourceCopy);

            // Calling the same again will tell us that the file was already there.
            v_ResultsFromResourceCopy = AppHomeFolder.CopyStaticResources(v_FilesToCopy, m_TestFilePath);
            Assert.AreEqual(new List <AppHomeFolder.CreationResults>()
            {
                AppHomeFolder.CreationResults.Exists
            }, v_ResultsFromResourceCopy);

            // Files which don't exist will report an error.
            v_ResultsFromResourceCopy = AppHomeFolder.CopyStaticResources(new List <string>()
            {
                "invalidFileName.txt", "log4netConfig", "i3.txt"
            }, m_TestFilePath);
            Assert.AreEqual(new List <AppHomeFolder.CreationResults>()
            {
                AppHomeFolder.CreationResults.Error, AppHomeFolder.CreationResults.Exists, AppHomeFolder.CreationResults.Error
            }, v_ResultsFromResourceCopy);

            Directory.Delete(m_TestFilePath, true);
        }