コード例 #1
0
        public void RulesNotPresent_Pass()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myfakerule.json"),
                FilePathExclusions = "none", //allow source under unittest path
                TestType           = "RulesNotPresent"
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;

            try
            {
                TagTestCommand command = new TagTestCommand(options);
                TagTestResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
                exitCode = TagTestResult.ExitCode.CriticalError;
            }

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.TestPassed);
        }
コード例 #2
0
        public void LogErrorLevel_Pass()
        {
            TagTestCommandOptions options = new TagTestCommandOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\nofilehere.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none", //allow source under unittest path
                LogFileLevel       = "error",
                LogFilePath        = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logerror.txt"),
            };

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

            Assert.IsTrue(exitCode == TagTestCommand.ExitCode.TestPassed);
        }
コード例 #3
0
        public void LogDebugLevel_Pass()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none", //allow source under unittest path
                LogFileLevel       = "debug",
                LogFilePath        = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logdebug.txt"),
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;
            try
            {
                TagTestCommand command = new TagTestCommand(options);
                TagTestResult  result  = command.GetResult();
                exitCode = result.ResultCode;

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

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.TestPassed);
        }
コード例 #4
0
        public void InvalidLogPath_Fail()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none", //allow source under unittest path
                LogFilePath        = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"baddir\logdebug.txt"),
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;
            try
            {
                TagTestCommand command = new TagTestCommand(options);
                TagTestResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
                exitCode = TagTestResult.ExitCode.CriticalError;
            }

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug?
        }
コード例 #5
0
        public void BasicZipReadDiff_Pass()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"zipped\main.zip"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none", //allow source under unittest path
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;
            try
            {
                TagTestCommand command = new TagTestCommand(options);
                TagTestResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
                exitCode = TagTestResult.ExitCode.CriticalError;
            }

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.TestPassed);
        }
コード例 #6
0
        public void RulesPresent_Fail()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myfakerule.json"),
                FilePathExclusions = "none", //allow source under unittest path
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;
            try
            {
                TagTestCommand command = new TagTestCommand(options);
                TagTestResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.TestFailed);
        }
コード例 #7
0
        public void InsecureLogPath_Fail()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none",
                LogFilePath        = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;
            try
            {
                TagTestCommand command = new TagTestCommand(options);
                TagTestResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
            }

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.CriticalError);
        }
コード例 #8
0
        public void NoConsoleOutput_Pass()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath            = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath       = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions    = "none",
                ConsoleVerbosityLevel = "none"
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;
            try
            {
                // Attempt to open output file.
                using (var writer = new StreamWriter(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"consoleout.txt")))
                {
                    // Redirect standard output from the console to the output file.
                    Console.SetOut(writer);

                    TagTestCommand command = new TagTestCommand(options);
                    TagTestResult  result  = command.GetResult();
                    exitCode = result.ResultCode;
                    try
                    {
                        string testContent = File.ReadAllText(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"consoleout.txt"));
                        if (String.IsNullOrEmpty(testContent))
                        {
                            exitCode = TagTestResult.ExitCode.TestPassed;
                        }
                        else
                        {
                            exitCode = TagTestResult.ExitCode.TestFailed;
                        }
                    }
                    catch (Exception)
                    {
                        exitCode = TagTestResult.ExitCode.TestPassed;//no console output file found
                    }
                }
            }
            catch (Exception)
            {
                exitCode = TagTestResult.ExitCode.CriticalError;
            }

            //reset to normal
            var standardOutput = new StreamWriter(Console.OpenStandardOutput());

            standardOutput.AutoFlush = true;
            Console.SetOut(standardOutput);

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.TestPassed);
        }
コード例 #9
0
        public void NoConsoleOutput_Pass()
        {
            TagTestCommandOptions options = new TagTestCommandOptions()
            {
                SourcePath            = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath       = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions    = "none",
                OutputFilePath        = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt"),
                ConsoleVerbosityLevel = "none"
            };

            TagTestCommand.ExitCode exitCode = TagTestCommand.ExitCode.CriticalError;
            try
            {
                // Attempt to open output file.
                using (var writer = new StreamWriter(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"consoleout.txt")))
                {
                    // Redirect standard output from the console to the output file.
                    Console.SetOut(writer);

                    TagTestCommand command = new TagTestCommand(options);
                    exitCode = (TagTestCommand.ExitCode)command.Run();
                    try
                    {
                        string testContent = File.ReadAllText(Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"consoleout.txt"));
                        if (String.IsNullOrEmpty(testContent))
                        {
                            exitCode = TagTestCommand.ExitCode.TestPassed;
                        }
                        else
                        {
                            exitCode = TagTestCommand.ExitCode.TestFailed;
                        }
                    }
                    catch (Exception)
                    {
                        exitCode = TagTestCommand.ExitCode.TestPassed;//no console output file found
                    }
                }
            }
            catch (Exception)
            {
                exitCode = TagTestCommand.ExitCode.CriticalError;
            }

            //reset to normal
            var standardOutput = new StreamWriter(Console.OpenStandardOutput());

            standardOutput.AutoFlush = true;
            Console.SetOut(standardOutput);

            Assert.IsTrue(exitCode == TagTestCommand.ExitCode.TestPassed);
        }
