HasMessage() public method

Determines if the specified message exists in the log.
public HasMessage ( LogLevel level, string message ) : bool
level LogLevel Log level.
message string Log message.
return bool
示例#1
0
        public void ArrangeInvalidSourceFileTest()
        {
            TestLogger   logger       = new TestLogger();
            FileArranger fileArranger = new FileArranger(null, logger);

            bool success = fileArranger.Arrange(_testInvalidSourceFile, null);

            Assert.IsFalse(success, "Expected file to not be arranged succesfully.");
            Assert.IsTrue(logger.HasMessage(LogLevel.Verbose, "0 files written."));
        }
示例#2
0
        public void ArrangeSolutionTest()
        {
            TestLogger   logger       = new TestLogger();
            FileArranger fileArranger = new FileArranger(null, logger);

            bool success = fileArranger.Arrange(_testSolutionFile, null);

            Assert.IsTrue(success, "Expected file to be arranged succesfully.");
            Assert.IsTrue(
                logger.HasMessage(LogLevel.Verbose, "2 files written."),
                "Expected 2 files to be written. - " + logger.ToString());
        }
示例#3
0
        public void ArrangeUTF8EncodedSourceFileTest()
        {
            TestLogger   logger       = new TestLogger();
            FileArranger fileArranger = new FileArranger(null, logger);

            bool success = fileArranger.Arrange(_testUTF8File, null);

            Assert.IsTrue(success, "Expected file to be arranged succesfully. - " + logger.ToString());
            Assert.IsTrue(
                logger.HasMessage(LogLevel.Verbose, "1 files written."),
                "Expected 1 file to be written. - " + logger.ToString());

            string originalContents = GetTestFileContents("UTF8.cs", Encoding.UTF8);

            originalContents = originalContents.Replace("#endregion", "#endregion Fields");
            Assert.AreEqual(originalContents, File.ReadAllText(_testUTF8File, Encoding.UTF8), "File contents should have been preserved.");
        }
示例#4
0
        public void ArrangeReadOnlySourceFileTest()
        {
            TestLogger   logger       = new TestLogger();
            FileArranger fileArranger = new FileArranger(null, logger);

            File.SetAttributes(_testValidSourceFile1, FileAttributes.ReadOnly);

            try
            {
                bool success = fileArranger.Arrange(_testValidSourceFile1, null);

                Assert.IsFalse(success, "Expected file to not be arranged succesfully.");
                Assert.IsTrue(logger.HasMessage(LogLevel.Verbose, "0 files written."));
            }
            finally
            {
                File.SetAttributes(_testValidSourceFile1, FileAttributes.Normal);
            }
        }
        public void CodeWithMultilineAutoPropertyShouldBeFormatted()
        {
            var tmp = GetTempCSharpFile();
            try
            {
                File.WriteAllText(tmp, GetTestFileContents(_uglyCodeResourceName));
                TestLogger logger = new TestLogger();
                FileArranger fileArranger = new FileArranger(null, logger);

                bool success = fileArranger.Arrange(tmp, null);

                Assert.IsTrue(success, "Expected file to be arranged succesfully. - " + logger);
                Assert.IsTrue(
                    logger.HasMessage(LogLevel.Verbose, "1 files written."), "Expected 1 file to be written. - " + logger);

                string originalContents = GetTestFileContents(_prettyCodeResourceName);
                Assert.AreEqual(originalContents, File.ReadAllText(tmp), "File should have been formatted to look like the pretty code file.");
            }
            finally
            {
                File.Delete(tmp);
            }
        }
        public void CodeWithMultilinePropertyShouldNotBeFormatted()
        {
            var tmp = GetTempCSharpFile();
            try
            {
                File.WriteAllText(tmp, GetTestFileContents(_implementedPropertyResourceName));
                TestLogger logger = new TestLogger();
                FileArranger fileArranger = new FileArranger(null, logger);

                bool success = fileArranger.Arrange(tmp, null);

                Assert.IsTrue(success, "Expected file to be arranged succesfully. - " + logger);
                Assert.IsTrue(
                    logger.HasMessage(LogLevel.Verbose, "0 files written."), "Expected no file to be written. - " + logger);

                string originalContents = GetTestFileContents(_implementedPropertyResourceName);
                Assert.AreEqual(originalContents, File.ReadAllText(tmp), "File contents should have been preserved.");
            }
            finally
            {
                File.Delete(tmp);
            }
        }
