Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

RPC tests #66

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 56 additions & 43 deletions Stratis.Bitcoin.Tests/Logging/LogsTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,64 @@

namespace Stratis.Bitcoin.Tests.Logging
{
public class LogsTestBase
{
private Mock<Microsoft.Extensions.Logging.ILogger> fullNodeLogger;
private Mock<ILoggerFactory> loggerFactory;
public class LogsTestBase
{
private Mock<ILogger> fullNodeLogger;
private Mock<ILoggerFactory> loggerFactory;
private Mock<ILogger> rpcLogger;

/// <remarks>
/// This class is not able to work concurrently because logs is a static class.
/// The logs class needs to be refactored first before tests can run in parallel.
/// </remarks>
public LogsTestBase()
{
fullNodeLogger = new Mock<ILogger>();
loggerFactory = new Mock<ILoggerFactory>();
loggerFactory.Setup(l => l.CreateLogger(It.IsAny<string>()))
.Returns(new Mock<ILogger>().Object);
loggerFactory.Setup(l => l.CreateLogger("FullNode"))
.Returns(fullNodeLogger.Object)
.Verifiable();
Logs.Configure(loggerFactory.Object);
}
/// <remarks>
/// This class is not able to work concurrently because logs is a static class.
/// The logs class needs to be refactored first before tests can run in parallel.
/// </remarks>
public LogsTestBase()
{
fullNodeLogger = new Mock<ILogger>();
rpcLogger = new Mock<ILogger>();
loggerFactory = new Mock<ILoggerFactory>();
loggerFactory.Setup(l => l.CreateLogger(It.IsAny<string>()))
.Returns(new Mock<ILogger>().Object);
loggerFactory.Setup(l => l.CreateLogger("FullNode"))
.Returns(fullNodeLogger.Object)
.Verifiable();
loggerFactory.Setup(l => l.CreateLogger("RPC"))
.Returns(rpcLogger.Object)
.Verifiable();
Logs.Configure(loggerFactory.Object);
}

public Mock<ILogger> FullNodeLogger
{
get
{
return fullNodeLogger;
}
}
public Mock<ILogger> FullNodeLogger
{
get
{
return fullNodeLogger;
}
}

protected void AssertLog<T>(Mock<ILogger> logger, LogLevel logLevel, string exceptionMessage,string message) where T: Exception
{
logger.Verify(f => f.Log<Object>(logLevel,
It.IsAny<EventId>(),
It.Is<Object>(l => ((FormattedLogValues)l)[0].Value.ToString().EndsWith(message)),
It.Is<T>(t=> t.Message.Equals(exceptionMessage)),
It.IsAny<Func<Object, Exception, string>>()));
}
public Mock<ILogger> RPCLogger
{
get
{
return rpcLogger;
}
}

protected void AssertLog(Mock<ILogger> logger, LogLevel logLevel, string message)
{
logger.Verify(f => f.Log<Object>(logLevel,
It.IsAny<EventId>(),
It.Is<Object>(l => ((FormattedLogValues)l)[0].Value.ToString().EndsWith(message)),
null,
It.IsAny<Func<Object, Exception, string>>()));
}
}
protected void AssertLog<T>(Mock<ILogger> logger, LogLevel logLevel, string exceptionMessage, string message) where T : Exception
{
logger.Verify(f => f.Log<Object>(logLevel,
It.IsAny<EventId>(),
It.Is<Object>(l => ((FormattedLogValues)l)[0].Value.ToString().EndsWith(message)),
It.Is<T>(t => t.Message.Equals(exceptionMessage)),
It.IsAny<Func<Object, Exception, string>>()));
}

protected void AssertLog(Mock<ILogger> logger, LogLevel logLevel, string message)
{
logger.Verify(f => f.Log<Object>(logLevel,
It.IsAny<EventId>(),
It.Is<Object>(l => ((FormattedLogValues)l)[0].Value.ToString().EndsWith(message)),
null,
It.IsAny<Func<Object, Exception, string>>()));
}
}
}
Loading