Skip to content

Commit

Permalink
Test re-factoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgernand committed Nov 4, 2021
1 parent 551f343 commit af36a0f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 79 deletions.
31 changes: 31 additions & 0 deletions Source/NHibernate.Logging.CommonLogging.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,37 @@ public static void Main()
Console.WriteLine(customer);
}

Console.WriteLine();
Console.WriteLine("-------------------------------------------------");
INHibernateLogger logger = NHibernateLogger.For("Demo");

logger.Debug("Single Message");
logger.Debug("Formatted Message {0}", 1);
logger.Debug(new Exception("Exception"), "Exception Message");
logger.Debug(new Exception("Exception"), "Formatted Exception Message {0}", 1);

logger.Info("Single Message");
logger.Info("Formatted Message {0}", 1);
logger.Info(new Exception("Exception"), "Exception Message");
logger.Info(new Exception("Exception"), "Formatted Exception Message {0}", 1);

logger.Warn("Single Message");
logger.Warn("Formatted Message {0}", 1);
logger.Warn(new Exception("Exception"), "Exception Message");
logger.Warn(new Exception("Exception"), "Formatted Exception Message {0}", 1);

logger.Error("Single Message");
logger.Error("Formatted Message {0}", 1);
logger.Error(new Exception("Exception"), "Exception Message");
logger.Error(new Exception("Exception"), "Formatted Exception Message {0}", 1);

logger.Fatal("Single Message");
logger.Fatal("Formatted Message {0}", 1);
logger.Fatal(new Exception("Exception"), "Exception Message");
logger.Fatal(new Exception("Exception"), "Formatted Exception Message {0}", 1);

Console.WriteLine("-------------------------------------------------");

Console.WriteLine();
Console.WriteLine("Press any key to quit...");
Console.ReadKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Common.Logging" Version="3.4.1" />
<PackageReference Include="NHibernate" Version="5.3.10" />
<None Remove="App.config.transform" />
</ItemGroup>

<ItemGroup>
<None Update="App.config.transform">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<Content Include="App.config.transform">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Common.Logging" Version="3.4.1" />
<PackageReference Include="NHibernate" Version="5.3.10" />
</ItemGroup>

