public void GenericMessageTest4() { var message = MessageTestUtils.CreateTextMessage("{ \"foo\" : \"bar\" }"); var mockChannel = new Mock <IModel>(); mockChannel.Setup(c => c.CreateBasicProperties()).Returns(new MockRabbitBasicProperties()); var listener = GetSimpleInstance("WithGenericMessageDictionaryType", typeof(IMessage <Dictionary <string, string> >)); listener.MessageConverter = new Rabbit.Support.Converter.JsonMessageConverter(); var accessor = RabbitHeaderAccessor.GetMutableAccessor(message); accessor.ContentType = MimeTypeUtils.APPLICATION_JSON_VALUE; listener.OnMessage(message, mockChannel.Object); Assert.IsType <Dictionary <string, string> >(sample.Payload); }
public void ExceptionInMultiListenerReturnException() { var message = MessageTestUtils.CreateTextMessage("foo"); var mockChannel = new Mock <IModel>(); mockChannel.Setup(c => c.CreateBasicProperties()).Returns(new MockRabbitBasicProperties()); var listener = GetMultiInstance("Fail", "FailWithReturn", true, typeof(string), typeof(byte[])); try { listener.OnMessage(message, mockChannel.Object); throw new Exception("Should have thrown an exception"); } catch (ListenerExecutionFailedException ex) { Assert.IsType <ArgumentException>(ex.InnerException); Assert.Contains("Expected test exception", ex.InnerException.Message); } catch (Exception ex) { throw new Exception("Should not have thrown an " + ex); } message = Message.Create(new byte[] { 1, 2 }, new MessageHeaders()); try { listener.OnMessage(message, mockChannel.Object); throw new Exception("Should have thrown an exception"); } catch (ReplyFailureException ex) { Assert.Contains("Failed to send reply", ex.Message); } catch (Exception ex) { throw new Exception("Should not have thrown an " + ex); } // TODO: The Java simpleconverter will convert the exception using java serialization... var accessor = RabbitHeaderAccessor.GetMutableAccessor(message); accessor.ReplyTo = "foo/bar"; listener.OnMessage(message, mockChannel.Object); // TODO: verify(channel).basicPublish(eq("foo"), eq("bar"), eq(false), any(BasicProperties.class), any(byte[].class)); }
public void BatchTypedObjectTest() { var message = MessageTestUtils.CreateTextMessage("{ \"foostring\" : \"bar1\" }"); var mockChannel = new Mock <IModel>(); mockChannel.Setup(c => c.CreateBasicProperties()).Returns(new MockRabbitBasicProperties()); var listener = GetBatchInstance("WithFooBatch", typeof(List <Foo>)); listener.MessageConverter = new Rabbit.Support.Converter.JsonMessageConverter(); var accessor = RabbitHeaderAccessor.GetMutableAccessor(message); accessor.ContentType = MimeTypeUtils.APPLICATION_JSON_VALUE; listener.OnMessageBatch(new List <IMessage>() { message }, mockChannel.Object); Assert.IsType <Foo>(sample.BatchPayloads[0]); }
public void ExceptionInInvocation() { var message = MessageTestUtils.CreateTextMessage("foo"); var mockChannel = new Mock <IModel>(); mockChannel.Setup(c => c.CreateBasicProperties()).Returns(new MockRabbitBasicProperties()); var listener = GetSimpleInstance("WrongParam", typeof(int)); try { listener.OnMessage(message, mockChannel.Object); throw new Exception("Should have thrown an exception"); } catch (ListenerExecutionFailedException ex) { Assert.IsType <MessageConversionException>(ex.InnerException); } catch (Exception ex) { throw new Exception("Should not have thrown an " + ex); } }
public void ExceptionInListenerBadReturnExceptionSetting() { var message = MessageTestUtils.CreateTextMessage("foo"); var mockChannel = new Mock <IModel>(); mockChannel.Setup(c => c.CreateBasicProperties()).Returns(new MockRabbitBasicProperties()); var listener = GetSimpleInstance("Fail", true, typeof(string)); try { listener.OnMessage(message, mockChannel.Object); throw new Exception("Should have thrown an exception"); } catch (ListenerExecutionFailedException ex) { Assert.IsType <ArgumentException>(ex.InnerException); Assert.Contains("Expected test exception", ex.InnerException.Message); } catch (Exception ex) { throw new Exception("Should not have thrown an " + ex); } }