|
| 1 | +using System; |
| 2 | +using Xunit; |
| 3 | +using NSubstitute; |
| 4 | +using UnityEngine; |
| 5 | +using ModuleManager.Collections; |
| 6 | +using ModuleManager.Logging; |
| 7 | + |
| 8 | +namespace ModuleManagerTests.Logging |
| 9 | +{ |
| 10 | + public class QueueLoggerTest |
| 11 | + { |
| 12 | + private IMessageQueue<ILogMessage> queue; |
| 13 | + private QueueLogger logger; |
| 14 | + |
| 15 | + public QueueLoggerTest() |
| 16 | + { |
| 17 | + queue = Substitute.For<IMessageQueue<ILogMessage>>(); |
| 18 | + logger = new QueueLogger(queue); |
| 19 | + } |
| 20 | + |
| 21 | + [Fact] |
| 22 | + public void TestLog() |
| 23 | + { |
| 24 | + logger.Log(LogType.Log, "this is a log message"); |
| 25 | + queue.Received().Add(Arg.Is<NormalMessage>(m => m.logType == LogType.Log && m.message == "this is a log message")); |
| 26 | + } |
| 27 | + |
| 28 | + [Fact] |
| 29 | + public void TestInfo() |
| 30 | + { |
| 31 | + logger.Info("useful information"); |
| 32 | + queue.Received().Add(Arg.Is<NormalMessage>(m => m.logType == LogType.Log && m.message == "useful information")); |
| 33 | + } |
| 34 | + |
| 35 | + [Fact] |
| 36 | + public void TestWarning() |
| 37 | + { |
| 38 | + logger.Warning("not to alarm you, but something might be wrong"); |
| 39 | + queue.Received().Add(Arg.Is<NormalMessage>(m => m.logType == LogType.Warning && m.message == "not to alarm you, but something might be wrong")); |
| 40 | + } |
| 41 | + |
| 42 | + [Fact] |
| 43 | + public void TestError() |
| 44 | + { |
| 45 | + logger.Error("you broke everything"); |
| 46 | + queue.Received().Add(Arg.Is<NormalMessage>(m => m.logType == LogType.Error && m.message == "you broke everything")); |
| 47 | + } |
| 48 | + |
| 49 | + |
| 50 | + [Fact] |
| 51 | + public void TestException() |
| 52 | + { |
| 53 | + Exception e = new Exception(); |
| 54 | + logger.Exception("An exception was thrown", e); |
| 55 | + queue.Received().Add(Arg.Is<ExceptionMessage>(m => m.message == "An exception was thrown" && m.exception == e)); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments