public void TestHttpPipelineTransportTimeout() { HttpPipelineMessageListener listener = new HttpPipelineMessageListener(5000, TimeSpan.FromSeconds(1)); bool timeoutFired = false; listener.Timeout += () => { timeoutFired = true; }; listener.Start(); Thread.Sleep(2000); Assert.IsTrue(timeoutFired); Assert.IsFalse(listener.IsListening); }
public void TestHttpPipelineTransport() { HttpPipelineMessageListener listener = new HttpPipelineMessageListener(5000, TimeSpan.FromSeconds(10)); HttpPipelineMessageSender sender = new HttpPipelineMessageSender(5000); Customer testObj = new Customer() { Name = "Adam", AccountNumber = "123" }; Exception listenException = null; Customer received = null; bool stopFired = false; listener.MessageReceivedHandler = (message) => { if (message.ControlAction == null) { Customer deserialized = message.DeserializetPipedObject <Customer>(); Assert.AreEqual(testObj.Name, deserialized.Name); Assert.AreEqual(testObj.AccountNumber, deserialized.AccountNumber); received = deserialized; return(new HttpPipelineControlResponse() { StatusCode = System.Net.HttpStatusCode.Accepted }); } else if (message.ControlAction == "Close") { return(new HttpPipelineControlResponse() { StatusCode = HttpStatusCode.OK, Close = true }); } else { throw new NotSupportedException(); } }; listener.ListenException += (ex) => { listenException = listenException ?? ex; }; listener.Stopped += () => { stopFired = true; }; listener.Start(); var pipeResponse = sender.SendObject(testObj); Assert.AreEqual(HttpStatusCode.Accepted, pipeResponse.StatusCode); var closeResponse = sender.SendControlAction("Close"); Assert.AreEqual(HttpStatusCode.OK, closeResponse.StatusCode); Thread.Sleep(200);// give the listener a few milliseconds to stop Assert.IsFalse(listener.IsListening); Assert.IsTrue(stopFired); Assert.IsNull(listenException); Assert.IsNotNull(received); }