public async Task ShouldSendAndReceiveBinaryDataCorrectly() { var seed1 = "b71a349865ed5907821e903389e83424d037d4e1680935fd3c1f33408df2fdf5"; var seed2 = "f40bc0903ae5064ec225a82d1ca8ca6c63d4ecf2c41689b82fc6bf581ea3b67b"; var address1 = "3fc6bbdae9be658e7b7e85de65d04f3bd39ad41afc316b82314cca7c62e9fd6e"; var address2 = "fc6c231915d568f50e4dac2858e833ec7fc6c27e9cd040ced08f941e5c8a32f7"; MultiClient client1 = default; var client2 = new MultiClient(new MultiClientOptions { SeedHex = seed2 }); var expectedRequestData = new byte[] { 5, 5, 5, 5 }; var expectedResponseData = new byte[] { 1, 2, 3, 4, 5 }; client2.OnMessage(request => { Assert.Equal(address1, request.Source); Assert.Equal(expectedRequestData, request.Payload); return(Task.FromResult((object)expectedResponseData)); }); var finished = false; client2.OnConnect(request => { Task.Delay(500).GetAwaiter().GetResult(); client1 = new MultiClient(new MultiClientOptions { SeedHex = seed1 }); client1.OnConnect(request => { var response = client1.SendAsync <byte[]>(address2, expectedRequestData); Assert.NotNull(response.Result); Assert.Equal(expectedResponseData, response.Result); finished = true; }); }); while (finished == false) { await Task.Delay(100); } client1.CloseAsync(); client2.CloseAsync(); Assert.True(finished); }
public async Task ShouldSendAndReceiveTextMessageCorrectly() { var seed1 = "b71a349865ed5907821e903389e83424d037d4e1680935fd3c1f33408df2fdf5"; var seed2 = "f40bc0903ae5064ec225a82d1ca8ca6c63d4ecf2c41689b82fc6bf581ea3b67b"; var address1 = "3fc6bbdae9be658e7b7e85de65d04f3bd39ad41afc316b82314cca7c62e9fd6e"; var address2 = "fc6c231915d568f50e4dac2858e833ec7fc6c27e9cd040ced08f941e5c8a32f7"; MultiClient client1 = default; var client2 = new MultiClient(new MultiClientOptions { SeedHex = seed2 }); var expectedRequestText = "Hello world!"; var expectedResponseText = "Hi there!"; client2.OnMessage(async request => { Assert.Equal(address1, request.Source); Assert.Equal(expectedRequestText, request.TextMessage); return(await Task.FromResult(expectedResponseText)); }); var finished = false; client2.OnConnect(request => { client1 = new MultiClient(new MultiClientOptions { SeedHex = seed1 }); client1.OnConnect(request => { var response = client1.SendAsync <string>(address2, expectedRequestText); Assert.NotNull(response.Result); Assert.Equal(expectedResponseText, response.Result); finished = true; }); }); client1.CloseAsync(); client2.CloseAsync(); Assert.True(finished); }