public void SendFor() { var tcs = new TaskCompletionSource<bool>(); tcs.SetResult (true); var mrm = new MessageResponseManager(); var msg = new BlankMessage { Header = new MessageHeader { MessageId = 1 } }; Task<Message> response = mrm.SendFor (msg, tcs.Task); var responseMsg = new BlankMessage { Header = new MessageHeader { MessageId = 2, ResponseMessageId = 1, IsResponse = true } }; mrm.Receive (responseMsg); if (!response.Wait (10000)) Assert.Fail ("Task never completed"); Assert.AreSame (responseMsg, response.Result); }
public void SendForCancel() { var tcs = new TaskCompletionSource<bool>(); tcs.SetResult (true); var mrm = new MessageResponseManager(); var msg = new BlankMessage { Header = new MessageHeader { MessageId = 1 } }; var source = new CancellationTokenSource(); Task<Message> response = mrm.SendFor (msg, tcs.Task, source.Token); source.Cancel(); try { if (!response.Wait (10000)) Assert.Fail ("Task never completed"); Assert.Fail ("Did not throw cancel exception"); } catch (AggregateException aex) { Assert.IsTrue (response.IsCanceled); Assert.That (aex.Flatten().InnerException, Is.InstanceOf<OperationCanceledException>()); } }
public void SendForSendFailed() { var tcs = new TaskCompletionSource <bool>(); tcs.SetResult(false); var mrm = new MessageResponseManager(); var msg = new BlankMessage { Header = new MessageHeader { MessageId = 1 } }; Task <Message> response = mrm.SendFor(msg, tcs.Task); try { if (!response.Wait(10000)) { Assert.Fail("Task never completed"); } Assert.Fail("Did not throw cancel exception"); } catch (AggregateException aex) { Assert.IsTrue(response.IsCanceled); Assert.That(aex.Flatten().InnerException, Is.InstanceOf <OperationCanceledException>()); } }
public void SendFor() { var tcs = new TaskCompletionSource <bool>(); tcs.SetResult(true); var mrm = new MessageResponseManager(); var msg = new BlankMessage { Header = new MessageHeader { MessageId = 1 } }; Task <Message> response = mrm.SendFor(msg, tcs.Task); var responseMsg = new BlankMessage { Header = new MessageHeader { MessageId = 2, ResponseMessageId = 1, IsResponse = true } }; mrm.Receive(responseMsg); if (!response.Wait(10000)) { Assert.Fail("Task never completed"); } Assert.AreSame(responseMsg, response.Result); }
public void SendForCancelSuccess() { var tcs = new TaskCompletionSource <bool>(); tcs.SetResult(true); var mrm = new MessageResponseManager(); var msg = new BlankMessage { Header = new MessageHeader { MessageId = 1 } }; var source = new CancellationTokenSource(); Task <Message> response = mrm.SendFor(msg, tcs.Task, source.Token); var responseMsg = new BlankMessage { Header = new MessageHeader { MessageId = 2, ResponseMessageId = 1, IsResponse = true } }; mrm.Receive(responseMsg); source.Cancel(); if (!response.Wait(10000)) { Assert.Fail("Task never completed"); } }
public void SendForTimeoutSuccess() { var tcs = new TaskCompletionSource <bool>(); tcs.SetResult(true); var mrm = new MessageResponseManager(); var msg = new BlankMessage { Header = new MessageHeader { MessageId = 1 } }; Task <Message> response = mrm.SendFor(msg, tcs.Task, 1000); var responseMsg = new BlankMessage { Header = new MessageHeader { MessageId = 2, ResponseMessageId = 1, IsResponse = true } }; mrm.Receive(responseMsg); Thread.Sleep(2000); mrm.CheckTimeouts(); if (!response.Wait(10000)) { Assert.Fail("Task never completed"); } }
private MessageEventArgs GetTestMessageArgs(int mid) { var msg = new BlankMessage(); msg.Header = new MessageHeader(); msg.Header.MessageId = mid; return(new MessageEventArgs(this.connection, msg)); }
public void BlankMessage() { var cmessage = new BlankMessage(); var c = GetNewClientConnection(); var test = new AsyncTest(e => { var me = (e as MessageEventArgs); Assert.IsNotNull(me); var msg = (me.Message as BlankMessage); Assert.IsNotNull(msg); }); IConnection sc; ManualResetEvent wait = new ManualResetEvent(false); this.provider.ConnectionMade += (s, e) => { sc = e.Connection; sc.MessageReceived += test.PassHandler; sc.Disconnected += test.FailHandler; wait.Set(); }; this.provider.Start(MessageTypes); c.Disconnected += test.FailHandler; c.Connected += (sender, e) => c.SendAsync(cmessage); c.ConnectAsync(Target, MessageTypes); if (!wait.WaitOne(10000)) { Assert.Fail("Failed to connect"); } test.Assert(10000); }
public void SendForTimeout() { var tcs = new TaskCompletionSource <bool>(); tcs.SetResult(true); var mrm = new MessageResponseManager(); var msg = new BlankMessage { Header = new MessageHeader { MessageId = 1 } }; Task <Message> response = mrm.SendFor(msg, tcs.Task, 1000); DateTime start = DateTime.Now; while ((DateTime.Now - start) < TimeSpan.FromSeconds(2)) { mrm.CheckTimeouts(); Thread.Sleep(1); } try { if (!response.Wait(10000)) { Assert.Fail("Task never completed"); } Assert.Fail("Did not throw cancel exception"); } catch (AggregateException aex) { Assert.IsTrue(response.IsCanceled); Assert.That(aex.Flatten().InnerException, Is.InstanceOf <OperationCanceledException>()); } }
public void SendForTimeoutSuccess() { var tcs = new TaskCompletionSource<bool>(); tcs.SetResult (true); var mrm = new MessageResponseManager(); var msg = new BlankMessage { Header = new MessageHeader { MessageId = 1 } }; Task<Message> response = mrm.SendFor (msg, tcs.Task, 1000); var responseMsg = new BlankMessage { Header = new MessageHeader { MessageId = 2, ResponseMessageId = 1, IsResponse = true } }; mrm.Receive (responseMsg); Thread.Sleep (2000); mrm.CheckTimeouts(); if (!response.Wait (10000)) Assert.Fail ("Task never completed"); }
public void SendForCancelSuccess() { var tcs = new TaskCompletionSource<bool>(); tcs.SetResult (true); var mrm = new MessageResponseManager(); var msg = new BlankMessage { Header = new MessageHeader { MessageId = 1 } }; var source = new CancellationTokenSource(); Task<Message> response = mrm.SendFor (msg, tcs.Task, source.Token); var responseMsg = new BlankMessage { Header = new MessageHeader { MessageId = 2, ResponseMessageId = 1, IsResponse = true } }; mrm.Receive (responseMsg); source.Cancel(); if (!response.Wait (10000)) Assert.Fail ("Task never completed"); }
private MessageEventArgs GetTestMessageArgs(int mid) { var msg = new BlankMessage(); msg.Header = new MessageHeader(); msg.Header.MessageId = mid; return new MessageEventArgs (this.connection, msg); }