public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true) { ExportTagsResult exportTagsResult = (ExportTagsResult)result; //For console output, update write once for same results to console or file WriteOnce.TextWriter = TextWriter; if (exportTagsResult.TagsList.Count > 0) { WriteOnce.Result("Results"); foreach (string tag in exportTagsResult.TagsList) { WriteOnce.General(tag); } } else { WriteOnce.General("No tags found"); } if (autoClose) { FlushAndClose(); } }
public void LogErrorLevel_Pass() { ExportTagsOptions options = new ExportTagsOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"mybadrule.json"), LogFileLevel = "error", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logerror.txt"), }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.CriticalError; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.ExitCode)result.ResultCode; } catch (Exception) { string testLogContent = File.ReadAllText(options.LogFilePath); if (!String.IsNullOrEmpty(testLogContent) && testLogContent.ToLower().Contains("error")) { exitCode = ExportTagsResult.ExitCode.Success; } else { exitCode = ExportTagsResult.ExitCode.CriticalError; } } Assert.IsTrue(exitCode == ExportTagsResult.ExitCode.Success); }
public void LogDebugLevel_Pass() { ExportTagsOptions options = new ExportTagsOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), LogFileLevel = "debug", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logdebug.txt"), }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.CriticalError; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.ExitCode)result.ResultCode; string testLogContent = File.ReadAllText(options.LogFilePath); if (String.IsNullOrEmpty(testLogContent)) { exitCode = ExportTagsResult.ExitCode.CriticalError; } else if (testLogContent.ToLower().Contains("debug")) { exitCode = ExportTagsResult.ExitCode.Success; } } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == ExportTagsResult.ExitCode.Success); }
public void DefaultWithCustomRules_Pass() { ExportTagsOptions options = new ExportTagsOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.CriticalError; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.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 == ExportTagsResult.ExitCode.Success); }
public void NoDefaultNoCustomRules_Fail() { ExportTagsOptions options = new ExportTagsOptions() { IgnoreDefaultRules = true }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.CriticalError; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.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 == ExportTagsResult.ExitCode.CriticalError); }
public void InsecureLogPath_Fail() { ExportTagsOptions options = new ExportTagsOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp"), }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.CriticalError; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.ExitCode)result.ResultCode; } catch (Exception) { exitCode = ExportTagsResult.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 == ExportTagsResult.ExitCode.CriticalError); }
public void InvalidLogPath_Fail() { ExportTagsOptions options = new ExportTagsOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"baddir\logdebug.txt"), }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.Success; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.ExitCode)result.ResultCode; } catch (Exception) { exitCode = ExportTagsResult.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 == ExportTagsResult.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug? }
public void LogErrorLevel_Pass() { ExportTagsOptions options = new ExportTagsOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"mybadrule.json"), LogFileLevel = "error", LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"logerror.txt"), }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.CriticalError; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.ExitCode)result.ResultCode; } catch (Exception) { string testLogContent = File.ReadAllText(options.LogFilePath); if (!String.IsNullOrEmpty(testLogContent) && testLogContent.ToLower().Contains("error")) { exitCode = ExportTagsResult.ExitCode.Success; } else { exitCode = ExportTagsResult.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 == ExportTagsResult.ExitCode.Success); }
public override void WriteResults(Result result, CLICommandOptions commandOptions, bool autoClose = true) { if (TextWriter is null) { throw new ArgumentNullException(nameof(TextWriter)); } ExportTagsResult exportTagsResult = (ExportTagsResult)result; if (exportTagsResult.TagsList.Count > 0) { TextWriter.WriteLine("Results"); foreach (string tag in exportTagsResult.TagsList) { TextWriter.WriteLine(tag); } } else { TextWriter.WriteLine("No tags found"); } if (autoClose) { FlushAndClose(); } }
private static int RunExportTagsCommand(CLIExportTagsCmdOptions cliOptions) { ExportTagsCommand command = new(new ExportTagsOptions() { IgnoreDefaultRules = cliOptions.IgnoreDefaultRules, CustomRulesPath = cliOptions.CustomRulesPath, }, loggerFactory); ExportTagsResult exportTagsResult = command.GetResult(); ResultsWriter writer = new(loggerFactory); writer.Write(exportTagsResult, cliOptions); return((int)exportTagsResult.ResultCode); }
private static int RunExportTagsCommand(CLIExportTagsCmdOptions cliOptions) { ExportTagsCommand command = new(new ExportTagsOptions() { IgnoreDefaultRules = cliOptions.IgnoreDefaultRules, CustomRulesPath = cliOptions.CustomRulesPath, ConsoleVerbosityLevel = cliOptions.ConsoleVerbosityLevel, Log = cliOptions.Log }); ExportTagsResult exportTagsResult = command.GetResult(); ResultsWriter.Write(exportTagsResult, cliOptions); return((int)exportTagsResult.ResultCode); }
public void NoDefaultNoCustomRules_Fail() { ExportTagsOptions options = new ExportTagsOptions() { IgnoreDefaultRules = true }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.CriticalError; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.ExitCode)result.ResultCode; } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == ExportTagsResult.ExitCode.CriticalError); }
public void Export_Pass() { ExportTagsOptions options = new ExportTagsOptions() { //empty }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.CriticalError; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.ExitCode)result.ResultCode; } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == ExportTagsResult.ExitCode.Success); }
public void DefaultWithCustomRules_Pass() { ExportTagsOptions options = new ExportTagsOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.CriticalError; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.ExitCode)result.ResultCode; } catch (Exception) { //check for specific error if desired } Assert.IsTrue(exitCode == ExportTagsResult.ExitCode.Success); }
public void InsecureLogPath_Fail() { ExportTagsOptions options = new ExportTagsOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testSource), @"unzipped\simple\empty.cpp"), }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.CriticalError; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.ExitCode)result.ResultCode; } catch (Exception) { exitCode = ExportTagsResult.ExitCode.CriticalError; } Assert.IsTrue(exitCode == ExportTagsResult.ExitCode.CriticalError); }
public void InvalidLogPath_Fail() { ExportTagsOptions options = new ExportTagsOptions() { CustomRulesPath = Path.Combine(Helper.GetPath(Helper.AppPath.testRules), @"myrule.json"), LogFilePath = Path.Combine(Helper.GetPath(Helper.AppPath.testOutput), @"baddir\logdebug.txt"), }; ExportTagsResult.ExitCode exitCode = ExportTagsResult.ExitCode.Success; try { ExportTagsCommand command = new ExportTagsCommand(options); ExportTagsResult result = command.GetResult(); exitCode = (ExportTagsResult.ExitCode)result.ResultCode; } catch (Exception) { exitCode = ExportTagsResult.ExitCode.CriticalError; } Assert.IsTrue(exitCode == ExportTagsResult.ExitCode.CriticalError);//test fails even when values match unless this case run individually -mstest bug? }