UDP パケットをリモートのソフトウェアに正常に送信することを実証する統合テストを作成する必要があります。リモート ソフトウェアはテスト環境 (レガシーですがサポートされているバージョン) では使用できず、私の管理下にないため、少なくともコマンドが期待どおりに実行されることを証明するテストをセットアップすると考えました。この質問の回答を読んだ後、次のようにコードを設定しました。
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());
}
ただし、これは上記のコメントのようには機能しません。ここで私が見逃しているものを見た人はいますか?