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

Commit

Permalink
Merge pull request #66 from Neurosploit/rpctests2
Browse files Browse the repository at this point in the history
RPC tests
  • Loading branch information
dangershony authored Mar 20, 2017
2 parents ac07a73 + 3ad933d commit c493ab5
Show file tree
Hide file tree
Showing 8 changed files with 802 additions and 431 deletions.
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

0 comments on commit c493ab5

Please sign in to comment.