Skip to content

Commit

Permalink
Add tests for ModLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
blowfishpro committed Sep 3, 2017
1 parent 6e8285c commit 7398d4d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
63 changes: 63 additions & 0 deletions ModuleManagerTests/Logging/ModLoggerTest.cs
@@ -0,0 +1,63 @@
using System;
using Xunit;
using NSubstitute;
using UnityEngine;
using ModuleManager.Logging;

namespace ModuleManagerTests.Logging
{
public class ModLoggerTest
{
private ILogger innerLogger;
private ModLogger logger;

public ModLoggerTest()
{
innerLogger = Substitute.For<ILogger>();
logger = new ModLogger("MyMod", innerLogger);
}
[Fact]
public void TestLog()
{
logger.Log(LogType.Log, "this is a log message");
logger.Log(LogType.Error, "this is another log message");

innerLogger.Received().Log(LogType.Log, "[MyMod] this is a log message");
innerLogger.Received().Log(LogType.Error, "[MyMod] this is another log message");
}

[Fact]
public void TestInfo()
{
logger.Info("well hi there");

innerLogger.Received().Log(LogType.Log, "[MyMod] well hi there");
}

[Fact]
public void TestWarning()
{
logger.Warning("I'm warning you");

innerLogger.Received().Log(LogType.Warning, "[MyMod] I'm warning you");
}

[Fact]
public void TestError()
{
logger.Error("You have made a grave mistake");

innerLogger.Received().Log(LogType.Error, "[MyMod] You have made a grave mistake");
}

[Fact]
public void TestException()
{
Exception e = new Exception();
logger.Exception("An exception was thrown", e);

innerLogger.Received().Log(LogType.Error, "[MyMod] An exception was thrown");
innerLogger.Received().LogException(e);
}
}
}
1 change: 1 addition & 0 deletions ModuleManagerTests/ModuleManagerTests.csproj
Expand Up @@ -52,6 +52,7 @@
<Compile Include="Collections\ImmutableStackTest.cs" />
<Compile Include="DummyTest.cs" />
<Compile Include="Extensions\NodeStackExtensionsTest.cs" />
<Compile Include="Logging\ModLoggerTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down

0 comments on commit 7398d4d

Please sign in to comment.