Skip to content

Commit

Permalink
small extension to print out error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
juuwel committed May 28, 2024
1 parent 53a6407 commit 15d472a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Tests/PlantTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using api.Events.Collections.Server;
using api.Events.PlantEvents.Client;
using api.Events.PlantEvents.Server;
using api.Events.Statistics;
Expand All @@ -19,6 +18,7 @@ public async Task CreatePlant()
var createPlantDto = GenerateRandomCreatePlantDto();

var webSocketTestClient = await new WebSocketTestClient().ConnectAsync();
webSocketTestClient.SubscribeToErrors();

await webSocketTestClient.DoAndAssert(new ClientWantsToCreatePlantDto { CreatePlantDto = createPlantDto, Jwt = jwt }, receivedMessages =>
{
Expand Down
21 changes: 21 additions & 0 deletions Tests/WebSocketTestClientExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text.Json;
using api.Events.Global;
using lib;
using Websocket.Client;

namespace Tests;

public static class WebSocketTestClientExtension
{
public static void SubscribeToErrors(this WebSocketTestClient client)
{
client.Client.MessageReceived.Subscribe<ResponseMessage>(msg =>
{
var baseDto = JsonSerializer.Deserialize<BaseDto>(msg.Text);
if (baseDto is ServerSendsErrorMessage errorMessage)
{
Console.WriteLine(errorMessage.Error);
}
});
}
}

0 comments on commit 15d472a

Please sign in to comment.