public void RequestReplyTest(string dest) { ITransportResolver resolver = MockTransportResolver(); using (IMessagingEngine engine = new MessagingEngine(resolver, new SonicTransportFactory())) { engine.SerializationManager.RegisterSerializer("fake", typeof(string), new FakeStringSerializer()); string response; using ( engine.RegisterHandler <string, string>(s => s == "ping" ? "pong" : "error", new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE1, serializationFormat: "fake"))) { var stopwatch = Stopwatch.StartNew(); response = engine.SendRequest <string, string>("ping", new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE1, serializationFormat: "fake")); stopwatch.Stop(); Console.WriteLine("Roundtrip: " + stopwatch.ElapsedMilliseconds + "ms"); } var requestFinished = new ManualResetEvent(false); Exception exception = null; var thread = new Thread(() => { try { engine.SendRequest <string, string>("ping", new Endpoint(TransportConstants.TRANSPORT_ID1, TransportConstants.QUEUE1, serializationFormat: "fake"), 500); } catch (Exception ex) { exception = ex; } requestFinished.Set(); }); thread.Start(); Assert.That(response, Is.EqualTo("pong")); Assert.That(requestFinished.WaitOne(2000), Is.True, "Request has not finished after timeout."); Assert.That(exception, Is.Not.Null, "Request was handled after handler registration is disposed."); Assert.That(exception, Is.InstanceOf <TimeoutException>(), "Wrong exception was thrown on timeout."); if (thread.IsAlive) { thread.Abort(); } } }