public void PeekAsyncMessageFromQueueShouldWork()
        {
            var name = $"IntegrationTest_{UniqueKeyUtility.Generate()}";

            try
            {
                var queue = _messageQueueManager.Create(name, true, true);

                var asyncResult = _messageQueueManager.BeginPeek(queue, TimeSpan.FromMilliseconds(100));

                var message = _messageQueueManager.EndPeek(queue, asyncResult);

                message.Should().BeNull("Because queue is empty");

                var id = SendMessage(queue, "Message");

                asyncResult = _messageQueueManager.BeginPeek(queue, TimeSpan.FromMilliseconds(100));
                message     = _messageQueueManager.EndPeek(queue, asyncResult);

                message.Should().NotBeNull();
                message.Id.Should().Be(id);
            }
            finally
            {
                _messageQueueManager.Delete(name, true);
            }
        }
        private void AddMessageToQueue(System.Messaging.MessageQueue messageQueue, object dto)
        {
            var body = new QueueMessage {
                MessageBody = dto.SerializeToJson(new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                }), MessageType = dto.GetType()
            };

            var message = new Message
            {
                Body        = body,
                AppSpecific = 1,
                BodyStream  = new MemoryStream(Encoding.UTF8.GetBytes(body.SerializeToJson(new JsonSerializerSettings {
                    TypeNameHandling = TypeNameHandling.All
                })))
            };

            _messageQueueManager.Receive(messageQueue, Arg.Any <TimeSpan>(), Arg.Any <System.Messaging.MessageQueueTransaction>()).Returns(message);
            _messageQueueManager.EndPeek(messageQueue, Arg.Any <IAsyncResult>()).Returns(message);
            _messageQueueManager.BeginPeek(messageQueue, Arg.Any <TimeSpan>()).Returns((IAsyncResult)null);
        }
예제 #3
0
 private void AddMessageToQueue(object dto)
 {
     _messageQueueManager.Receive(Arg.Any <System.Messaging.MessageQueue>(), Arg.Any <TimeSpan>(), Arg.Any <System.Messaging.MessageQueueTransaction>()).Returns(GetMessage(dto));
     _messageQueueManager.BeginPeek(Arg.Any <System.Messaging.MessageQueue>(), Arg.Any <TimeSpan>()).Returns((IAsyncResult)null);
     _messageQueueManager.EndPeek(Arg.Any <System.Messaging.MessageQueue>(), Arg.Any <IAsyncResult>()).Returns(GetMessage(dto));
 }