public void CallbackLoggerTest(LogLevel level) { MsalLogger logger = CreateLogger(level); var counter = 0; var validationCounter = 1; var levelToValidate = LogLevel.Always; Action incrementCounter = () => { if (level > levelToValidate) { validationCounter++; } levelToValidate++; }; _callback.When(x => x(LogLevel.Always, Arg.Any <string>(), false)).Do(x => counter++); logger.Always(TestConstants.TestMessage); Assert.AreEqual(validationCounter, counter); _callback.Received().Invoke(Arg.Is((LogLevel)validationCounter - 2), Arg.Any <string>(), Arg.Is(false)); incrementCounter.Invoke(); _callback.When(x => x(LogLevel.Error, Arg.Any <string>(), false)).Do(x => counter++); logger.Error(TestConstants.TestMessage); Assert.AreEqual(validationCounter, counter); _callback.Received().Invoke(Arg.Is((LogLevel)validationCounter - 2), Arg.Any <string>(), Arg.Is(false)); incrementCounter.Invoke(); _callback.When(x => x(LogLevel.Warning, Arg.Any <string>(), false)).Do(x => counter++); logger.Warning(TestConstants.TestMessage); Assert.AreEqual(validationCounter, counter); _callback.Received().Invoke(Arg.Is((LogLevel)validationCounter - 2), Arg.Any <string>(), Arg.Is(false)); incrementCounter.Invoke(); _callback.When(x => x(LogLevel.Info, Arg.Any <string>(), false)).Do(x => counter++); logger.Info(TestConstants.TestMessage); Assert.AreEqual(validationCounter, counter); incrementCounter.Invoke(); _callback.When(x => x(LogLevel.Verbose, Arg.Any <string>(), false)).Do(x => counter++); logger.Verbose(TestConstants.TestMessage); Assert.AreEqual(validationCounter, counter); }
public void CallbackTestErrorTest() { MsalLogger logger = CreateLogger(LogLevel.Error); var counter = 0; _callback.When(x => x(LogLevel.Error, Arg.Any <string>(), false)).Do(x => counter++); logger.Error(TestConstants.TestMessage); Assert.AreEqual(1, counter); _callback.Received().Invoke(Arg.Is(LogLevel.Error), Arg.Any <string>(), Arg.Is(false)); _callback.When(x => x(LogLevel.Warning, Arg.Any <string>(), false)).Do(x => counter++); logger.Warning(TestConstants.TestMessage); Assert.AreEqual(1, counter); _callback.Received().Invoke(Arg.Is(LogLevel.Error), Arg.Any <string>(), Arg.Is(false)); _callback.When(x => x(LogLevel.Info, Arg.Any <string>(), false)).Do(x => counter++); logger.Info(TestConstants.TestMessage); Assert.AreEqual(1, counter); _callback.When(x => x(LogLevel.Verbose, Arg.Any <string>(), false)).Do(x => counter++); logger.Verbose(TestConstants.TestMessage); Assert.AreEqual(1, counter); }
public void CallbackTestErrorTest() { Logger logger = new Logger(Guid.Empty, null); var counter = 0; Logger.Level = Logger.LogLevel.Error; _callback.When(x => x(Logger.LogLevel.Error, Arg.Any <string>(), false)).Do(x => counter++); logger.Error("test message"); Assert.AreEqual(1, counter); _callback.When(x => x(Logger.LogLevel.Warning, Arg.Any <string>(), false)).Do(x => counter++); logger.Warning("test message"); Assert.AreEqual(1, counter); _callback.When(x => x(Logger.LogLevel.Info, Arg.Any <string>(), false)).Do(x => counter++); logger.Info("test message"); Assert.AreEqual(1, counter); _callback.When(x => x(Logger.LogLevel.Verbose, Arg.Any <string>(), false)).Do(x => counter++); logger.Verbose("test message"); Assert.AreEqual(1, counter); }