tests: add tests

This commit is contained in:
Stevan Freeborn
2025-05-09 18:28:40 -05:00
parent 4bfe705fb6
commit c16e8754db
12 changed files with 133 additions and 26 deletions
+1
View File
@@ -5,3 +5,4 @@ dotnet_diagnostic.CA2201.severity = none
dotnet_diagnostic.CA2007.severity = none
dotnet_diagnostic.CA1303.severity = none
dotnet_diagnostic.CA1031.severity = none
dotnet_diagnostic.CA1034.severity = none
@@ -1,3 +1,5 @@
using WebSocket = System.Net.WebSockets.WebSocket;
namespace StevesBot.Worker.Tests.Integration.Infrastructure;
# pragma warning disable CA1001
@@ -1,5 +1,3 @@
using System.Text;
using WebSocket = StevesBot.Worker.WebSockets.WebSocket;
namespace StevesBot.Worker.Tests.Integration;
@@ -0,0 +1,16 @@
namespace StevesBot.Worker.Tests.Unit;
public class DiscordEventTypesTests
{
[Theory]
[MemberData(nameof(TestData))]
public void Event_WhenCalled_ItShouldReturnCorrectValue(string eventType, string expectedValue)
{
eventType.Should().Be(expectedValue);
}
public static TheoryData<string, string> TestData => new()
{
{ DiscordEventTypes.Ready, "READY" },
};
}
@@ -0,0 +1,37 @@
namespace StevesBot.Worker.Tests.Unit;
public class DiscordIntentsTests
{
[Theory]
[MemberData(nameof(TestData))]
public void Intents_ShouldHaveCorrectValue(long intent, long expectedValue)
{
intent.Should().Be(expectedValue);
}
public static TheoryData<long, long> TestData => new()
{
{ DiscordIntents.Guilds, 1 },
{ DiscordIntents.GuildMembers, 2 },
{ DiscordIntents.GuildModeration, 4 },
{ DiscordIntents.GuildExpressions, 8 },
{ DiscordIntents.GuildIntegrations, 16 },
{ DiscordIntents.GuildWebhooks, 32 },
{ DiscordIntents.GuildInvites, 64 },
{ DiscordIntents.GuildVoiceStates, 128 },
{ DiscordIntents.GuildPresences, 256 },
{ DiscordIntents.GuildMessages, 512 },
{ DiscordIntents.GuildMessageReactions, 1024 },
{ DiscordIntents.GuildMessageTyping, 2048 },
{ DiscordIntents.DirectMessages, 4096 },
{ DiscordIntents.DirectMessageReactions, 8192 },
{ DiscordIntents.DirectMessageTyping, 16384 },
{ DiscordIntents.MessageContent, 32768 },
{ DiscordIntents.GuildScheduledEvents, 65536 },
{ DiscordIntents.AutoModerationConfiguration, 1048576 },
{ DiscordIntents.AutoModerationExecution, 2097152 },
{ DiscordIntents.GuildMessagePolls, 16777216 },
{ DiscordIntents.DirectMessagePolls, 33554432 },
{ DiscordIntents.All, 53608447 }
};
}
@@ -0,0 +1,19 @@
namespace StevesBot.Worker.Tests.Unit;
public class DiscordOpCodesTests
{
[Theory]
[MemberData(nameof(TestData))]
public void OpCode_ShouldHaveCorrectValue(int opCode, int expectedValue)
{
opCode.Should().Be(expectedValue);
}
public static TheoryData<int, int> TestData => new()
{
{ DiscordOpCodes.Dispatch, 0 },
{ DiscordOpCodes.Heartbeat, 1 },
{ DiscordOpCodes.Hello, 10 },
{ DiscordOpCodes.HeartbeatAck, 11 }
};
}
@@ -0,0 +1,17 @@
using WebSocket = StevesBot.Worker.WebSockets.WebSocket;
namespace StevesBot.Worker.Tests.Unit;
public class WebSocketFactoryTests
{
private readonly WebSocketFactory _webSocketFactory = new();
[Fact]
public void Create_WhenCalled_ItShouldReturnNewWebSocketInstance()
{
var result = _webSocketFactory.Create();
result.Should().NotBeNull();
result.Should().BeOfType<WebSocket>();
}
}
+2
View File
@@ -1,4 +1,5 @@
global using System.Net.WebSockets;
global using System.Text;
global using Microsoft.AspNetCore.Builder;
global using Microsoft.AspNetCore.Hosting;
@@ -11,3 +12,4 @@ global using StevesBot.Worker.Discord;
global using StevesBot.Worker.Discord.Events;
global using StevesBot.Worker.Tests.Integration.Infrastructure;
global using StevesBot.Worker.Threading;
global using StevesBot.Worker.WebSockets;