public void CustomRules_Pass() { VerifyRulesOptions options = new VerifyRulesOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), }; VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError; try { VerifyRulesCommand command = new VerifyRulesCommand(options); VerifyRulesResult 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 == VerifyRulesResult.ExitCode.Verified); }
[Ignore] //default option won't find rules unless run from CLI; todo to look at addressed public void DefaultRules_Pass() { VerifyRulesOptions options = new VerifyRulesOptions() { VerifyDefaultRules = true }; VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError; try { VerifyRulesCommand command = new VerifyRulesCommand(options); VerifyRulesResult 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 == VerifyRulesResult.ExitCode.Verified); }
public void InsecureLogPath_Fail() { VerifyRulesOptions options = new VerifyRulesOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp") }; VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError; try { VerifyRulesCommand command = new VerifyRulesCommand(options); VerifyRulesResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { exitCode = VerifyRulesResult.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 == VerifyRulesResult.ExitCode.CriticalError); }
public void InvalidLogPath_Fail() { VerifyRulesOptions options = new VerifyRulesOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"baddir\logdebug.txt"), }; VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError; try { VerifyRulesCommand command = new VerifyRulesCommand(options); VerifyRulesResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { exitCode = VerifyRulesResult.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 == VerifyRulesResult.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug? }
public void LogErrorLevel_Pass() { VerifyRulesOptions options = new VerifyRulesOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"mybadrule.json"), LogFileLevel = "error", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logerror.txt"), }; VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError; try { VerifyRulesCommand command = new VerifyRulesCommand(options); VerifyRulesResult result = command.GetResult(); exitCode = result.ResultCode; } catch (Exception) { string testLogContent = File.ReadAllText(options.LogFilePath); if (!String.IsNullOrEmpty(testLogContent) && testLogContent.ToLower().Contains("error")) { exitCode = VerifyRulesResult.ExitCode.Verified; } else { exitCode = VerifyRulesResult.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 == VerifyRulesResult.ExitCode.Verified); }
private static int RunVerifyRulesCommand(CLIVerifyRulesCmdOptions cliOptions) { VerifyRulesResult.ExitCode exitCode = VerifyRulesResult.ExitCode.CriticalError; VerifyRulesCommand command = new VerifyRulesCommand(new VerifyRulesOptions() { VerifyDefaultRules = cliOptions.VerifyDefaultRules, CustomRulesPath = cliOptions.CustomRulesPath, ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel, Failfast = cliOptions.Failfast, Log = cliOptions.Log }); VerifyRulesResult exportTagsResult = command.GetResult(); exitCode = exportTagsResult.ResultCode; ResultsWriter.Write(exportTagsResult, cliOptions); return((int)exitCode); }