public void LogDebugLevel_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", //allow source under unittest path LogFileLevel = "debug", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logdebug.txt"), }; TagTestCommand.ExitCode exitCode = TagTestCommand.ExitCode.CriticalError; try { TagTestCommand command = new TagTestCommand(options); exitCode = (TagTestCommand.ExitCode)command.Run(); string testLogContent = File.ReadAllText(options.LogFilePath); if (String.IsNullOrEmpty(testLogContent)) { exitCode = TagTestCommand.ExitCode.CriticalError; } else if (testLogContent.ToLower().Contains("debug")) { exitCode = TagTestCommand.ExitCode.TestPassed; } } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == TagTestCommand.ExitCode.TestPassed); }
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); }
private static int RunTagTestCommand(TagTestCommandOptions opts) { Logger = Utils.SetupLogging(opts); WriteOnce.Log = Logger; opts.Log = Logger; return(new TagTestCommand(opts).Run()); }
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); }
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); }
[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); }
[Ignore]//another faulty fail that passes when run individually...MSTest flaw? public void InsecureLogPath_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", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\main.cpp"), }; 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); }
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? }
public void RulesNotPresentNoResults_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"), TestType = "RulesNotPresent", 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.TestFailed); }
public void RulesNotPresent_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), @"myfakerule.json"), FilePathExclusions = "none", //allow source under unittest path TestType = "RulesNotPresent" }; 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.TestPassed); }
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); }
private static int RunTagTestCommand(TagTestCommandOptions opts) { SetupLogging(opts); return(new TagTestCommand(opts).Run()); }