LoggerTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Tests.Core LoggerTests

Namespace: DeltaEngine.Tests.Core
Assembly: DeltaEngine.Tests (in DeltaEngine.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class LoggerTests

The LoggerTests type exposes the following members.

Constructors

  NameDescription
Public methodLoggerTests
Initializes a new instance of the LoggerTests class
Top
Methods

  NameDescription
Public methodIfNoLoggerIsAttachedWeGetAWarning
Public methodLogError
Public methodLogInfoMessage
Public methodLogSameMessageMultipleTimes
Public methodLogWarning
Public methodMakeSureNoLoggersAreAttached
Public methodRegisteringLoggerInTheSameThreadTwiceIsNotAllowed
Public methodRegisteringTheSameLoggerTwiceIsNotAllowed
Top
Examples

[Test]
public void LogInfoMessage()
{
    using (var logger = new MockLogger())
    {
        Assert.IsEmpty(logger.LastMessage);
        Logger.Info("Hello");
        Assert.AreEqual("Hello", logger.LastMessage);
        Assert.AreEqual(0, logger.NumberOfRepeatedMessagesIgnored);
    }
}
[Test]
public void LogSameMessageMultipleTimes()
{
    using (var logger = new MockLogger())
    {
        Logger.Info("Hello");
        Logger.Info("Hello");
        Assert.AreEqual(1, logger.NumberOfRepeatedMessagesIgnored);
    }
}
[Test]
public void LogWarning()
{
    using (var logger = new MockLogger())
    {
        Logger.Warning("Ohoh");
        Assert.AreEqual("Ohoh", logger.LastMessage);
        Logger.Warning(new NullReferenceException());
        Assert.IsTrue(logger.LastMessage.Contains("NullReferenceException"));
    }
}
[Test]
public void LogError()
{
    using (var logger = new MockLogger())
    {
        Logger.Error(new ExternalException());
        Assert.IsTrue(logger.LastMessage.Contains(new ExternalException().Message),
            logger.LastMessage);
    }
}
[Test]
public void RegisteringLoggerInTheSameThreadTwiceIsNotAllowed()
{
    using (new SameThreadLogger())
    {
        Logger.Info("La la la");
        Assert.Throws<Logger.LoggerWasAlreadyAttached>(() => { using (new SameThreadLogger()) {} });
    }
[Test]
public void RegisteringTheSameLoggerTwiceIsNotAllowed()
{
    using (new AnotherLogger())
    {
        Assert.Throws<Logger.LoggerWasAlreadyAttached>(() => { using (new AnotherLogger()) {} });
    }
[Test]
public void IfNoLoggerIsAttachedWeGetAWarning()
{
    const string Warning = "Ohoh";
    const string Message = "No loggers have been created for this message: " + Warning;
    var defaultOut = Console.Out;
    var console = new StringWriter();
    Console.SetOut(console);
    Logger.Warning(Warning);
    Assert.IsTrue(console.ToString().Contains(Message), console.ToString());
    Console.SetOut(defaultOut);
    console.Dispose();
}
See Also