コード例 #10
0
        private static int RunTagTestCommand(CLITagTestCmdOptions cliOptions)
        {
            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;

            TagTestCommand command = new TagTestCommand(new TagTestOptions()
            {
                SourcePath            = cliOptions.SourcePath,
                CustomRulesPath       = cliOptions.CustomRulesPath,
                FilePathExclusions    = cliOptions.FilePathExclusions,
                TestType              = cliOptions.TestType,
                ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel,
                Log = cliOptions.Log
            });

            TagTestResult tagTestCommand = command.GetResult();

            exitCode = tagTestCommand.ResultCode;
            ResultsWriter.Write(tagTestCommand, cliOptions);

            return((int)exitCode);
        }
コード例 #11
0
        public void NoRules_Fail()
        {
            TagTestCommandOptions options = new TagTestCommandOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                FilePathExclusions = "none", //allow source under unittest path
            };

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

            Assert.IsTrue(exitCode == TagTestCommand.ExitCode.CriticalError);
        }
コード例 #12
0
        [Ignore]//occasional fail loading isharpzip lib for unknown reasons -todo to ensure only test related
        public void BasicZipReadDiff_Pass()
        {
            TagTestCommandOptions options = new TagTestCommandOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"zipped\main.zip"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none", //allow source under unittest path
            };

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

            Assert.IsTrue(exitCode == TagTestCommand.ExitCode.TestPassed);
        }
コード例 #13
0
        public void LogTraceLevel_Pass()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none", //allow source under unittest path
                LogFileLevel       = "trace",
                LogFilePath        = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logtrace.txt"),
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;
            try
            {
                TagTestCommand command = new TagTestCommand(options);
                TagTestResult  result  = command.GetResult();
                exitCode = result.ResultCode;

                string testLogContent = File.ReadAllText(options.LogFilePath);
                if (String.IsNullOrEmpty(testLogContent))
                {
                    exitCode = TagTestResult.ExitCode.CriticalError;
                }
                else if (testLogContent.ToLower().Contains("trace"))
                {
                    exitCode = TagTestResult.ExitCode.TestPassed;
                }
            }
            catch (Exception)
            {
                exitCode = TagTestResult.ExitCode.CriticalError;
            }

            //because these are static and each test is meant to be indpendent null assign the references to create the log
            WriteOnce.Log = null;
            Utils.Logger  = null;

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.TestPassed);
        }
コード例 #14
0
        public void RulesPresentNoResults_Fail()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none", //allow source under unittest path
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;
            try
            {
                TagTestCommand command = new TagTestCommand(options);
                TagTestResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.TestFailed);
        }
コード例 #15
0
        public void InsecureLogPath_Fail()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none",
                LogFilePath        = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;
            try
            {
                TagTestCommand command = new TagTestCommand(options);
                TagTestResult  result  = command.GetResult();
                exitCode = result.ResultCode;
            }
            catch (Exception)
            {
            }

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.CriticalError);
        }
コード例 #16
0
        public void InvalidLogPath_Fail()
        {
            TagTestCommandOptions options = new TagTestCommandOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none", //allow source under unittest path
                LogFilePath        = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"baddir\logdebug.txt"),
            };

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

            Assert.IsTrue(exitCode == TagTestCommand.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug?
        }
コード例 #17
0
        public void NoOutputSelected_Fail()
        {
            TagTestCommandOptions options = new TagTestCommandOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                CustomRulesPath    = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"),
                FilePathExclusions = "none",
                //OutputFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"output.txt"),
                ConsoleVerbosityLevel = "none" //together with no output file = no output at all which is a fail
            };

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

            Assert.IsTrue(exitCode == TagTestCommand.ExitCode.CriticalError);
        }