public void TestRequest()
        {
            // arrange
            var mq = new MessageQueueMock();

            mq.Setup();

            using (var scope = Factory.Current.BeginLifetimeScope(b =>
            {
                b.RegisterInstance(mq.Object).As <IMessageQueue>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    var sender = new MessageQueueSender();

                    var handler = new Mock <IRemoteResponseHandler <string, string> >();

                    // act
                    sender.Request("foo", "test", handler.Object);

                    // assert
                    var messageQueueRequest = Entity.GetByField <MessageQueueRequest>("reply_foo", MessageQueueRequest.MessageQueueRequestKey_Field)
                                              .OrderByDescending(e => e.CreatedDate)
                                              .FirstOrDefault();

                    messageQueueRequest.Should().NotBeNull();

                    mq.Respond("foo").Should().Be("\"test\"");
                }
        }
        public void TestRespond()
        {
            // arrange
            var mq = new MessageQueueMock();

            mq.Setup();

            using (var scope = Factory.Current.BeginLifetimeScope(b =>
            {
                b.RegisterInstance(mq.Object).As <IMessageQueue>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    var listener = new MessageQueueListener();

                    string consumed = null;

                    mq.Request("foo", "\"test\"");
                    mq.Consume += (s, e) =>
                    {
                        consumed = e.Message;
                    };

                    // act
                    listener.Respond <string, string>("foo", null);
                    listener.Stop();

                    // assert
                    consumed.Should().Be("\"test\"");
                }
        }
        public void TestPublish()
        {
            // arrange
            var mq = new MessageQueueMock();

            mq.Setup();

            using (var scope = Factory.Current.BeginLifetimeScope(b =>
            {
                b.RegisterInstance(mq.Object).As <IMessageQueue>();
            }))
                using (Factory.SetCurrentScope(scope))
                {
                    var sender = new MessageQueueSender();

                    // act
                    sender.Publish("foo", "test");

                    // assert
                    mq.Subscribe("foo").Should().Be("\"test\"");
                }
        }