示例#7
0
        public void ArrangeProjectFilteredTest()
        {
            CodeConfiguration filterProjectConfig = CodeConfiguration.Default.Clone() as CodeConfiguration;

            // Set up the filter
            FilterBy filter = new FilterBy();

            filter.Condition = "!($(File.Path) : '.Filtered.')";
            ((ProjectHandlerConfiguration)filterProjectConfig.Handlers[0]).ProjectExtensions[0].FilterBy = filter;

            string filterProjectConfigFile = Path.Combine(Path.GetTempPath(), "FilterProjectConfig.xml");

            try
            {
                filterProjectConfig.Save(filterProjectConfigFile);

                TestLogger   logger       = new TestLogger();
                FileArranger fileArranger = new FileArranger(filterProjectConfigFile, logger);

                bool success = fileArranger.Arrange(_testFilteredProjectFile, null);

                Assert.IsTrue(success, "Expected file to be arranged succesfully.");
                Assert.IsTrue(
                    logger.HasMessage(LogLevel.Verbose, "0 files written."),
                    "Expected 0 files to be written - " + logger.ToString());
            }
            finally
            {
                try
                {
                    File.Delete(filterProjectConfigFile);
                }
                catch
                {
                }
            }
        }
示例#8
0
        public void ArrangeDirectoryTest()
        {
            string testSourceParentDirectory = Path.Combine(Path.GetTempPath(), "TestSource");
            string testSourceChildDirectory = Path.Combine(testSourceParentDirectory, "Child");

            try
            {
                try
                {
                    Directory.CreateDirectory(testSourceParentDirectory);
                }
                catch
                {
                }

                try
                {
                    Directory.CreateDirectory(testSourceChildDirectory);
                }
                catch
                {
                }

                File.Copy(
                    _testValidSourceFile1,
                    Path.Combine(testSourceParentDirectory, Path.GetFileName(_testValidSourceFile1)),
                    true);

                File.Copy(
                    _testValidSourceFile2,
                    Path.Combine(testSourceParentDirectory, Path.GetFileName(_testValidSourceFile2)),
                    true);

                File.Copy(
                    _testValidSourceFile1,
                    Path.Combine(testSourceChildDirectory, Path.GetFileName(_testValidSourceFile1)),
                    true);

                File.Copy(
                    _testValidSourceFile2,
                    Path.Combine(testSourceChildDirectory, Path.GetFileName(_testValidSourceFile2)),
                    true);

                TestLogger logger = new TestLogger();
                FileArranger fileArranger = new FileArranger(null, logger);

                bool success = fileArranger.Arrange(testSourceParentDirectory, null);

                string log = logger.ToString();
                Assert.IsTrue(success, "Expected directory to be arranged succesfully - " + log);
                Assert.IsTrue(
                    logger.HasMessage(LogLevel.Verbose, "4 files written."),
                    "Expected 4 files to be written - " + log);
            }
            finally
            {
                try
                {
                    Directory.Delete(testSourceParentDirectory, true);
                }
                catch
                {
                }
            }
        }
示例#9
0
        public void ArrangeSingleSourceFileOutputTest()
        {
            string tempFile = Path.GetTempFileName();

            try
            {
                TestLogger logger = new TestLogger();
                string originalText = File.ReadAllText(_testValidSourceFile1);

                bool success = Arrange(logger, _testValidSourceFile1, tempFile);

                string postText = File.ReadAllText(_testValidSourceFile1);

                Assert.AreEqual(originalText, postText, "Original file should not have been modified.");

                Assert.IsTrue(File.Exists(tempFile), "Output file was not created.");
                string arrangedText = File.ReadAllText(tempFile);
                Assert.IsTrue(arrangedText.Length > 0, "Output file is empty.");
                Assert.AreNotEqual(originalText, arrangedText, "File was not arranged.");

                Assert.IsTrue(success, "Expected file to be arranged succesfully.");
                Assert.IsTrue(logger.HasMessage(LogLevel.Verbose, "1 files written."));
            }
            finally
            {
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
            }
        }
