You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Returns not working on UdpClient.Receive() method.
Class code:
var remoteEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0);
var receiveBytes = this.udpClient.Receive(ref remoteEndPoint);
var responseData = Encoding.ASCII.GetString(receiveBytes);
Unit testing code:
var remoteEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0);
var b = Encoding.ASCII.GetBytes("responseData");
udpClientMock.Setup(x => x.Receive(ref remoteEndPoint)).Returns(b);
Nothing is returned (byte[]). Exception is "The following setups were not matched:
IUdpClientExtended x => x.Receive(0.0.0.0:0)". It is also problem with replacing Returns with Throws.
With Strict mode, the error says: "Invocation failed with mock behavior Strict. All invocations on the mock must have a corresponding setup."
The text was updated successfully, but these errors were encountered:
I am not sure that I understand how your two repro code blocks are supposed to work and be related to one another. It seems incomplete. Could you please post a minimally complete code example that leads to the error message you're describing?
This doesn't work because the instance of IPEndPoint you're passing to your mock (differentEndpoint) is not the exact same instance that you used during the mock setup (even though both have the same value).
AFAIK, Moq doesn't currently support It.IsAny<T> for ref parameters. So the solution here is either of these:
Change the definition of IUdpClientExtended so that Receive's parameter is by value instead of ref.
Use the exact same instance of IPEndPoint to your mock that you're using during the setup.
If the above doesn't help you, or my repro code doesn't match your scenario, please report back and we can reopen this issue.
Returns not working on UdpClient.Receive() method.
Class code:
Unit testing code:
Nothing is returned (byte[]). Exception is "The following setups were not matched:
IUdpClientExtended x => x.Receive(0.0.0.0:0)". It is also problem with replacing Returns with Throws.
With Strict mode, the error says: "Invocation failed with mock behavior Strict. All invocations on the mock must have a corresponding setup."
The text was updated successfully, but these errors were encountered: