public void When_publishing_event_class_should_set_class_as_message_type()
        {
            var publishPipeline = new FakePipeline <IOutgoingPublishContext>();
            var context         = CreateContext(publishPipeline);

            MessageOperations.Publish <MyMessage>(context, m => { }, new PublishOptions());

            Assert.That(publishPipeline.ReceivedContext.Message.MessageType, Is.EqualTo(typeof(MyMessage)));
        }
        public void When_publishing_should_generate_message_id_and_set_message_id_header()
        {
            var publishPipeline = new FakePipeline <IOutgoingPublishContext>();
            var context         = CreateContext(publishPipeline);

            MessageOperations.Publish <MyMessage>(context, m => { }, new PublishOptions());

            var messageId = publishPipeline.ReceivedContext.MessageId;

            Assert.IsNotNull(messageId);
            Assert.AreEqual(messageId, publishPipeline.ReceivedContext.Headers[Headers.MessageId]);
        }
        public void When_publishing_with_user_defined_message_id_should_set_defined_id_and_header()
        {
            const string expectedMessageID = "expected message id";

            var publishPipeline = new FakePipeline <IOutgoingPublishContext>();
            var context         = CreateContext(publishPipeline);
            var publishOptions  = new PublishOptions();

            publishOptions.SetMessageId(expectedMessageID);

            MessageOperations.Publish <MyMessage>(context, m => { }, publishOptions);

            Assert.AreEqual(expectedMessageID, publishPipeline.ReceivedContext.MessageId);
            Assert.AreEqual(expectedMessageID, publishPipeline.ReceivedContext.Headers[Headers.MessageId]);
        }
        public void When_publishing_should_clone_headers()
        {
            var publishPipeline = new FakePipeline <IOutgoingPublishContext>();
            var context         = CreateContext(publishPipeline);
            var publishOptions  = new PublishOptions();

            publishOptions.SetHeader("header1", "header1 value");

            MessageOperations.Publish <MyMessage>(context, m => { }, publishOptions);
            publishPipeline.ReceivedContext.Headers.Add("header2", "header2 value");
            publishPipeline.ReceivedContext.Headers["header1"] = "updated header1 value";

            var optionsHeaders = publishOptions.GetHeaders();

            Assert.AreEqual(1, optionsHeaders.Count);
            Assert.AreEqual("header1 value", optionsHeaders["header1"]);
        }