Added RedirectUsingNamedRoute
[castle.git] / Core / Castle.Core.Tests / ConsoleLoggerTestCase.cs
blob1a214f9382b01aa9662f75637e5ef9c8721e34e5
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.Core.Logging.Tests
17 using System;
18 using System.IO;
20 using Castle.Core.Logging;
22 using NUnit.Framework;
24 [TestFixture]
25 public class ConsoleLoggerTestCase
27 private StringWriter outWriter = new StringWriter();
28 private StringWriter errorWriter = new StringWriter();
30 [SetUp]
31 public void ReplaceOut()
33 outWriter.GetStringBuilder().Length = 0;
34 errorWriter.GetStringBuilder().Length = 0;
36 Console.SetOut(outWriter);
37 Console.SetError(errorWriter);
40 [Test]
41 public void InfoLogger()
43 ConsoleLogger log = new ConsoleLogger("Logger", LoggerLevel.Info);
45 log.Debug("Some debug message");
46 log.Info("Some info message");
47 log.Error("Some error message");
48 log.Fatal("Some fatal error message");
49 log.Warn("Some warn message");
51 String logcontents = outWriter.GetStringBuilder().ToString();
53 StringWriter expected = new StringWriter();
54 expected.WriteLine("[Info] 'Logger' Some info message");
55 expected.WriteLine("[Error] 'Logger' Some error message");
56 expected.WriteLine("[Fatal] 'Logger' Some fatal error message");
57 expected.WriteLine("[Warn] 'Logger' Some warn message");
59 Assert.AreEqual(expected.GetStringBuilder().ToString(), logcontents, "logcontents don't match");
62 [Test]
63 public void DebugLogger()
65 ConsoleLogger log = new ConsoleLogger("Logger", LoggerLevel.Debug);
67 log.Debug("Some debug message");
68 log.Info("Some info message");
69 log.Error("Some error message");
70 log.Fatal("Some fatal error message");
71 log.Warn("Some warn message");
73 String logcontents = outWriter.GetStringBuilder().ToString();
75 StringWriter expected = new StringWriter();
76 expected.WriteLine("[Debug] 'Logger' Some debug message");
77 expected.WriteLine("[Info] 'Logger' Some info message");
78 expected.WriteLine("[Error] 'Logger' Some error message");
79 expected.WriteLine("[Fatal] 'Logger' Some fatal error message");
80 expected.WriteLine("[Warn] 'Logger' Some warn message");
82 Assert.AreEqual(expected.GetStringBuilder().ToString(), logcontents, "logcontents don't match");
85 [Test]
86 public void WarnLogger()
88 ConsoleLogger log = new ConsoleLogger("Logger", LoggerLevel.Warn);
90 log.Debug("Some debug message");
91 log.Info("Some info message");
92 log.Error("Some error message");
93 log.Fatal("Some fatal error message");
94 log.Warn("Some warn message");
96 String logcontents = outWriter.GetStringBuilder().ToString();
98 StringWriter expected = new StringWriter();
99 expected.WriteLine("[Error] 'Logger' Some error message");
100 expected.WriteLine("[Fatal] 'Logger' Some fatal error message");
101 expected.WriteLine("[Warn] 'Logger' Some warn message");
103 Assert.AreEqual(expected.GetStringBuilder().ToString(), logcontents, "logcontents don't match");
106 [Test]
107 public void ExceptionLogging()
109 ConsoleLogger log = new ConsoleLogger("Logger", LoggerLevel.Debug);
111 log.Debug("Some debug message", new ApplicationException("Some exception message"));
113 String logcontents = outWriter.GetStringBuilder().ToString();
115 StringWriter expected = new StringWriter();
116 expected.WriteLine("[Debug] 'Logger' Some debug message");
117 expected.WriteLine("[Debug] 'Logger' System.ApplicationException: Some exception message ");
119 Assert.AreEqual(expected.GetStringBuilder().ToString(), logcontents, "logcontents don't match");