コード例 #1
0
        public void LogMgrShouldCorrectlyHandleInitializeToDifferentLogger()
        {
            var dir1Dto = new DirectoryDto(".\\logdir");

            DirectoryHelper.DeleteADirectory(dir1Dto);

            var fileStamp = DateHelper.NowYearMthDayHrsSecs();

            var defaultLogFileBaseName = ".\\logdir\\installLog.log";

            var mgr = new ConsoleCommandLogMgr(defaultLogFileBaseName,
                                                fileStamp,
                                                    string.Empty);

            Assert.IsTrue(mgr.DefaultConsoleLogPathFileBaseName == defaultLogFileBaseName);

            Assert.IsTrue(mgr.CurrentConsoleLogPathFileBaseName == defaultLogFileBaseName);

            var newLogFileBaseName = ".\\logdir\\install2Log.log";

            mgr.InitializeCmdConsoleLog(newLogFileBaseName);

            Assert.IsTrue(mgr.DefaultConsoleLogPathFileBaseName == defaultLogFileBaseName);

            Assert.IsTrue(mgr.CurrentConsoleLogPathFileBaseName == newLogFileBaseName);

            mgr.Dispose();

            DirectoryHelper.DeleteADirectory(dir1Dto);
        }
コード例 #2
0
        public void WriteLinesToTwoLoggers()
        {
            var dir1Dto = new DirectoryDto(".\\logdir");

            DirectoryHelper.DeleteADirectory(dir1Dto);

            var fileStamp = DateHelper.NowYearMthDayHrsSecs();

            var mgr = new ConsoleCommandLogMgr(".\\logdir\\installLog.log",
                                                fileStamp,
                                                    string.Empty);

            var currWrkDir = TestDirectories.GetTestExeDir();
            var subDir = "\\logdir\\installLog" + "_" + fileStamp + ".log";
            var expectedResult = FileHelper.CombineDirSubDirWithFile(currWrkDir, subDir);

            mgr.InitializeCmdConsoleLog(string.Empty);

            var textOutput = "Hello World!";
            mgr.LogWriteLine(textOutput);
            var expectedText = textOutput + Environment.NewLine;

            mgr.LogFlushStreamWriter();

            StreamReader sReader = null;
            var sb = new StringBuilder();
            FileStream fStream = null;
            try
            {

                fStream = new FileStream(expectedResult.FileXinfo.FullName,
                    FileMode.Open,
                    FileAccess.Read,
                    FileShare.ReadWrite);

                sReader = new StreamReader(fStream);
                sb.Append(sReader.ReadToEnd());
            }
            catch (Exception ex)
            {
                // ReSharper disable once UnusedVariable
                var x = ex.Message;

            }
            finally
            {
                if (sReader != null)
                {
                    sReader.Close();
                    sReader.Dispose();
                    sReader = null;
                }

                if (fStream != null)
                {
                    fStream.Close();
                    fStream.Dispose();
                    fStream = null;
                }
            }
            var result = sb.ToString();

            Assert.IsTrue(result == expectedText);

            subDir = ".\\logdir\\installLog2" + "_" + fileStamp + ".log";
            var baseFile = ".\\logdir\\installLog2" +".log";
            expectedResult = FileHelper.CombineDirSubDirWithFile(currWrkDir, subDir);

            mgr.InitializeCmdConsoleLog(baseFile);
            textOutput = "Hello2 World!";
            mgr.LogWriteLine(textOutput);
            expectedText = textOutput + Environment.NewLine;
            mgr.LogFlushStreamWriter();
            sb = new StringBuilder();

            try
            {
                fStream = new FileStream(expectedResult.FileXinfo.FullName,
                    FileMode.Open,
                    FileAccess.Read,
                    FileShare.ReadWrite);

                sReader = new StreamReader(fStream);
                sb.Append(sReader.ReadToEnd());
            }
            catch(Exception ex)
            {
                // ReSharper disable once UnusedVariable
                var y = ex.Message;
            }
            finally
            {
                if (sReader != null)
                {
                    sReader.Close();
                    sReader.Dispose();
                }

                if (fStream != null)
                {
                    fStream.Close();
                    fStream.Dispose();
                }

            }

            result = sb.ToString();
            mgr.Dispose();
            DirectoryHelper.DeleteADirectory(dir1Dto);

            Assert.IsTrue(result == expectedText);
        }
コード例 #3
0
        public void WriteTextLinesToLogMgr()
        {
            var dir1Dto = new DirectoryDto(".\\logdir");

            DirectoryHelper.DeleteADirectory(dir1Dto);

            var fileStamp = DateHelper.NowYearMthDayHrsSecs();

            var mgr = new ConsoleCommandLogMgr(".\\logdir\\installLog.log",
                                                fileStamp,
                                                    string.Empty);

            var currWrkDir = TestDirectories.GetTestExeDir();
            var subDir = "\\logdir\\installLog" + "_" + fileStamp + ".log";
            var expectedResult = FileHelper.CombineDirSubDirWithFile(currWrkDir, subDir);

            mgr.InitializeCmdConsoleLog(string.Empty);

            var textOutput = "Hello World!";
            mgr.LogWriteLine(textOutput);
            var expectedText = textOutput+ Environment.NewLine;

            mgr.LogFlushStreamWriter();

            mgr.Dispose();

            StreamReader sReader = null;
            var sb = new StringBuilder();

            try
            {
                sReader = new StreamReader(expectedResult.FileXinfo.FullName);
                sb.Append(sReader.ReadToEnd());
                sReader.Close();
                sReader.Dispose();
            }
            catch
            {
                if (sReader != null)
                {
                    sReader.Close();
                    sReader.Dispose();
                }

                Assert.IsTrue(false);
            }
            var result = sb.ToString();

            DirectoryHelper.DeleteADirectory(dir1Dto);

            Assert.IsTrue(result == expectedText);
        }