Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 8 additions & 0 deletions Assets/EditorTests/Logger.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions Assets/EditorTests/Logger/LoggerServiceConfigTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using com.mapcolonies.core.Services.LoggerService;
using NUnit.Framework;

namespace EditorTests.Logger
{
public class LoggerServiceConfigTests
{
[Test]
public void Init_WhenJsonExists_LoadsBasicProperties()
{
LoggerServiceConfig config = new LoggerServiceConfig();
config.Init();
Assert.IsTrue(config.ServiceEnabled);
Assert.IsTrue(config.EnableConsole);
Assert.AreEqual("Logger/log4net.xml", config.Log4NetConfigXml);
Assert.AreEqual("DEBUG", config.MinLogLevel);
}
}
}
2 changes: 2 additions & 0 deletions Assets/EditorTests/Logger/LoggerServiceConfigTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Assets/EditorTests/Logger/LoggerServiceTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using com.mapcolonies.core.Services.LoggerService;
using NUnit.Framework;
using UnityEngine;

namespace EditorTests.Logger
{
public class LoggerServiceTests
{
private ILogHandler _originalHandler;

[SetUp]
public void SetUp()
{
_originalHandler = Debug.unityLogger.logHandler;
}

[TearDown]
public void TearDown()
{
Debug.unityLogger.logHandler = _originalHandler;
}

[Test]
public void Ctor_WhenConfigValid_ReplacesUnityLogHandlerWithLog4NetHandler()
{
LoggerServiceConfig config = new LoggerServiceConfig();
config.Init();

ILogHandler before = Debug.unityLogger.logHandler;
LoggerService loggerService = null;

try
{
loggerService = new LoggerService(config);
Assert.IsInstanceOf<Log4NetHandler>(Debug.unityLogger.logHandler);
Assert.IsTrue(Debug.unityLogger.logEnabled);
}
finally
{
loggerService?.Dispose();
Assert.AreSame(before, Debug.unityLogger.logHandler);
}
}
}
}
2 changes: 2 additions & 0 deletions Assets/EditorTests/Logger/LoggerServiceTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Assets/PlayModeTests/Logger.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions Assets/PlayModeTests/Logger/LoggerInitializerPlayModeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System.Collections;
using System.Reflection;
using com.mapcolonies.core.Services.LoggerService;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;

namespace PlayModeTests.Logger
{
public class LoggerInitializerPlayModeTests
{
private ILogHandler _originalHandler;

[SetUp]
public void SetUp()
{
_originalHandler = Debug.unityLogger.logHandler;
Log4NetHandler.ApplicationDataPath = null;
Log4NetHandler.UnityVersion = null;
}

[TearDown]
public void TearDown()
{
TryCallDispose();
Debug.unityLogger.logHandler = _originalHandler;
}

[UnityTest]
public IEnumerator Init_SetsHandlerAndStaticFields_AndDisposeRestoresHandler()
{
LoggerInitializer.Init();
yield return null;

Assert.IsInstanceOf<Log4NetHandler>(Debug.unityLogger.logHandler);
Assert.AreEqual(Application.dataPath, Log4NetHandler.ApplicationDataPath);
Assert.NotNull(Log4NetHandler.UnityVersion);

TryCallDispose();
Assert.AreSame(_originalHandler, Debug.unityLogger.logHandler);
}

private void TryCallDispose()
{
MethodInfo m = typeof(LoggerInitializer).GetMethod("Dispose", BindingFlags.NonPublic | BindingFlags.Static);
m?.Invoke(null, null);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading