Skip to content

Commit

Permalink
adding non-zero offset to the ReceiveMessageFrom test
Browse files Browse the repository at this point in the history
  • Loading branch information
ovebastiansen committed Jan 29, 2021
1 parent 2efca1e commit 57c84d3
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public async Task ReceiveSent_TCP_Success(bool ipv6)
[InlineData(true)]
public async Task ReceiveSentMessages_UDP_Success(bool ipv4)
{
const int Offset = 10;
const int DatagramSize = 256;
const int DatagramsToSend = 16;

Expand All @@ -69,7 +70,9 @@ public async Task ReceiveSentMessages_UDP_Success(bool ipv4)
sender.BindToAnonymousPort(address);

byte[] sendBuffer = new byte[DatagramSize];
byte[] receiveBuffer = new byte[DatagramSize];
var receiveInternalBuffer = new byte[DatagramSize + Offset];
var emptyBuffer = new byte[Offset];
ArraySegment<byte> receiveBuffer = new ArraySegment<byte>(receiveInternalBuffer, Offset, DatagramSize);
Random rnd = new Random(0);

IPEndPoint remoteEp = new IPEndPoint(ipv4 ? IPAddress.Any : IPAddress.IPv6Any, 0);
Expand All @@ -83,7 +86,8 @@ public async Task ReceiveSentMessages_UDP_Success(bool ipv4)
IPPacketInformation packetInformation = result.PacketInformation;

Assert.Equal(DatagramSize, result.ReceivedBytes);
AssertExtensions.SequenceEqual(sendBuffer, receiveBuffer);
AssertExtensions.SequenceEqual(emptyBuffer, new ReadOnlySpan<byte>(receiveInternalBuffer, 0, Offset));
AssertExtensions.SequenceEqual(sendBuffer, new ReadOnlySpan<byte>(receiveInternalBuffer, Offset, DatagramSize));
Assert.Equal(sender.LocalEndPoint, result.RemoteEndPoint);
Assert.Equal(((IPEndPoint)sender.LocalEndPoint).Address, packetInformation.Address);
}
Expand Down

0 comments on commit 57c84d3

Please sign in to comment.