tests: oh we love our tests

This commit is contained in:
Stevan Freeborn
2025-05-22 23:00:42 -05:00
parent ceb693acbc
commit 6c25d25ea1
3 changed files with 115 additions and 1 deletions
@@ -28,4 +28,55 @@ public class WelcomeMessageHandlerTests
Times.Never
);
}
[Fact]
public async Task HandleAsync_WhenMessageCreateEventIsNotAUserJoinMessage_ItShouldNotCreateMessage()
{
var @event = new MessageCreateDiscordEvent()
{
Data = new()
{
Type = -1,
},
};
await WelcomeMessageHandler.HandleAsync(@event, _serviceProvider);
_mockDiscordRestClient
.Verify(
static c => c.CreateMessageAsync(It.IsAny<string>(), It.IsAny<CreateMessageRequest>(), It.IsAny<CancellationToken>()),
Times.Never
);
}
[Fact]
public async Task HandleAsync_WhenUserJoinMessageCreateEventReceived_ItShouldCreateWelcomeMessage()
{
_mockDiscordRestClient
.Setup(static c => c.CreateMessageAsync(It.IsAny<string>(), It.IsAny<CreateMessageRequest>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new DiscordMessage());
var @event = new MessageCreateDiscordEvent()
{
Data = new()
{
Type = DiscordMessageTypes.UserJoin,
Id = Guid.NewGuid().ToString(),
ChannelId = Guid.NewGuid().ToString(),
GuildId = Guid.NewGuid().ToString(),
Author = new()
{
Id = Guid.NewGuid().ToString(),
}
}
};
await WelcomeMessageHandler.HandleAsync(@event, _serviceProvider);
_mockDiscordRestClient
.Verify(
static c => c.CreateMessageAsync(It.IsAny<string>(), It.IsAny<CreateMessageRequest>(), It.IsAny<CancellationToken>()),
Times.Once
);
}
}