示例#10
0
        public void ArrangeReadOnlySourceFileTest()
        {
            TestLogger logger = new TestLogger();
            FileArranger fileArranger = new FileArranger(null, logger);

            File.SetAttributes(_testValidSourceFile1, FileAttributes.ReadOnly);

            try
            {
                bool success = fileArranger.Arrange(_testValidSourceFile1, null);

                Assert.IsFalse(success, "Expected file to not be arranged succesfully.");
                Assert.IsTrue(logger.HasMessage(LogLevel.Verbose, "0 files written."));
            }
            finally
            {
                File.SetAttributes(_testValidSourceFile1, FileAttributes.Normal);
            }
        }
示例#11
0
        public void ArrangeProjectFilteredTest()
        {
            CodeConfiguration filterProjectConfig = CodeConfiguration.Default.Clone() as CodeConfiguration;

            // Set up the filter
            FilterBy filter = new FilterBy();
            filter.Condition = "!($(File.Path) : '.Filtered.')";
            ((ProjectHandlerConfiguration)filterProjectConfig.Handlers[0]).ProjectExtensions[0].FilterBy = filter;

            string filterProjectConfigFile = Path.Combine(Path.GetTempPath(), "FilterProjectConfig.xml");

            try
            {
                filterProjectConfig.Save(filterProjectConfigFile);

                TestLogger logger = new TestLogger();
                FileArranger fileArranger = new FileArranger(filterProjectConfigFile, logger);

                bool success = fileArranger.Arrange(_testFilteredProjectFile, null);

                Assert.IsTrue(success, "Expected file to be arranged succesfully.");
                Assert.IsTrue(
                    logger.HasMessage(LogLevel.Verbose, "0 files written."),
                    "Expected 0 files to be written - " + logger.ToString());
            }
            finally
            {
                try
                {
                    File.Delete(filterProjectConfigFile);
                }
                catch
                {
                }
            }
        }
示例#12
0
        public void ArrangeInvalidSourceFileTest()
        {
            TestLogger logger = new TestLogger();
            FileArranger fileArranger = new FileArranger(null, logger);

            bool success = fileArranger.Arrange(_testInvalidSourceFile, null);

            Assert.IsFalse(success, "Expected file to not be arranged succesfully.");
            Assert.IsTrue(logger.HasMessage(LogLevel.Verbose, "0 files written."));
        }
示例#13
0
        public void ArrangeDirectoryEmptyTest()
        {
            string testSourceParentDirectory = Path.Combine(Path.GetTempPath(), "TestSource");

            try
            {
                try
                {
                    Directory.CreateDirectory(testSourceParentDirectory);
                }
                catch
                {
                }

                TestLogger logger = new TestLogger();
                bool success = Arrange(logger, testSourceParentDirectory);

                string log = logger.ToString();
                Assert.IsTrue(success, "Expected directory to be arranged succesfully - " + log);
                Assert.IsTrue(
                    logger.HasMessage(LogLevel.Verbose, "0 files written."),
                    "Expected 0 files to be written - " + log);
            }
            finally
            {
                try
                {
                    Directory.Delete(testSourceParentDirectory, true);
                }
                catch
                {
                }
            }
        }
示例#14
0
        public void RestoreUnknownTest()
        {
            TestLogger logger = new TestLogger();

            bool success = Arrange(logger, Guid.NewGuid().ToString(), "/r");
            Assert.IsFalse(success, "Expected file to not be restored succesfully.");
            Assert.IsTrue(logger.HasMessage(LogLevel.Error, "Restore failed"));
        }