</Project>
47 changes: 15 additions & 32 deletions Source/NHibernate.Logging.UnitTests/CommonLogging/CommonLogMock.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
namespace NHibernate.Logging.UnitTests
namespace NHibernate.Logging.UnitTests.CommonLogging
{
using System;
using Common.Logging;

internal class CommonLogMock : ILog
{
public int trace;
public int traceException;
public int traceFormat;
public int debug;
public int debugException;
public int debugFormat;
public int info;
public int infoException;
public int infoFormat;
public int warn;
public int warnException;
public int warnFormat;
public int error;
public int errorException;
public int errorFormat;
public int fatal;
public int fatalException;
public int isTraceEnabled;
public int isDebugEnabled;
public int isInfoEnabled;
Expand Down Expand Up @@ -84,17 +67,17 @@ public void Trace(IFormatProvider formatProvider, Action<FormatMessageHandler> f
#region Debug
public void Debug(object message)
{
this.debug++;
throw new NotImplementedException();
}

public void Debug(object message, Exception exception)
{
this.debugException++;
throw new NotImplementedException();
}

public void DebugFormat(string format, params object[] args)
{
this.debugFormat++;
throw new NotImplementedException();
}

public void DebugFormat(string format, Exception exception, params object[] args)
Expand Down Expand Up @@ -136,17 +119,17 @@ public void Debug(IFormatProvider formatProvider, Action<FormatMessageHandler> f
#region Info
public void Info(object message)
{
this.info++;
throw new NotImplementedException();
}

public void Info(object message, Exception exception)
{
this.infoException++;
throw new NotImplementedException();
}

public void InfoFormat(string format, params object[] args)
{
this.infoFormat++;
throw new NotImplementedException();
}

public void InfoFormat(string format, Exception exception, params object[] args)
Expand Down Expand Up @@ -188,17 +171,17 @@ public void Info(IFormatProvider formatProvider, Action<FormatMessageHandler> fo
#region Warn
public void Warn(object message)
{
this.warn++;
throw new NotImplementedException();
}

public void Warn(object message, Exception exception)
{
this.warnException++;
throw new NotImplementedException();
}

public void WarnFormat(string format, params object[] args)
{
this.warnFormat++;
throw new NotImplementedException();
}

public void WarnFormat(string format, Exception exception, params object[] args)
Expand Down Expand Up @@ -240,17 +223,17 @@ public void Warn(IFormatProvider formatProvider, Action<FormatMessageHandler> fo
#region Error
public void Error(object message)
{
this.error++;
throw new NotImplementedException();
}

public void Error(object message, Exception exception)
{
this.errorException++;
throw new NotImplementedException();
}

public void ErrorFormat(string format, params object[] args)
{
this.errorFormat++;
throw new NotImplementedException();
}

public void ErrorFormat(string format, Exception exception, params object[] args)
Expand Down Expand Up @@ -292,12 +275,12 @@ public void Error(IFormatProvider formatProvider, Action<FormatMessageHandler> f
#region Fatal
public void Fatal(object message)
{
this.fatal++;
throw new NotImplementedException();
}

public void Fatal(object message, Exception exception)
{
this.fatalException++;
throw new NotImplementedException();
}

public void FatalFormat(string format, params object[] args)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NHibernate.Logging.UnitTests
namespace NHibernate.Logging.UnitTests.CommonLogging
{
using FluentAssertions;
using NHibernate;
Expand All @@ -8,49 +8,56 @@
[TestFixture]
public class CommonLoggingLoggerTest
{
private CommonLogMock logMock;
private CommonLoggingLogger logger;

[SetUp]
public void SetUp()
{
this.logMock = new CommonLogMock();
this.logger = new CommonLoggingLogger(this.logMock);
}

[Test]
public void ShouldCall_IsTranceEnabled()
{
this.logger.IsEnabled(NHibernateLogLevel.Trace);
this.logMock.isTraceEnabled.Should().Be(1);
}

[Test]
public void ShouldCall_IsDebugEnabled()
{
this.logger.IsEnabled(NHibernateLogLevel.Debug);
this.logMock.isDebugEnabled.Should().Be(1);
}

[Test]
public void ShouldCall_IsInfoEnabled()
{
this.logger.IsEnabled(NHibernateLogLevel.Info);
this.logMock.isInfoEnabled.Should().Be(1);
}

[Test]
public void ShouldCall_IsWarnEnabled()
{
this.logger.IsEnabled(NHibernateLogLevel.Warn);
this.logMock.isWarnEnabled.Should().Be(1);
}

[Test]
public void ShouldCall_IsErrorEnabled()
{
this.logger.IsEnabled(NHibernateLogLevel.Error);
this.logMock.isErrorEnabled.Should().Be(1);
}

[Test]
public void CallingMethods()
public void ShouldCall_IsFatalEnabled()
{
CommonLogMock logMock = new CommonLogMock();
CommonLoggingLogger logger = new CommonLoggingLogger(logMock);

logger.IsEnabled(NHibernateLogLevel.Trace);
logger.IsEnabled(NHibernateLogLevel.Debug);
logger.IsEnabled(NHibernateLogLevel.Info);
logger.IsEnabled(NHibernateLogLevel.Warn);
logger.IsEnabled(NHibernateLogLevel.Error);
logger.IsEnabled(NHibernateLogLevel.Fatal);

logger.Log(NHibernateLogLevel.Trace, default, null);
logger.Log(NHibernateLogLevel.Debug, default, null);
logger.Log(NHibernateLogLevel.Info, default, null);
logger.Log(NHibernateLogLevel.Warn, default, null);
logger.Log(NHibernateLogLevel.Error, default, null);
logger.Log(NHibernateLogLevel.Fatal, default, null);

logMock.trace.Should().Be(1);
logMock.traceException.Should().Be(1);
logMock.traceFormat.Should().Be(1);
logMock.debug.Should().Be(1);
logMock.debugException.Should().Be(1);
logMock.debugFormat.Should().Be(1);
logMock.info.Should().Be(1);
logMock.infoException.Should().Be(1);
logMock.infoFormat.Should().Be(1);
logMock.warn.Should().Be(1);
logMock.warnException.Should().Be(1);
logMock.warnFormat.Should().Be(1);
logMock.error.Should().Be(1);
logMock.errorException.Should().Be(1);
logMock.errorFormat.Should().Be(1);
logMock.fatal.Should().Be(1);
logMock.fatalException.Should().Be(1);
logMock.isTraceEnabled.Should().Be(1);
logMock.isDebugEnabled.Should().Be(1);
logMock.isInfoEnabled.Should().Be(1);
logMock.isWarnEnabled.Should().Be(1);
logMock.isErrorEnabled.Should().Be(1);
logMock.isFatalEnabled.Should().Be(1);
this.logger.IsEnabled(NHibernateLogLevel.Fatal);
this.logMock.isFatalEnabled.Should().Be(1);
}
}
}

0 comments on commit af36a0f

Please sign in to comment.