public void TestCustomCollectionPathsNoFormatType() { Arguments arg = new Arguments(new [] { "-c", "test.txt" }); List <string> addtlPaths = new List <string>(); List <string> paths = new List <string>(); string sep = "/"; var userProfile = Environment.ExpandEnvironmentVariables("%HOME%"); var logger = new CyLR.Logger(); logger.LoggingOptions["output_file_path"] = "4.log"; logger.Setup(); if (!Platform.IsUnixLike()) { sep = "\\"; userProfile = Environment.ExpandEnvironmentVariables("%USERPROFILE%"); } paths.Add(userProfile + sep + "not_a_filename___"); using (StreamWriter sr = new StreamWriter("test.txt")) { sr.WriteLine("\t" + userProfile + sep + "not_a_filename___"); sr.WriteLine("force " + userProfile + sep + "not_a_filename___"); } var cPaths = CollectionPaths.GetPaths(arg, addtlPaths, false, logger); paths.Sort(); cPaths.Sort(); Assert.NotEqual(paths, cPaths); Assert.Empty(cPaths); }
public void TestLoggerLevelConfigs() { var logger = new CyLR.Logger(); // Defaults logger.Setup(); Assert.Equal(CyLR.Logger.Level.trace, logger.fileLevel); Assert.Equal(CyLR.Logger.Level.info, logger.consoleLevel); logger.TearDown(); // Warn and Error logger.LoggingOptions["output_file_min_level"] = "warn"; logger.LoggingOptions["output_console_min_level"] = "error"; logger.Setup(); Assert.Equal(CyLR.Logger.Level.warn, logger.fileLevel); Assert.Equal(CyLR.Logger.Level.error, logger.consoleLevel); logger.TearDown(); // Error and Warn logger.LoggingOptions["output_file_min_level"] = "error"; logger.LoggingOptions["output_console_min_level"] = "warn"; logger.Setup(); Assert.Equal(CyLR.Logger.Level.error, logger.fileLevel); Assert.Equal(CyLR.Logger.Level.warn, logger.consoleLevel); // Test each of the levels for both output formats List <CyLR.Logger.Level> levels = new List <CyLR.Logger.Level> { CyLR.Logger.Level.trace, CyLR.Logger.Level.debug, CyLR.Logger.Level.info, CyLR.Logger.Level.warn, CyLR.Logger.Level.error, CyLR.Logger.Level.critical, CyLR.Logger.Level.none }; logger.TearDown(); foreach (var l in levels) { logger.LoggingOptions["output_file_min_level"] = l.ToString(); logger.LoggingOptions["output_console_min_level"] = l.ToString(); logger.Setup(); Assert.Equal(l, logger.fileLevel); Assert.Equal(l, logger.consoleLevel); logger.TearDown(); } }
public void TestCustomCollectionPaths() { Arguments arg = new Arguments(new [] { "-c", "test.txt" }); List <string> addtlPaths = new List <string>(); List <string> paths = new List <string>(); string sep = "/"; var userProfile = Environment.ExpandEnvironmentVariables("%HOME%"); var logger = new CyLR.Logger(); logger.LoggingOptions["output_file_path"] = "1.log"; logger.LoggingOptions["output_console_min_level"] = "error"; logger.Setup(); // Set platform specific variables. if (!Platform.IsUnixLike()) { sep = "\\"; userProfile = Environment.ExpandEnvironmentVariables("%USERPROFILE%"); } // Define expected test files paths.Add(userProfile + sep + "CyLR_test.file"); paths.Add(userProfile + sep + "CyLR_glob_test"); paths.Add(userProfile + sep + "CyLR_Regex_test"); // Create test files foreach (var path in paths) { if (!File.Exists(path)) { File.Create(path); } } // Create custom patterns file. using (StreamWriter sr = new StreamWriter("test.txt")) { sr.WriteLine("glob\t**" + sep + "CyLR_glob_test"); sr.WriteLine("static\t" + userProfile + sep + "CyLR_test.file"); if (Platform.IsUnixLike()) { sr.WriteLine("regex\t^" + userProfile + sep + "CyLR_[A-Za-z]{5}_test$"); } else { sr.WriteLine("regex\t^" + userProfile.Replace("\\", "\\\\") + sep + sep + "CyLR_[A-Za-z]{5}_test$"); } } var cPaths = CollectionPaths.GetPaths(arg, addtlPaths, false, logger); paths.Sort(); cPaths.Sort(); Assert.Equal(paths, cPaths); }
public void TestLoggerLevelMessages() { var logger = new CyLR.Logger(); string expected; string actual; logger.Setup(); logger.trace("This is a trace!"); expected = "[trace] This is a trace!\n"; actual = logger.logMessages.Split(" ", 2)[1]; Assert.Equal(expected, actual); logger.logMessages = ""; logger.debug("This is a debug!"); expected = "[debug] This is a debug!\n"; actual = logger.logMessages.Split(" ", 2)[1]; Assert.Equal(expected, actual); logger.logMessages = ""; logger.info("This is a info!"); expected = "[info] This is a info!\n"; actual = logger.logMessages.Split(" ", 2)[1]; Assert.Equal(expected, actual); logger.logMessages = ""; logger.warn("This is a warning!"); expected = "[warn] This is a warning!\n"; actual = logger.logMessages.Split(" ", 2)[1]; Assert.Equal(expected, actual); logger.logMessages = ""; logger.error("This is a error!"); expected = "[error] This is a error!\n"; actual = logger.logMessages.Split(" ", 2)[1]; Assert.Equal(expected, actual); logger.logMessages = ""; logger.critical("This is a critical!"); expected = "[critical] This is a critical!\n"; actual = logger.logMessages.Split(" ", 2)[1]; Assert.Equal(expected, actual); logger.logMessages = ""; logger.none("This is a none!"); expected = "[none] This is a none!\n"; actual = logger.logMessages.Split(" ", 2)[1]; Assert.Equal(expected, actual); logger.TearDown(); }
public void TestLoggerLevelMessages() { var logger = new CyLR.Logger(); var now = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); string expected; logger.Setup(); logger.trace("This is a trace!"); now = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); expected = $"{now} [trace] This is a trace!\n"; Assert.Equal(expected, logger.logMessages); logger.logMessages = ""; logger.debug("This is a debug!"); now = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); expected = $"{now} [debug] This is a debug!\n"; Assert.Equal(expected, logger.logMessages); logger.logMessages = ""; logger.info("This is a info!"); now = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); expected = $"{now} [info] This is a info!\n"; Assert.Equal(expected, logger.logMessages); logger.logMessages = ""; logger.warn("This is a warning!"); now = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); expected = $"{now} [warn] This is a warning!\n"; Assert.Equal(expected, logger.logMessages); logger.logMessages = ""; logger.error("This is a error!"); now = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); expected = $"{now} [error] This is a error!\n"; Assert.Equal(expected, logger.logMessages); logger.logMessages = ""; logger.critical("This is a critical!"); now = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); expected = $"{now} [critical] This is a critical!\n"; Assert.Equal(expected, logger.logMessages); logger.logMessages = ""; logger.none("This is a none!"); now = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); expected = $"{now} [none] This is a none!\n"; Assert.Equal(expected, logger.logMessages); logger.TearDown(); }
public void TestLoggerFormats() { var logger = new CyLR.Logger(); logger.Setup(); logger.logger(CyLR.Logger.Level.warn, "This is a warning!"); var expected = "[warn] This is a warning!\n"; var actual = logger.logMessages.Split(" ", 2)[1]; Assert.Equal(expected, actual); logger.TearDown(); }
public void TestLoggerFormats() { var logger = new CyLR.Logger(); logger.Setup(); logger.logger(CyLR.Logger.Level.warn, "This is a warning!"); var now = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss"); var expected = $"{now} [warn] This is a warning!\n"; Assert.Equal(expected, logger.logMessages); logger.TearDown(); }
public void TestCustomCollectionPathsRegExFail() { Arguments arg = new Arguments(new [] { "-c", "test.txt" }); List <string> addtlPaths = new List <string>(); List <string> paths = new List <string>(); string sep = "/"; var userProfile = Environment.ExpandEnvironmentVariables("%HOME%"); var logger = new CyLR.Logger(); logger.LoggingOptions["output_file_path"] = "2.log"; logger.Setup(); if (!Platform.IsUnixLike()) { sep = "\\"; userProfile = Environment.ExpandEnvironmentVariables("%USERPROFILE%"); } paths.Add(userProfile + sep + "CyLR_Regex_test"); using (StreamWriter sr = new StreamWriter("test.txt")) { if (Platform.IsUnixLike()) { sr.WriteLine("regex\t^" + userProfile + sep + "CyLR_[A-Za-z]{10}_test$"); } else { sr.WriteLine("regex\t^" + userProfile.Replace("\\", "\\\\") + sep + sep + "CyLR_[A-Za-z]{10}_test$"); } } // Create test files foreach (var path in paths) { if (!File.Exists(path)) { File.Create(path); } } var cPaths = CollectionPaths.GetPaths(arg, addtlPaths, false, logger); paths.Sort(); cPaths.Sort(); Assert.NotEqual(paths, cPaths); Assert.Empty(cPaths); }