I need to create an integration test that demonstrates successful sending of a UDP packet to a remote piece of software. The remote software is unavailable in a test environent (it's a legacy but still supported version) and not under my control, so I thought I'd set up a test that at least proves the command's going out as expected. After reading this question's answers, I set up my code as follows:
public void TestRemoteCommand()
{
//A "strategy picker"; will instantiate a version-specific
//implementation, using a UdpClient in this case
var communicator = new NotifyCommunicator(IPAddress.Loopback.ToString(), "1.0");
const string message = "REMOTE COMMAND";
const int port = <specific port the actual remote software listens on>;
var receivingEndpoint = new IPEndPoint(IPAddress.Loopback, port);
//my test listener; will listen on the same port already connected to by
//the communicator's UdpClient (set up without sharing)
var client = new UdpClient();
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
client.Client.Bind(receivingEndpoint);
//Results in the UDP diagram being sent
communicator.SendRemoteCommand();
//This assertion always fails
Assert.IsTrue(client.Available > 0);
var result = client.Receive(ref receivingEndpoint);
Assert.AreEqual(result.Select(b => (char)b).ToArray(), message.ToCharArray());
}
However, this isn't working as in the comment above. Anybody see what I'm missing here?