Skip to content

Commit

Permalink
Make TestMessage work
Browse files Browse the repository at this point in the history
  • Loading branch information
CrunkA3 committed Jul 17, 2022
1 parent a9ea96d commit e38e400
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions WeatherFlowUdpListener.Tests/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
using System.Net;
using System.Net.Sockets;

namespace WeatherFlowUdpListener.Tests;

public class Tests
{
WFListener? WFListener;
FakeUdpClient? fakeUdpClient;
WFListenerOptions? udpClientOptions;


[SetUp]
public void Setup()
{
fakeUdpClient = new FakeUdpClient();
WFListener = WFListener.Create(options =>
{
options.Client = fakeUdpClient;
});
WFListener = WFListener.Create(options => udpClientOptions = options);
}

[Test]
Expand All @@ -26,12 +24,14 @@ public async Task TestGetSomeMessageAsync()
Assert.IsNotNull(WFListener);
WFListener!.OnReceiveMessage(m =>
{
Assert.IsNotEmpty(m.Type);
Assert.AreEqual(m.Type, "evt_precip");
cancellationTokenSource.Cancel();
});

var listenTask = WFListener.ListenAsync(cancellationToken);
fakeUdpClient!.SendFakeData("{\"serial_number\":\"SK-00008453\",\"type\":\"evt_precip\",\"hub_sn\":\"HB-00000001\",\"evt\":[1493322445]}");

var sendData = System.Text.Encoding.ASCII.GetBytes("{\"serial_number\":\"SK-00008453\",\"type\":\"evt_precip\",\"hub_sn\":\"HB-00000001\",\"evt\":[1493322445]}");
await udpClientOptions!.Client.SendAsync(sendData, new IPEndPoint(IPAddress.Loopback, WFListenerOptions.listenPort));

await listenTask;
}
Expand Down

0 comments on commit e38e400

Please sign in to comment.