示例#15
0
        public void ArrangeSingleSourceFileTest()
        {
            TestLogger logger = new TestLogger();

            string originalText = File.ReadAllText(_testValidSourceFile1);

            bool success = Arrange(logger, _testValidSourceFile1);

            Assert.IsTrue(success, "Expected file to be arranged succesfully.");
            Assert.IsTrue(logger.HasMessage(LogLevel.Verbose, "1 files written."));

            string arrangedText = File.ReadAllText(_testValidSourceFile1);
            Assert.IsTrue(arrangedText.Length > 0, "File is empty.");
            Assert.AreNotEqual(originalText, arrangedText, "File was not arranged.");
        }
示例#16
0
        public void ArrangeDirectoryTest()
        {
            string testSourceParentDirectory = Path.Combine(Path.GetTempPath(), "TestSource");
            string testSourceChildDirectory  = Path.Combine(testSourceParentDirectory, "Child");

            try
            {
                try
                {
                    Directory.CreateDirectory(testSourceParentDirectory);
                }
                catch
                {
                }

                try
                {
                    Directory.CreateDirectory(testSourceChildDirectory);
                }
                catch
                {
                }

                File.Copy(
                    _testValidSourceFile1,
                    Path.Combine(testSourceParentDirectory, Path.GetFileName(_testValidSourceFile1)),
                    true);

                File.Copy(
                    _testValidSourceFile2,
                    Path.Combine(testSourceParentDirectory, Path.GetFileName(_testValidSourceFile2)),
                    true);

                File.Copy(
                    _testValidSourceFile1,
                    Path.Combine(testSourceChildDirectory, Path.GetFileName(_testValidSourceFile1)),
                    true);

                File.Copy(
                    _testValidSourceFile2,
                    Path.Combine(testSourceChildDirectory, Path.GetFileName(_testValidSourceFile2)),
                    true);

                TestLogger   logger       = new TestLogger();
                FileArranger fileArranger = new FileArranger(null, logger);

                bool success = fileArranger.Arrange(testSourceParentDirectory, null);

                string log = logger.ToString();
                Assert.IsTrue(success, "Expected directory to be arranged succesfully - " + log);
                Assert.IsTrue(
                    logger.HasMessage(LogLevel.Verbose, "4 files written."),
                    "Expected 4 files to be written - " + log);
            }
            finally
            {
                try
                {
                    Directory.Delete(testSourceParentDirectory, true);
                }
                catch
                {
                }
            }
        }
示例#17
0
        public void ArrangeSolutionTest()
        {
            TestLogger logger = new TestLogger();
            FileArranger fileArranger = new FileArranger(null, logger);

            bool success = fileArranger.Arrange(_testSolutionFile, null);

            Assert.IsTrue(success, "Expected file to be arranged succesfully.");
            Assert.IsTrue(
                logger.HasMessage(LogLevel.Verbose, "2 files written."),
                "Expected 2 files to be written. - " + logger.ToString());
        }
示例#18
0
        public void ArrangeUTF8EncodedSourceFileTest()
        {
            TestLogger logger = new TestLogger();
            FileArranger fileArranger = new FileArranger(null, logger);

            bool success = fileArranger.Arrange(_testUTF8File, null);

            Assert.IsTrue(success, "Expected file to be arranged succesfully. - " + logger.ToString());
            Assert.IsTrue(
                logger.HasMessage(LogLevel.Verbose, "1 files written."),
                "Expected 1 file to be written. - " + logger.ToString());

            string originalContents = GetTestFileContents("UTF8.cs", Encoding.UTF8);
            originalContents = originalContents.Replace("#endregion", "#endregion Fields");
            Assert.AreEqual(originalContents, File.ReadAllText(_testUTF8File, Encoding.UTF8), "File contents should have been preserved.");
        }
示例#19
0
        public void ArrangeMSBuildSolutionTest()
        {
            TestLogger logger = new TestLogger();

            bool success = Arrange(logger, _testMSBuildSolutionFile);

            Assert.IsTrue(success, "Expected file to be arranged succesfully - {0}", logger.ToString());
            Assert.IsTrue(logger.HasMessage(LogLevel.Verbose, "2 files written."), logger.ToString());
        }