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;
@@ -4,5 +4,5 @@ internal sealed class DiscordClientOptions
{
public string ApiUrl { get; init; } = string.Empty;
public string AppToken { get; init; } = string.Empty;
public int Intents { get; init; }
public long Intents { get; init; }
}
+23 -23
View File
@@ -2,28 +2,28 @@ namespace StevesBot.Worker.Discord;
internal static class DiscordIntents
{
public const int Guilds = 1 << 0;
public const int GuildMembers = 1 << 1;
public const int GuildModeration = 1 << 2;
public const int GuildExpressions = 1 << 3;
public const int GuildIntegrations = 1 << 4;
public const int GuildWebhooks = 1 << 5;
public const int GuildInvites = 1 << 6;
public const int GuildVoiceStates = 1 << 7;
public const int GuildPresences = 1 << 8;
public const int GuildMessages = 1 << 9;
public const int GuildMessageReactions = 1 << 10;
public const int GuildMessageTyping = 1 << 11;
public const int DirectMessages = 1 << 12;
public const int DirectMessageReactions = 1 << 13;
public const int DirectMessageTyping = 1 << 14;
public const int MessageContent = 1 << 15;
public const int GuildScheduledEvents = 1 << 16;
public const int AutoModerationConfiguration = 1 << 20;
public const int AutoModerationExecution = 1 << 21;
public const int GuildMessagePolls = 1 << 24;
public const int DirectMessagePolls = 1 << 25;
public const int All = Guilds
public const long Guilds = 1 << 0;
public const long GuildMembers = 1 << 1;
public const long GuildModeration = 1 << 2;
public const long GuildExpressions = 1 << 3;
public const long GuildIntegrations = 1 << 4;
public const long GuildWebhooks = 1 << 5;
public const long GuildInvites = 1 << 6;
public const long GuildVoiceStates = 1 << 7;
public const long GuildPresences = 1 << 8;
public const long GuildMessages = 1 << 9;
public const long GuildMessageReactions = 1 << 10;
public const long GuildMessageTyping = 1 << 11;
public const long DirectMessages = 1 << 12;
public const long DirectMessageReactions = 1 << 13;
public const long DirectMessageTyping = 1 << 14;
public const long MessageContent = 1 << 15;
public const long GuildScheduledEvents = 1 << 16;
public const long AutoModerationConfiguration = 1 << 20;
public const long AutoModerationExecution = 1 << 21;
public const long GuildMessagePolls = 1 << 24;
public const long DirectMessagePolls = 1 << 25;
public const long All = Guilds
| GuildMembers
| GuildModeration
| GuildExpressions
@@ -44,4 +44,4 @@ internal static class DiscordIntents
| AutoModerationExecution
| GuildMessagePolls
| DirectMessagePolls;
}
}
@@ -0,0 +1,6 @@
namespace StevesBot.Worker.WebSockets;
internal interface IWebSocketFactory
{
IWebSocket Create();
}
@@ -0,0 +1,9 @@
namespace StevesBot.Worker.WebSockets;
internal class WebSocketFactory : IWebSocketFactory
{
public IWebSocket Create()
{
return new WebSocket();
}
}