public void Does_serialize_to_correct_MQ_name()
        {
            var message = new Message<Greet>(new Greet {Name = "Test"}) {};

            var mqClient = new RedisMessageQueueClient(new BasicRedisClientManager());

            mqClient.Publish(message);
        }
Exemplo n.º 2
0
        public void Can_serialize_IMessage()
        {
            var message = new Message<string> { Id = new Guid(), CreatedDate = new DateTime(), Body = "test" };
            var messageString = TypeSerializer.SerializeToString((IMessage<string>)message);

            Assert.That(messageString, Is.EqualTo(
            "{__type:\"ServiceStack.Messaging.Message`1[[System.String, mscorlib]], ServiceStack.Interfaces\","
             + "Id:00000000000000000000000000000000,CreatedDate:0001-01-01,Priority:0,RetryAttempts:0,Body:test}"));
        }
 public string GetMessageEnvelope(Message msg)
 {
     var sb = new StringBuilder();
     using (var sw = XmlWriter.Create(new StringWriter(sb)))
     {
         msg.WriteMessage(sw);
         sw.Flush();
         return sb.ToString();
     }
 }
Exemplo n.º 4
0
        public void Can_serialize_Message()
        {
            var message = new Message<string> { Id = new Guid(), CreatedDate = new DateTime(), Body = "test" };
            var messageString = TypeSerializer.SerializeToString(message);

            Assert.That(messageString, Is.EqualTo(
            "{Id:00000000000000000000000000000000,CreatedDate:0001-01-01,Priority:0,RetryAttempts:0,Body:test}"));

            Serialize(message);
        }
Exemplo n.º 5
0
        public void PluginHelp(Message message, IMessageClient client, string plugin)
        {
            string ouputMessage = string.Format("Commands for {0}:", plugin);
            IEnumerable<List<Command>> helpInformationCommands = _helpInformation.Where(hi => hi.Plugin.ToLower() == plugin.ToLower()).Select(hi => hi.Commands);

            foreach (var commands in _helpInformation.Where(hi => hi.Plugin.ToLower() == plugin.ToLower()).Select(hi => hi.Commands))
            {
                foreach (Command command in commands)
                {
                    ouputMessage += "\n" + string.Format("Command Syntax: {0}\nDescription: {1}\nExample: {2}\n", command.Syntax, command.Description, command.Example);
                }
            }

            client.ReplyTo(message, helpInformationCommands.Any()
                                      ? ouputMessage
                                      : string.Format("Plugin '{0}' not found.", plugin));
        }
Exemplo n.º 6
0
        public void can_call_an_unauthenticated_method()
        {
            var uniqueCallbackQ = "mq:c1" + ":" + Guid.NewGuid().ToString("N");
            var clientMsg = new Message<GetFactorial>(new GetFactorial {ForNumber = 2})
            {
                ReplyTo = uniqueCallbackQ
            };

            var redisFactory = new PooledRedisClientManager("localhost:6379");
            var mqHost = new RedisMqServer(redisFactory, retryCount: 2);

            var mqClient = mqHost.CreateMessageQueueClient();

            mqClient.Publish(clientMsg);
            var response = mqClient.Get<GetFactorialResponse>(clientMsg.ReplyTo, new TimeSpan(0, 0, 10)); //Blocks thread on client until reply message is received
            Assert.IsNotNull(response);
            Assert.AreEqual(2, response.GetBody().Result);
        }
        public void WrapExceptionHandlerDoesNotExecuteCustomExHandlerIfMessageWasNotProcessed()
        {
            // Arrange    
            var msg = new Message<int>(1);
            var ex = new MessageNotProcessedException();
            var exFuncInvoked = false;
            this.MessageProcessor
                .Setup(x => x.OnMessageProcessingFailed(msg, ex, false))
                .Verifiable();

            var exHandler = this.MessageHandlerRegister.WrapExceptionHandler<int>((message, exception) => exFuncInvoked = true);

            // Test the the MessageProcessor is invoked!  
            exHandler.Invoke(msg, ex);

            // Assert
            Assert.IsFalse(exFuncInvoked);
            this.MessageProcessor.Verify(x => x.OnMessageProcessingFailed(msg, ex, false), Times.Once());
        }
Exemplo n.º 8
0
        public void can_call_an_authenticated_method()
        {
            var uniqueCallbackQ = "mq:c1" + ":" + Guid.NewGuid().ToString("N");
            var clientMsg = new Message<Secure>(new Secure())
            {
                ReplyTo = uniqueCallbackQ,
                Tag = "basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(SystemConstants.AllowedUser + ":" + SystemConstants.AllowedPass))
            };

            var redisFactory = new PooledRedisClientManager("localhost:6379");
            var mqHost = new RedisMqServer(redisFactory, retryCount: 2);

            var mqClient = mqHost.CreateMessageQueueClient();

            mqClient.Publish(clientMsg);
            var response = mqClient.Get<SecureResponse>(clientMsg.ReplyTo, new TimeSpan(0, 0, 10)); //Blocks thread on client until reply message is received
            Assert.IsNotNull(response);
            Assert.AreEqual("Confidential", response.GetBody().Result);
        }
