tests: add unit tests for CreateMessageRequest, DiscordMessageReference, and DiscordRestClient

refactor: update DiscordRestClient and IDiscordRestClient to use default CancellationToken
refactor: rename MessageReference to DiscordMessageReference and add DiscordMessageReferenceTypes
chore: update WelcomeMessageHandler to use new DiscordMessageReference
This commit is contained in:
Stevan Freeborn
2025-05-22 18:02:41 -05:00
parent 58dc5896ca
commit ceb693acbc
14 changed files with 245 additions and 17 deletions
@@ -0,0 +1,31 @@
using StevesBot.Worker.Handlers;
namespace StevesBot.Worker.Tests.Unit;
public class WelcomeMessageHandlerTests
{
private readonly Mock<IDiscordRestClient> _mockDiscordRestClient = new();
private readonly Mock<ILogger<IDiscordGatewayClient>> _mockLogger = new();
private readonly IServiceProvider _serviceProvider;
public WelcomeMessageHandlerTests()
{
var serviceCollection = new ServiceCollection();
serviceCollection.AddSingleton(_mockDiscordRestClient.Object);
serviceCollection.AddSingleton(_mockLogger.Object);
_serviceProvider = serviceCollection.BuildServiceProvider();
}
[Fact]
public async Task HandleAsync_WhenEventIsNotMessageCreateEvent_ItShouldNotCreateMessage()
{
await WelcomeMessageHandler.HandleAsync(new DiscordEvent(), _serviceProvider);
_mockDiscordRestClient
.Verify(
static c => c.CreateMessageAsync(It.IsAny<string>(), It.IsAny<CreateMessageRequest>(), It.IsAny<CancellationToken>()),
Times.Never
);
}
}