Exemplo n.º 1
0
        public void SetUp()
        {
            dataBus = MockRepository.GenerateMock <IDataBus>();

            receiveBehavior = new DataBusReceiveBehavior
            {
                DataBus           = dataBus,
                DataBusSerializer = new DefaultDataBusSerializer()
            };

            sendBehavior = new DataBusSendBehavior
            {
                DataBus           = dataBus,
                DataBusSerializer = new DefaultDataBusSerializer()
            };
        }
Exemplo n.º 2
0
        public void SetUp()
        {
            dataBus = MockRepository.GenerateMock<IDataBus>();

            receiveBehavior = new DataBusReceiveBehavior
            {
                DataBus = dataBus,
                DataBusSerializer = new DefaultDataBusSerializer()
            };

            sendBehavior = new DataBusSendBehavior
            {
                DataBus = dataBus,
                DataBusSerializer = new DefaultDataBusSerializer()
            };
        }
Exemplo n.º 3
0
        public async Task Incoming_databus_properties_should_be_hydrated()
        {
            var propertyKey = Guid.NewGuid().ToString();
            var databusKey  = Guid.NewGuid().ToString();

            var message = new LogicalMessage(new MessageMetadata(typeof(MessageWithDataBusProperty)), new MessageWithDataBusProperty
            {
                DataBusProperty = new DataBusProperty <string>("not used in this test")
                {
                    Key = propertyKey
                }
            });

            var fakeDatabus     = new FakeDataBus();
            var receiveBehavior = new DataBusReceiveBehavior(fakeDatabus, new XmlDataBusSerializer <string>(), new Conventions());

            using (var stream = new MemoryStream())
            {
                var serializer = new System.Xml.Serialization.XmlSerializer(typeof(string));
                serializer.Serialize(stream, "test");
                stream.Position = 0;

                fakeDatabus.StreamsToReturn[databusKey] = stream;

                await receiveBehavior.Invoke(
                    new IncomingLogicalMessageContext(
                        message,
                        "messageId",
                        "replyToAddress",
                        new Dictionary <string, string>
                {
                    { "NServiceBus.DataBus." + propertyKey, databusKey }
                },
                        null),
                    ctx => Task.CompletedTask);
            }

            var instance = (MessageWithDataBusProperty)message.Instance;

            Assert.AreEqual(instance.DataBusProperty.Value, "test");
        }
        public async Task Incoming_databus_properties_should_be_hydrated()
        {
            var propertyKey = Guid.NewGuid().ToString();
            var databusKey = Guid.NewGuid().ToString();

            var message = new LogicalMessage(new MessageMetadata(typeof(MessageWithDataBusProperty)), new MessageWithDataBusProperty
                              {
                                  DataBusProperty = new DataBusProperty<string>("not used in this test")
                                  {
                                      Key = propertyKey
                                  }
                              });

            var fakeDatabus = new FakeDataBus();
            var receiveBehavior = new DataBusReceiveBehavior(fakeDatabus, new DefaultDataBusSerializer(), new Conventions());

            using (var stream = new MemoryStream())
            {
                new BinaryFormatter().Serialize(stream, "test");
                stream.Position = 0;

                fakeDatabus.StreamsToReturn[databusKey] = stream;

                await receiveBehavior.Invoke(
                    new IncomingLogicalMessageContext(
                        message,
                        "messageId",
                        "replyToAddress",
                        new Dictionary<string, string>
                        {
                            {"NServiceBus.DataBus." + propertyKey, databusKey}
                        },
                        null),
                    ctx => TaskEx.CompletedTask);
            }

            var instance = (MessageWithDataBusProperty)message.Instance;

            Assert.AreEqual(instance.DataBusProperty.Value, "test");
        }