Exemplo n.º 1
0
        public async Task GetReplyReturnsFirstReply()
        {
            GivenSentMessage();
            GivenReply();
            WhenReplyReceived();

            var cancellationToken   = CancellationTokenSource.Token;
            var awaitedReplyContent = await SentMessage.GetReply(cancellationToken);

            Assert.NotNull(awaitedReplyContent);
            Assert.Equal(Reply.Content, awaitedReplyContent);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Observes the sent message replies until the first reply is received
        /// or a timeout occurs
        /// </summary>
        /// <param name="sentMessage">The sent message</param>
        /// <param name="timeout">The maximum amount of time to wait for a reply</param>
        /// <returns>Returns a task whose result will be the deserialized content of the
        /// reply message</returns>
        public static Task <object> GetReply(this ISentMessage sentMessage, TimeSpan timeout = default(TimeSpan))
        {
            var cts = timeout >= TimeSpan.Zero
                ? new CancellationTokenSource(timeout)
                : new CancellationTokenSource();

            var ct = cts.Token;

            // ReSharper disable once MethodSupportsCancellation
            return(sentMessage.GetReply(ct).ContinueWith(t =>
            {
                cts.Dispose();
                return t.Result;
            }));
        }
Exemplo n.º 3
0
        protected async Task AssertReplyReceived()
        {
            Assert.NotNull(SentMessage);

            var timeout = TimeSpan.FromSeconds(5);
            var reply   = await SentMessage.GetReply(timeout);

            Assert.NotNull(reply);
            Assert.IsType <TestReply>(reply);

            var testReply = (TestReply)reply;

            Assert.Equal(Message.GuidData, testReply.GuidData);
            Assert.Equal(Message.IntData, testReply.IntData);
            Assert.Equal(Message.StringData, testReply.StringData);
            Assert.Equal(Message.DateData, testReply.DateData);
        }