예제 #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 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);
        }
        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);
        }
        public void NoRules_Fail()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                FilePathExclusions = "none", //allow source under unittest path
            };

            TagTestResult.ExitCode exitCode = TagTestResult.ExitCode.CriticalError;

            try
            {
                string args = string.Format(@"tagtest -s {0} -k none -l {1}",
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                                            Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"log.txt"));

                exitCode = (TagTestResult.ExitCode)Microsoft.ApplicationInspector.CLI.Program.Main(args.Split(' '));
            }
            catch (Exception)
            {
                //check for specific error if desired
            }

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.CriticalError);
        }
        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);
        }
        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);
        }
        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?
        }
        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 NoRules_Fail()
        {
            TagTestOptions options = new TagTestOptions()
            {
                SourcePath         = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"),
                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.CriticalError);
        }
        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);
        }
예제 #11
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;
            }

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.TestPassed);
        }
예제 #12
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);
        }
예제 #13
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;
            }

            Assert.IsTrue(exitCode == TagTestResult.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug?
        }
예제 #14
0
        public void RulesNotPresentNoResults_Success()
        {
            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"),
                TestType           = "RulesNotPresent",
                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.TestPassed);
        }