https://github.com/vforteli/flexinets.net.udpclient
https://github.com/vforteli/flexinets.net.udpclient
mock netstandard testing udp-client
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/vforteli/flexinets.net.udpclient
- Owner: vforteli
- License: mit
- Created: 2018-03-18T18:33:20.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-03-20T09:11:12.000Z (over 8 years ago)
- Last Synced: 2025-10-05T23:25:37.188Z (9 months ago)
- Topics: mock, netstandard, testing, udp-client
- Language: C#
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Flexinets.Net.IUdpClient
The purpose of the mock UdpClient is to test receiveing and sending UDP packets.
Currently it is only designed for limited use cases where a server receive an UDP packet, and then responds to it using the same UdpClient.
Usage
```
var expected = "test";
var bytes = Encoding.UTF8.GetBytes(expected);
var client = new UdpClientMock();
var factory = new UdpClientMockFactory(client);
var task = factory.CreateClient(null).ReceiveAsync();
// This will wait until some other thread sends a response to the same udpclient
var response = await client.SendMock(new UdpReceiveResult(bytes, new IPEndPoint(IPAddress.Any, 1812)));
var actual = Encoding.UTF8.GetString(response.Buffer);
Assert.AreEqual(expected, actual);