tests: add tests
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
namespace StevesBot.Worker.Tests.Unit;
|
||||
|
||||
public class HelloDiscordEventTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldInitializeProperties()
|
||||
{
|
||||
var helloEvent = new HelloDiscordEvent();
|
||||
var helloData = new HelloData();
|
||||
|
||||
helloEvent.OpCode.Should().Be(0);
|
||||
helloEvent.Sequence.Should().BeNull();
|
||||
helloEvent.Type.Should().BeNull();
|
||||
helloEvent.Data.Should().BeEquivalentTo(helloData);
|
||||
helloData.HeartbeatInterval.Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithParameters_ItShouldInitializeProperties()
|
||||
{
|
||||
var opCode = 1;
|
||||
var sequence = 2;
|
||||
var type = "type";
|
||||
var heartbeatInterval = 1000;
|
||||
|
||||
|
||||
var helloData = new HelloData
|
||||
{
|
||||
HeartbeatInterval = heartbeatInterval
|
||||
};
|
||||
|
||||
var helloEvent = new HelloDiscordEvent
|
||||
{
|
||||
OpCode = opCode,
|
||||
Sequence = sequence,
|
||||
Type = type,
|
||||
Data = helloData
|
||||
};
|
||||
|
||||
helloEvent.OpCode.Should().Be(opCode);
|
||||
helloEvent.Sequence.Should().Be(sequence);
|
||||
helloEvent.Type.Should().Be(type);
|
||||
helloEvent.Data.Should().BeSameAs(helloData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenCalled_ItShouldReturnHelloDiscordEvent()
|
||||
{
|
||||
var data = new
|
||||
{
|
||||
op = 0,
|
||||
s = null as int?,
|
||||
t = null as string,
|
||||
d = new
|
||||
{
|
||||
heartbeat_interval = 1000
|
||||
}
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(data);
|
||||
|
||||
var helloEvent = JsonSerializer.Deserialize<HelloDiscordEvent>(json);
|
||||
|
||||
helloEvent.Should().NotBeNull();
|
||||
helloEvent!.OpCode.Should().Be(data.op);
|
||||
helloEvent.Sequence.Should().Be(data.s);
|
||||
helloEvent.Type.Should().Be(data.t);
|
||||
helloEvent.Data.Should().NotBeNull();
|
||||
helloEvent.Data!.HeartbeatInterval.Should().Be(data.d.heartbeat_interval);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
namespace StevesBot.Worker.Tests.Unit;
|
||||
|
||||
public class ReadyDiscordEventTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldInitializeProperties()
|
||||
{
|
||||
var readyEvent = new ReadyDiscordEvent();
|
||||
var readyData = new ReadyData();
|
||||
|
||||
readyEvent.OpCode.Should().Be(0);
|
||||
readyEvent.Sequence.Should().BeNull();
|
||||
readyEvent.Type.Should().BeNull();
|
||||
readyEvent.Data.Should().BeEquivalentTo(readyData);
|
||||
readyData.Version.Should().Be(0);
|
||||
readyData.SessionId.Should().Be(string.Empty);
|
||||
readyData.ResumeGatewayUrl.Should().Be(string.Empty);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledWithParameters_ItShouldInitializeProperties()
|
||||
{
|
||||
var readyData = new ReadyData
|
||||
{
|
||||
Version = 1,
|
||||
SessionId = "session_id",
|
||||
ResumeGatewayUrl = "resume_gateway_url"
|
||||
};
|
||||
|
||||
var readyEvent = new ReadyDiscordEvent
|
||||
{
|
||||
OpCode = 1,
|
||||
Sequence = 2,
|
||||
Type = "type",
|
||||
Data = readyData
|
||||
};
|
||||
|
||||
readyEvent.OpCode.Should().Be(1);
|
||||
readyEvent.Sequence.Should().Be(2);
|
||||
readyEvent.Type.Should().Be("type");
|
||||
readyEvent.Data.Should().BeSameAs(readyData);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Deserialize_WhenCalled_ItShouldReturnReadyDiscordEvent()
|
||||
{
|
||||
var data = new
|
||||
{
|
||||
op = 0,
|
||||
s = null as int?,
|
||||
t = null as string,
|
||||
d = new
|
||||
{
|
||||
v = 1,
|
||||
session_id = "session_id",
|
||||
resume_gateway_url = "resume_gateway_url"
|
||||
}
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(data);
|
||||
|
||||
var readyEvent = JsonSerializer.Deserialize<ReadyDiscordEvent>(json);
|
||||
|
||||
readyEvent.Should().NotBeNull();
|
||||
readyEvent!.OpCode.Should().Be(data.op);
|
||||
readyEvent.Sequence.Should().Be(data.s);
|
||||
readyEvent.Type.Should().Be(data.t);
|
||||
readyEvent.Data.Version.Should().Be(data.d.v);
|
||||
readyEvent.Data.SessionId.Should().Be(data.d.session_id);
|
||||
readyEvent.Data.ResumeGatewayUrl.Should().Be(data.d.resume_gateway_url);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
global using System.Net.WebSockets;
|
||||
global using System.Text;
|
||||
global using System.Text.Json;
|
||||
|
||||
global using Microsoft.AspNetCore.Builder;
|
||||
global using Microsoft.AspNetCore.Hosting;
|
||||
@@ -12,4 +13,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;
|
||||
global using StevesBot.Worker.WebSockets;
|
||||
Reference in New Issue
Block a user