tests: add tests
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
namespace StevesBot.Worker.Tests.Integration;
|
||||||
|
|
||||||
|
public class DiscordEventConverterTests
|
||||||
|
{
|
||||||
|
private readonly JsonSerializerOptions _jsonSerializerOptions = new()
|
||||||
|
{
|
||||||
|
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
|
||||||
|
Converters =
|
||||||
|
{
|
||||||
|
new DiscordEventConverter()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Deserialize_WhenCalledWithUnknownOpCode_ItShouldReturnADiscordEvent()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private string Serialize(object obj)
|
||||||
|
{
|
||||||
|
return JsonSerializer.Serialize(obj, _jsonSerializerOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
private T? Deserialize<T>(string json)
|
||||||
|
{
|
||||||
|
return JsonSerializer.Deserialize<T>(json, _jsonSerializerOptions);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
namespace StevesBot.Worker.Tests.Unit;
|
||||||
|
|
||||||
|
public class HeartbeatDiscordEventTests
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData(null)]
|
||||||
|
[InlineData(1)]
|
||||||
|
public void Constructor_WhenCalled_ItShouldInitializeProperties(int? sequence)
|
||||||
|
{
|
||||||
|
var heartbeatEvent = new HeartbeatDiscordEvent(sequence);
|
||||||
|
|
||||||
|
heartbeatEvent.OpCode.Should().Be(1);
|
||||||
|
heartbeatEvent.Sequence.Should().Be(sequence);
|
||||||
|
heartbeatEvent.Type.Should().BeNull();
|
||||||
|
heartbeatEvent.Data.Should().BeNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using WebSocket = StevesBot.Worker.WebSockets.WebSocket;
|
||||||
|
|
||||||
|
namespace StevesBot.Worker.Tests.Unit;
|
||||||
|
|
||||||
|
public class WebSocketTests
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void State_WhenCalled_ItShouldReturnWebSocketState()
|
||||||
|
{
|
||||||
|
using var webSocket = new WebSocket();
|
||||||
|
var state = webSocket.State;
|
||||||
|
|
||||||
|
state.Should().Be(WebSocketState.None);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ namespace StevesBot.Worker.Discord.Events;
|
|||||||
internal sealed record HelloDiscordEvent : DiscordEvent
|
internal sealed record HelloDiscordEvent : DiscordEvent
|
||||||
{
|
{
|
||||||
[JsonPropertyName("d")]
|
[JsonPropertyName("d")]
|
||||||
public new HelloData? Data { get; init; }
|
public new HelloData Data { get; init; } = new HelloData();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal sealed record HelloData
|
internal sealed record HelloData
|
||||||
|
|||||||
Reference in New Issue
Block a user