Example #1
0
        public void ShouldProcessMessagesAccordingToFilter()
        {
            const string typeName = "SomeTypeName";

            var consumer = A.Fake <IMessageConsumer>();

            A.CallTo(() => _session.CreateConsumer(_destination, null, false)).Returns(consumer);

            IBytesMessage            bytesMessage = A.Fake <IBytesMessage>();
            ITestMessage             message      = A.Fake <ITestMessage>();
            Func <IDictionary, bool> filter       = properties => (int?)properties["Id"] == 123;

            const string serializedFixtureString = "<xml>Some fixture XML</xml>";
            var          bytes = Encoding.UTF8.GetBytes(serializedFixtureString);

            var messageProperties = new PrimitiveMap();

            messageProperties.SetString(MessagePropertyNames.TypeName, typeName);
            messageProperties.SetInt("Id", 123);

            A.CallTo(() => bytesMessage.Content).Returns(bytes);
            A.CallTo(() => bytesMessage.Properties).Returns(messageProperties);
            A.CallTo(() => _deserializer.Deserialize(A <Stream> ._)).Returns(message);
            A.CallTo(() => _deserializer.GetTypeName()).Returns(typeName);

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

            _source.Messages.Subscribe(_observer);
            consumer.Listener += Raise.FreeForm.With((Apache.NMS.IMessage)bytesMessage);

            A.CallTo(() => _deserializer.Deserialize(A <Stream> ._)).MustHaveHappened();
            A.CallTo(() => _observer.OnNext(message)).MustHaveHappened();
        }
Example #2
0
        public void TestMarshalPrimitiveMap()
        {
            XmlPrimitiveMapMarshaler marshaler = new XmlPrimitiveMapMarshaler();

            PrimitiveMap map = new PrimitiveMap();

            map.SetBool("boolean", true);
            map.SetByte("byte", (byte)1);
            map["bytes1"] = new byte[1];
            map.SetChar("char", 'a');
            map.SetDouble("double", 1.5);
            map.SetFloat("float", 1.5f);
            map.SetInt("int", 1);
            map.SetLong("long", 1);
            map["object"] = "stringObj";
            map.SetShort("short", (short)1);
            map.SetString("string", "string");

            byte[] result = marshaler.Marshal(map);
            Assert.IsNotNull(result);

            result = marshaler.Marshal(null);
            Assert.IsNull(result);
        }