Exemplo n.º 9
0
 public void MainHelpMenu(Message message, IMessageClient client)
 {
     string response = _helpInformation.Aggregate("List of Plugins. Please use help <plugin> for more information.", (current, helpInformation) => current + ("\n\t-" + helpInformation.Plugin));
     client.ReplyTo(message, response);
 }
        public void post_transaction_ok_with_authentication()
        {
            var uniqueCallbackQ = "mq:c1" + ":" + Guid.NewGuid().ToString("N");

            var transaction = new Transaction
            {
                Amount = 10.00m,
                Card = "XXXXXXXXXX124",
                CreateDate = DateTime.UtcNow,
                SubscriptionId = 101,
                GatewayTransactionId = "123456",
                TransactionTypeId = (long)TRANSACTION_TYPE.AuthorizeAndCapture,
                TransactionStatusId = (long)TRANSACTION_STATUS.Pending,
                GatewayResponse = "ok"
            };

            var clientMsg = new Message<Transaction>(transaction)
            {
                ReplyTo = uniqueCallbackQ,
                Tag = "basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(DefaultAdmin.Username + ":" + DefaultAdmin.Password))
            };

            var redisFactory = new PooledRedisClientManager("localhost:6379");
            var mqHost = new RedisMqServer(redisFactory, retryCount: 2);

            var mqClient = mqHost.CreateMessageQueueClient();

            mqClient.Publish(clientMsg);
            var response = mqClient.Get<PostResponse<Transaction>>(clientMsg.ReplyTo, new TimeSpan(0,10,10)); //Blocks thread on client until reply message is received
            var result = response.GetBody().Result;
            Assert.IsNotNull(result);
            Assert.IsTrue(result.Id > 0);
        }
        public void WrapExceptionHandlerIndicatesMoveToDlqWhenRetryCountIsExceeded()
        {
            // Arrange    
            var msg = new Message<int>(1);
            msg.RetryAttempts = 1000; // Ensure it exceeds the retry limit.
            var ex = new MessageNotProcessedException();
            var exFuncInvoked = false;
            this.MessageProcessor
                .Setup(x => x.OnMessageProcessingFailed(msg, ex, true))
                .Verifiable();

            var exHandler = this.MessageHandlerRegister.WrapExceptionHandler<int>((message, exception) => exFuncInvoked = true);

            // Test that when the retry count is exceeded, the parameter 'moveMessageToDlq' is true. 
            exHandler.Invoke(msg, ex);

            // Assert
            Assert.IsFalse(exFuncInvoked);
            this.MessageProcessor.Verify(x => x.OnMessageProcessingFailed(msg, ex, true), Times.Once());
        }
        public void WrapMessageInvokesCustomProcessAndHandlesAnyUncaughtExceptions()
        {
            // Arrange    
            var msg = new Message<int>(1);
            var expectedResult = 10;

            this.MessageProcessor
                .Setup(x => x.CanProcessMessage(msg))
                .Throws(new InvalidOperationException())
                .Verifiable();

            var wrapper = this.MessageHandlerRegister.WrapMessageProcessor<int>(message => expectedResult);

            // Act
            object result = null;
            bool exceptionThrown = false;
            try
            {
                result = wrapper.Invoke(msg);
            }
            catch (Exception ex)
            {
                // Determine result, for testing.
                exceptionThrown = true;
            }

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOf<MessageNotProcessedException>(result);
            Assert.IsFalse(exceptionThrown);

            this.MessageProcessor.VerifyAll();
            this.MessageProcessor.Verify(x => x.CanProcessMessage(msg), Times.Once());
            this.MessageProcessor.Verify(x => x.OnMessageProcessed(msg), Times.Never());
        }
        public void WrapMessageInvokesCustomProcessHandlerFollowedByOnMessageProcessed()
        {
            // Arrange    
            var msg = new Message<int>(1);
            var expectedResult = 10;

            this.MessageProcessor
                .Setup(x => x.CanProcessMessage(msg))
                .Returns(true)
                .Verifiable();

            var wrapper = this.MessageHandlerRegister.WrapMessageProcessor<int>(message => expectedResult);

            this.MessageProcessor
                .Setup(x => x.OnMessageProcessed(msg))
                .Verifiable();

            // Act
            var result = wrapper.Invoke(msg);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(expectedResult, result);
            this.MessageProcessor.VerifyAll();
            this.MessageProcessor.Verify(x => x.CanProcessMessage(msg), Times.Once());
            this.MessageProcessor.Verify(x => x.OnMessageProcessed(msg), Times.Once());
        }
        public void WrapMessageProcessorReturnsExceptionWhenMessageProcessorCanNotProcessMessage()
        {
           // Arrange    
            var msg = new Message<int>(1);
            var expectedResult = 10;

            this.MessageProcessor
                .Setup(x => x.CanProcessMessage(msg))
                .Returns(false)
                .Verifiable();

            var wrapper = this.MessageHandlerRegister.WrapMessageProcessor<int>(message => expectedResult);

            // Act
            var result = wrapper.Invoke(msg);

            // Assert
            Assert.IsNotNull(result);
            Assert.IsInstanceOf<MessageNotProcessedException>(result);
            this.MessageProcessor.VerifyAll();
        }