public void FormatPattern_RenderEscapedRenderer()
 {
     LogKernel kernel = new LogKernel(new LogConfiguration());
     ILogger logger = kernel.GetLogger();
     FormatPatternFactory factory = new FormatPatternFactory();
     FormatPattern pattern = factory.Create("$$(time(format='HH:mm:ss'))");
     ILogEntry entry = new LogEntry(DateTime.Now, LogLevel.Information, "The log message.", logger, null);
     Assert.AreEqual("$(time(format='HH:mm:ss'))", pattern.Render(entry));
 }
 private string Render(string format, LogLevel level)
 {
     LogKernel kernel = new LogKernel(new LogConfiguration());
     ILogger logger = kernel.GetLogger();
     FormatPatternFactory factory = new FormatPatternFactory();
     FormatPattern pattern = factory.Create(format);
     ILogEntry entry = new LogEntry(DateTimeOffset.Now, level, "The log message.", logger, null);
     return pattern.Render(entry);
 }
 public void FormatPatternFactory_BuildPatternWithLiteral()
 {
     var factory = new FormatPatternFactory();
     var pattern = factory.Create("Hello World!");
     Assert.IsNotNull(pattern);
     Assert.IsNotNull(pattern.Renderers);
     Assert.AreEqual(1, pattern.Renderers.Length);
     Assert.IsInstanceOf<LiteralRenderer>(pattern.Renderers[0]);
     Assert.AreEqual("Hello World!", ((LiteralRenderer)pattern.Renderers[0]).Literal);
 }
 public void FormatPatternFactory_BuildPatternWithTransformer()
 {
     LogKernel kernel = new LogKernel(new LogConfiguration());
     ILogger logger = kernel.GetLogger();
     FormatPatternFactory factory = new FormatPatternFactory();
     FormatPattern pattern = factory.Create("$(uppercase(message()))");
     ILogEntry entry = new LogEntry(DateTimeOffset.Now, LogLevel.Information, "The log message.", logger, null);
     string rendered = pattern.Render(entry);
     Assert.IsNotNullOrEmpty(rendered);
     Assert.AreEqual("THE LOG MESSAGE.", rendered);
 }
 public void FormatPatternFactory_BuildPatternWithNestedTransformers()
 {
     LogKernel kernel = new LogKernel(new LogConfiguration());
     ILogger logger = kernel.GetLogger();
     FormatPatternFactory factory = new FormatPatternFactory();
     FormatPattern pattern = factory.Create("$(rot13(uppercase(message())))");
     ILogEntry entry = new LogEntry(DateTimeOffset.Now, LogLevel.Information, "Hello World!", logger, null);
     string rendered = pattern.Render(entry);
     Assert.IsNotNullOrEmpty(rendered);
     Assert.AreEqual("URYYB JBEYQ!", rendered);
 }
 public void FormatPatternFactory_BuildPatternWithNestedTransformers()
 {
     var factory = new FormatPatternFactory();
     var pattern = factory.Create("$(uppercase(rot13(message())))");
     Assert.IsNotNull(pattern);
     Assert.IsNotNull(pattern.Renderers);
     Assert.AreEqual(1, pattern.Renderers.Length);
     Assert.IsInstanceOf<UppercaseTransformer>(pattern.Renderers[0]);
     Assert.IsInstanceOf<Rot13Transformer>(((UppercaseTransformer)pattern.Renderers[0]).Renderer);
     Assert.IsInstanceOf<MessageRenderer>(((Rot13Transformer)((UppercaseTransformer)pattern.Renderers[0]).Renderer).Renderer);
 }
 public void FormatPatternFactory_BuildComplexPattern()
 {
     LogKernel kernel = new LogKernel(new LogConfiguration());
     ILogger logger = kernel.GetLogger();
     FormatPatternFactory factory = new FormatPatternFactory();
     FormatPattern pattern = factory.Create("[$(time(format='HH:mm:ss'))] $(uppercase(rot13(message())))");
     DateTimeOffset currentTime = DateTimeOffset.Now;
     ILogEntry entry = new LogEntry(currentTime, LogLevel.Information, "Hello World!", logger, null);
     string rendered = pattern.Render(entry);
     string expected = string.Format("[{0:HH:mm:ss}] URYYB JBEYQ!", currentTime);
     Assert.IsNotNullOrEmpty(rendered);
     Assert.AreEqual(expected, rendered);
 }
 public void FormatPatternFactory_BuildComplexPattern()
 {
     var factory = new FormatPatternFactory();
     var pattern = factory.Create("[$(time())] $(uppercase(rot13(message())))");
     Assert.IsNotNull(pattern);
     Assert.IsNotNull(pattern.Renderers);
     Assert.AreEqual(4, pattern.Renderers.Length);
     Assert.IsInstanceOf<LiteralRenderer>(pattern.Renderers[0]);
     Assert.IsInstanceOf<TimeRenderer>(pattern.Renderers[1]);
     Assert.IsInstanceOf<LiteralRenderer>(pattern.Renderers[2]);
     Assert.IsInstanceOf<UppercaseTransformer>(pattern.Renderers[3]);
     Assert.IsInstanceOf<Rot13Transformer>(((UppercaseTransformer)pattern.Renderers[3]).Renderer);
     Assert.IsInstanceOf<MessageRenderer>(((Rot13Transformer)((UppercaseTransformer)pattern.Renderers[3]).Renderer).Renderer);
 }
 public void FormatPattern_RenderLiteralPattern()
 {
     LogKernel kernel = new LogKernel(new LogConfiguration());
     ILogger logger = kernel.GetLogger();
     FormatPatternFactory factory = new FormatPatternFactory();
     FormatPattern pattern = factory.Create("Hello World!");
     ILogEntry entry = new LogEntry(DateTimeOffset.Now, LogLevel.Information, "The log message.", logger, null);
     string rendered = pattern.Render(entry);
     Assert.IsNotNullOrEmpty(rendered);
     Assert.AreEqual("Hello World!", rendered);
 }
 public void FormatPattern_RenderTimeRenderer()
 {
     LogKernel kernel = new LogKernel(new LogConfiguration());
     ILogger logger = kernel.GetLogger();
     FormatPatternFactory factory = new FormatPatternFactory();
     FormatPattern pattern = factory.Create("$(time(format='HH:mm:ss'))");
     DateTimeOffset currentTime = DateTimeOffset.Now;
     ILogEntry entry = new LogEntry(currentTime, LogLevel.Information, "The log message.", logger, null);
     string rendered = pattern.Render(entry);
     Assert.IsNotNullOrEmpty(rendered);
     Assert.AreEqual(currentTime.ToString("HH:mm:ss"), rendered);
 }
 public void FormatPatternFactory_BuildPatternWithRendererThatDoNotExist()
 {
     var factory = new FormatPatternFactory();
     var pattern = factory.Create("$(nonexistent(format='HH:mm:ss'))");
 }
 public void FormatPatternFactory_BuildPatternWithRenderer()
 {
     var factory = new FormatPatternFactory();
     var pattern = factory.Create("$(time(format='HH:mm:ss'))");
     Assert.IsNotNull(pattern);
     Assert.IsNotNull(pattern.Renderers);
     Assert.AreEqual(1, pattern.Renderers.Length);
     Assert.IsInstanceOf<TimeRenderer>(pattern.Renderers[0]);
     Assert.AreEqual("HH:mm:ss", ((TimeRenderer)pattern.Renderers[0]).Format);
 }
 public void FormatPatternFactory_BuildPatternWithNestedRendererThatDoNotExist()
 {
     var factory = new FormatPatternFactory();
     var pattern = factory.Create("$(uppercase(nonexistent()))");
 }
 public void FormatPatternFactory_BuildPatternWithTransformerThatHasNoRenderer()
 {
     var factory = new FormatPatternFactory();
     var pattern = factory.Create("$(nonexistent(uppercase()))");
 }
 public void FormatPatternFactory_BuildPatternWithTransformerThatDoNotExist()
 {
     var factory = new FormatPatternFactory();
     var pattern = factory.Create("$(nonexistent(message()))");
 }