public void PersonFullNamerIsProperlyReceived(string destQueue, string firstName, string lastName)
        {
            // arrange
            using var context = new RabbitMqContextBuilder()
                                .WithConnectionString("amqp://*****:*****@localhost")
                                .WithExchange("HelloExchange")
                                .CreateContext();

            using var receiver = context.CreateCommandReceiver(destQueue);
            receiver.DeclareCommandQueue();

            var sender = context.CreateCommandSender();

            var nameObject = new Person
            {
                FirstName = firstName,
                LastName  = lastName
            };

            var command = new CommandMessage
            {
                DestinationQueue = destQueue,
                Timestamp        = 294859,
                CorrelationId    = Guid.NewGuid(),
                ReplyQueue       = "ReplyQueue",
                Body             = Encoding.Unicode.GetBytes(JsonConvert.SerializeObject(nameObject))
            };

            // Act
            receiver.StartReceivingCommands(commandMessage =>
            {
                Person person       = JsonConvert.DeserializeObject <Person>(Encoding.Unicode.GetString(commandMessage.Body));
                person.FullName     = $"{person.FirstName} {person.LastName}";
                string jsonResponse = JsonConvert.SerializeObject(person);

                return(new CommandMessage
                {
                    CorrelationId = commandMessage.CorrelationId,
                    Timestamp = commandMessage.Timestamp,
                    Body = Encoding.Unicode.GetBytes(jsonResponse)
                });
            });

            var result = sender.SendCommandAsync(command);

            // Assert
            var stringResult = Encoding.Unicode.GetString(result.Result.Body);
            var personResult = JsonConvert.DeserializeObject <Person>(stringResult);

            Assert.AreEqual($"{firstName} {lastName}", personResult.FullName);
        }
        public void CommandIsProperlySentThrough(string destQueue, string message)
        {
            // arrange
            using var context = new RabbitMqContextBuilder()
                                .WithConnectionString("amqp://*****:*****@localhost")
                                .WithExchange("HelloExchange")
                                .CreateContext();

            using var receiver = context.CreateCommandReceiver(destQueue);
            receiver.DeclareCommandQueue();

            var sender = context.CreateCommandSender();

            var nameObject = new NameMessage(message);
            var command    = new CommandMessage
            {
                DestinationQueue = destQueue,
                Timestamp        = 294859,
                CorrelationId    = Guid.NewGuid(),
                ReplyQueue       = "ReplyQueue",
                Body             = Encoding.Unicode.GetBytes(JsonConvert.SerializeObject(nameObject))
            };

            // Act
            receiver.StartReceivingCommands(commandMessage =>
            {
                NameMessage name = JsonConvert.DeserializeObject <NameMessage>(Encoding.Unicode.GetString(commandMessage.Body));

                return(new CommandMessage
                {
                    CorrelationId = commandMessage.CorrelationId,
                    Timestamp = commandMessage.Timestamp,
                    Body = Encoding.Unicode.GetBytes($"Hallo {name.Name}")
                });
            });

            var result = sender.SendCommandAsync(command);

            // Assert
            var stringResult = Encoding.Unicode.GetString(result.Result.Body);

            Assert.AreEqual($"Hallo {message}", stringResult);
        }
        public void ResumeResumesReceivingMessagesAfterItWasPaused(long timestamp)
        {
            // Arrange
            using IBusContext <IConnection> context = new RabbitMqContextBuilder()
                                                      .WithConnectionString("amqp://*****:*****@localhost")
                                                      .WithExchange("HelloExchange")
                                                      .CreateContext();

            bool messageReceived = false;

            using var receiver = context.CreateCommandReceiver("topic.queue.test");
            receiver.DeclareCommandQueue();
            receiver.StartReceivingCommands(e =>
            {
                messageReceived = true;
                return(null);
            });

            var eventMessage = new CommandMessage
            {
                Body             = Encoding.Unicode.GetBytes("TestMessage"),
                Timestamp        = timestamp,
                CorrelationId    = Guid.NewGuid(),
                DestinationQueue = "topic.queue.test",
                EventType        = "TestEvent"
            };

            receiver.Pause();

            // Act
            var sender = context.CreateCommandSender();

            sender.SendCommandAsync(eventMessage);

            receiver.Resume();

            // Assert
            Thread.Sleep(WaitTime);

            Assert.AreEqual(true, messageReceived);
        }