You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

69 lines
1.8 KiB

  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using MQTTnet.Diagnostics;
  3. namespace MQTTnet.Tests
  4. {
  5. [TestClass]
  6. public class MqttNetLogger_Tests
  7. {
  8. [TestMethod]
  9. public void Root_Log_Messages()
  10. {
  11. var logger = new MqttNetLogger();
  12. var childLogger = logger.CreateScopedLogger("Source1");
  13. var logMessagesCount = 0;
  14. logger.LogMessagePublished += (s, e) =>
  15. {
  16. logMessagesCount++;
  17. };
  18. childLogger.Verbose("Verbose");
  19. childLogger.Info("Info");
  20. childLogger.Warning(null, "Warning");
  21. childLogger.Error(null, "Error");
  22. Assert.AreEqual(4, logMessagesCount);
  23. }
  24. [TestMethod]
  25. public void Bubbling_Log_Messages()
  26. {
  27. var logger = new MqttNetLogger();
  28. var childLogger = logger.CreateScopedLogger("Source1");
  29. var logMessagesCount = 0;
  30. logger.LogMessagePublished += (s, e) =>
  31. {
  32. logMessagesCount++;
  33. };
  34. childLogger.Verbose("Verbose");
  35. childLogger.Info("Info");
  36. childLogger.Warning(null, "Warning");
  37. childLogger.Error(null, "Error");
  38. Assert.AreEqual(4, logMessagesCount);
  39. }
  40. [TestMethod]
  41. public void Set_Custom_Log_ID()
  42. {
  43. var logger = new MqttNetLogger("logId");
  44. var childLogger = logger.CreateScopedLogger("Source1");
  45. logger.LogMessagePublished += (s, e) =>
  46. {
  47. Assert.AreEqual("logId", e.LogMessage.LogId);
  48. };
  49. childLogger.Verbose("Verbose");
  50. childLogger.Info("Info");
  51. childLogger.Warning(null, "Warning");
  52. childLogger.Error(null, "Error");
  53. }
  54. }
  55. }