public void LogDebugLevel_Pass()
        {
            ExportTagsCommandOptions options = new ExportTagsCommandOptions()
            {
                CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                LogFileLevel    = "debug",
                LogFilePath     = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logdebug.txt"),
            };

            ExportTagsCommand.ExitCode exitCode = ExportTagsCommand.ExitCode.CriticalError;
            try
            {
                ExportTagsCommand command = new ExportTagsCommand(options);
                exitCode = (ExportTagsCommand.ExitCode)command.Run();
                string testLogContent = File.ReadAllText(options.LogFilePath);
                if (String.IsNullOrEmpty(testLogContent))
                {
                    exitCode = ExportTagsCommand.ExitCode.CriticalError;
                }
                else if (testLogContent.ToLower().Contains("debug"))
                {
                    exitCode = ExportTagsCommand.ExitCode.Success;
                }
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == ExportTagsCommand.ExitCode.Success);
        }
        public void LogErrorLevel_Pass()
        {
            ExportTagsCommandOptions options = new ExportTagsCommandOptions()
            {
                CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"mybadrule.json"),
                LogFileLevel    = "error",
                LogFilePath     = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logerror.txt"),
            };

            ExportTagsCommand.ExitCode exitCode = ExportTagsCommand.ExitCode.CriticalError;
            try
            {
                ExportTagsCommand command = new ExportTagsCommand(options);
                exitCode = (ExportTagsCommand.ExitCode)command.Run();
            }
            catch (Exception e)
            {
                string testLogContent = File.ReadAllText(options.LogFilePath);
                if (!String.IsNullOrEmpty(testLogContent) && testLogContent.ToLower().Contains("error"))
                {
                    exitCode = ExportTagsCommand.ExitCode.Success;
                }
                else
                {
                    exitCode = ExportTagsCommand.ExitCode.CriticalError;
                }
            }

            Assert.IsTrue(exitCode == ExportTagsCommand.ExitCode.Success);
        }
Ejemplo n.º 3
0
        private static int RunExportTagsCommand(ExportTagsCommandOptions opts)
        {
            Logger        = Utils.SetupLogging(opts);
            WriteOnce.Log = Logger;
            opts.Log      = Logger;

            return(new ExportTagsCommand(opts).Run());
        }
        public void DefaultWithCustomRules_Pass()
        {
            ExportTagsCommandOptions options = new ExportTagsCommandOptions()
            {
                CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
            };

            ExportTagsCommand.ExitCode exitCode = ExportTagsCommand.ExitCode.CriticalError;
            try
            {
                ExportTagsCommand command = new ExportTagsCommand(options);
                exitCode = (ExportTagsCommand.ExitCode)command.Run();
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == ExportTagsCommand.ExitCode.Success);
        }
        public void NoDefaultNoCustomRules_Fail()
        {
            ExportTagsCommandOptions options = new ExportTagsCommandOptions()
            {
                IgnoreDefaultRules = true
            };

            ExportTagsCommand.ExitCode exitCode = ExportTagsCommand.ExitCode.CriticalError;
            try
            {
                ExportTagsCommand command = new ExportTagsCommand(options);
                exitCode = (ExportTagsCommand.ExitCode)command.Run();
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == ExportTagsCommand.ExitCode.CriticalError);
        }
        public void ExportToFile_Fail()
        {
            ExportTagsCommandOptions options = new ExportTagsCommandOptions()
            {
                OutputFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"baddir\exporttags.txt")
            };

            ExportTagsCommand.ExitCode exitCode = ExportTagsCommand.ExitCode.CriticalError;
            try
            {
                ExportTagsCommand command = new ExportTagsCommand(options);
                exitCode = (ExportTagsCommand.ExitCode)command.Run();
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == ExportTagsCommand.ExitCode.CriticalError);
        }
        public void Export_Pass()
        {
            ExportTagsCommandOptions options = new ExportTagsCommandOptions()
            {
                //empty
            };

            ExportTagsCommand.ExitCode exitCode = ExportTagsCommand.ExitCode.CriticalError;
            try
            {
                ExportTagsCommand command = new ExportTagsCommand(options);
                exitCode = (ExportTagsCommand.ExitCode)command.Run();
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == ExportTagsCommand.ExitCode.Success);
        }
        [Ignore]//another faulty fail that passes when run individually...MSTest flaw?
        public void InsecureLogPath_Fail()
        {
            ExportTagsCommandOptions options = new ExportTagsCommandOptions()
            {
                CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                LogFilePath     = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
            };

            ExportTagsCommand.ExitCode exitCode = ExportTagsCommand.ExitCode.CriticalError;
            try
            {
                ExportTagsCommand command = new ExportTagsCommand(options);
                exitCode = (ExportTagsCommand.ExitCode)command.Run();
            }
            catch (Exception)
            {
                exitCode = ExportTagsCommand.ExitCode.CriticalError;
            }

            Assert.IsTrue(exitCode == ExportTagsCommand.ExitCode.CriticalError);
        }
        public void InvalidLogPath_Fail()
        {
            ExportTagsCommandOptions options = new ExportTagsCommandOptions()
            {
                CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                LogFilePath     = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"baddir\logdebug.txt"),
            };

            ExportTagsCommand.ExitCode exitCode = ExportTagsCommand.ExitCode.CriticalError;
            try
            {
                ExportTagsCommand command = new ExportTagsCommand(options);
                exitCode = (ExportTagsCommand.ExitCode)command.Run();
            }
            catch (Exception)
            {
                exitCode = ExportTagsCommand.ExitCode.CriticalError;
            }

            Assert.IsTrue(exitCode == ExportTagsCommand.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug?
        }
Ejemplo n.º 10
0
 private static int RunExportTagsCommand(ExportTagsCommandOptions opts)
 {
     SetupLogging(opts);
     return(new ExportTagsCommand(opts).Run());
 }