From 2af4b2830109e109461ced12588bc66d2c19e699 Mon Sep 17 00:00:00 2001 From: austins Date: Tue, 8 Oct 2024 22:37:57 -0700 Subject: [PATCH] Add test for GatewayReconnectException log --- .../RedirectLogMessageToLoggerHandlerTests.cs | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/DiscordTranslationBot.Tests.Unit/Commands/Logging/RedirectLogMessageToLoggerHandlerTests.cs b/tests/DiscordTranslationBot.Tests.Unit/Commands/Logging/RedirectLogMessageToLoggerHandlerTests.cs index 5919709..eff8809 100644 --- a/tests/DiscordTranslationBot.Tests.Unit/Commands/Logging/RedirectLogMessageToLoggerHandlerTests.cs +++ b/tests/DiscordTranslationBot.Tests.Unit/Commands/Logging/RedirectLogMessageToLoggerHandlerTests.cs @@ -1,4 +1,5 @@ using Discord; +using Discord.WebSocket; using DiscordTranslationBot.Commands.Logging; namespace DiscordTranslationBot.Tests.Unit.Commands.Logging; @@ -38,4 +39,29 @@ public async Task Handle_RedirectLogMessageToLogger_Success(LogSeverity severity logEntry.Message.Should().Be($"Discord {command.LogMessage.Source}: {command.LogMessage.Message}"); logEntry.Exception.Should().Be(command.LogMessage.Exception); } + + [Fact] + public async Task Handle_RedirectLogMessageToLogger_GatewayReconnectException_ChangesLogLevel() + { + // Arrange + var command = new RedirectLogMessageToLogger + { + LogMessage = new LogMessage( + LogSeverity.Error, + "source1", + "message1", + new GatewayReconnectException("test")) + }; + + const LogLevel expectedLevel = LogLevel.Information; + + // Act + await _sut.Handle(command, CancellationToken.None); + + // Assert + var logEntry = _logger.Entries[0]; + logEntry.LogLevel.Should().Be(expectedLevel); + logEntry.Message.Should().Be($"Discord {command.LogMessage.Source}: {command.LogMessage.Message}"); + logEntry.Exception.Should().Be(command.LogMessage.Exception); + } }