Beispiel #1
0
        public void ShouldAcknowledgeMessagesIfValid()
        {
            _source = new MessageSource <ITestMessage>(_lazyConnection, new[] { _deserializer }, _destination,
                                                       AcknowledgementMode.ClientAcknowledge);

            Mock <IMessageConsumer> mockConsumer = MockConsumerExtensions.Create(_session, _destination);
            ITextMessage            textMessage  = A.Fake <ITextMessage>();

            _source.Messages.Subscribe(_observer);
            mockConsumer.RaiseFakeMessage(textMessage);

            A.CallTo(() => textMessage.Acknowledge()).MustHaveHappened(Repeated.Exactly.Once);
        }
Beispiel #2
0
        public void ShouldNotAcknowledgeMessagesIfInvalid()
        {
            _source = new MessageSource <ITestMessage>(_lazyConnection, new[] { _deserializer }, _destination,
                                                       AcknowledgementMode.ClientAcknowledge);

            Mock <IMessageConsumer> mockConsumer = MockConsumerExtensions.Create(_session, _destination);
            ITextMessage            textMessage  = A.Fake <ITextMessage>();

            A.CallTo(() => _deserializer.Deserialize(A <string> .Ignored)).Throws <Exception>();

            _source.Messages.Subscribe(_observer);
            mockConsumer.RaiseFakeMessage(textMessage);

            A.CallTo(() => textMessage.Acknowledge()).MustNotHaveHappened();
        }
Beispiel #3
0
        public void ShouldDeserializeByteMessagesAndPublishMessageWhenReceived()
        {
            Mock <IMessageConsumer> mockConsumer = MockConsumerExtensions.Create(_session, _destination);
            IBytesMessage           bytesMessage = A.Fake <IBytesMessage>();
            ITestMessage            message      = A.Fake <ITestMessage>();

            byte[] bytes = new byte[0];
            A.CallTo(() => bytesMessage.Content).Returns(bytes);
            A.CallTo(() => _deserializer.Deserialize(bytes)).Returns(message);

            _source.Messages.Subscribe(_observer);
            mockConsumer.RaiseFakeMessage(bytesMessage);

            A.CallTo(() => _observer.OnNext(message)).MustHaveHappened();
        }
Beispiel #4
0
        public void ShouldDeserializeAndPublishMessageWhenReceived()
        {
            Mock <IMessageConsumer> mockConsumer            = MockConsumerExtensions.Create(_session, _destination);
            ITextMessage            textMessage             = A.Fake <ITextMessage>();
            ITestMessage            message                 = A.Fake <ITestMessage>();
            const string            serializedFixtureString = "<xml>Some fixture XML</xml>";

            A.CallTo(() => textMessage.Text).Returns(serializedFixtureString);
            A.CallTo(() => _deserializer.Deserialize(serializedFixtureString)).Returns(message);

            _source.Messages.Subscribe(_observer);
            mockConsumer.RaiseFakeMessage(textMessage);

            A.CallTo(() => _observer.OnNext(message)).MustHaveHappened();
        }
Beispiel #5
0
        public void ShouldDeserializeAndPublishMessageOfRightTypeName()
        {
            Mock <IMessageConsumer> mockConsumer            = MockConsumerExtensions.Create(_session, _destination);
            ITextMessage            textMessage             = A.Fake <ITextMessage>();
            ITestMessage            message                 = A.Fake <ITestMessage>();
            const string            serializedFixtureString = "<xml>Some fixture XML</xml>";

            A.CallTo(() => textMessage.Text).Returns(serializedFixtureString);
            A.CallTo(() => textMessage.Properties.Contains(MessagePropertyNames.TypeName)).Returns(true);
            A.CallTo(() => textMessage.Properties.GetString(MessagePropertyNames.TypeName)).Returns("SomeTypeName");
            A.CallTo(() => _deserializer.Deserialize(serializedFixtureString)).Returns(message);
            A.CallTo(() => _deserializer.GetTypeName()).Returns("SomeTypeName");

            _source = new MessageSource <ITestMessage>(_lazyConnection, new[] { _deserializer }, _destination,
                                                       _acknowledgementMode);

            _source.Messages.Subscribe(_observer);
            mockConsumer.RaiseFakeMessage(textMessage);

            A.CallTo(() => _observer.OnNext(message)).MustHaveHappened();
        }