Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace ModuleManager.Logging | ||
{ | ||
public class LogSplitter : IBasicLogger | ||
{ | ||
private readonly IBasicLogger logger1; | ||
private readonly IBasicLogger logger2; | ||
|
||
public LogSplitter(IBasicLogger logger1, IBasicLogger logger2) | ||
{ | ||
this.logger1 = logger1 ?? throw new ArgumentNullException(nameof(logger1)); | ||
this.logger2 = logger2 ?? throw new ArgumentNullException(nameof(logger2)); | ||
} | ||
|
||
public void Log(LogType logType, string message) | ||
{ | ||
logger1.Log(logType, message); | ||
logger2.Log(logType, message); | ||
} | ||
|
||
public void Exception(string message, Exception exception) | ||
{ | ||
logger1.Exception(message, exception); | ||
logger2.Exception(message, exception); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System; | ||
using Xunit; | ||
using NSubstitute; | ||
using UnityEngine; | ||
using ModuleManager.Logging; | ||
|
||
namespace ModuleManagerTests.Logging | ||
{ | ||
public class LogSplitterTest | ||
{ | ||
[Fact] | ||
public void TestConstructor__Logger1Null() | ||
{ | ||
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate | ||
{ | ||
new LogSplitter(null, Substitute.For<IBasicLogger>()); | ||
}); | ||
|
||
Assert.Equal("logger1", ex.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void TestConstructor__Logger2Null() | ||
{ | ||
ArgumentNullException ex = Assert.Throws<ArgumentNullException>(delegate | ||
{ | ||
new LogSplitter(Substitute.For<IBasicLogger>(), null); | ||
}); | ||
|
||
Assert.Equal("logger2", ex.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void TestLog() | ||
{ | ||
IBasicLogger logger1 = Substitute.For<IBasicLogger>(); | ||
IBasicLogger logger2 = Substitute.For<IBasicLogger>(); | ||
LogSplitter logSplitter = new LogSplitter(logger1, logger2); | ||
logSplitter.Log(LogType.Log, "some stuff"); | ||
logger1.Received().Log(LogType.Log, "some stuff"); | ||
logger2.Received().Log(LogType.Log, "some stuff"); | ||
} | ||
|
||
[Fact] | ||
public void TestException() | ||
{ | ||
IBasicLogger logger1 = Substitute.For<IBasicLogger>(); | ||
IBasicLogger logger2 = Substitute.For<IBasicLogger>(); | ||
LogSplitter logSplitter = new LogSplitter(logger1, logger2); | ||
Exception ex = new Exception(); | ||
logSplitter.Exception("some stuff", ex); | ||
logger1.Received().Exception("some stuff", ex); | ||
logger2.Received().Exception("some stuff", ex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters