public void When_using_the_default_serialization_strategy_messages_are_correctly_round_tripped()
        {
            var typeNameSerializer = new TypeNameSerializer();
            var serializer = new JsonSerializer( typeNameSerializer );
            const string correlationId = "CorrelationId";
            var serializationStrategy = new DefaultMessageSerializationStrategy( typeNameSerializer, serializer, () => correlationId );

            var messageBody = new MyMessage {Text = "Hello world!"};
            var message = new Message<MyMessage>( messageBody );
            var serializedMessage = serializationStrategy.SerializeMessage( message );
            var deserializedMessage = serializationStrategy.DeserializeMessage( serializedMessage.Properties, serializedMessage.Body );

            Assert.That( deserializedMessage.Message.Body.GetType(), Is.EqualTo( message.Body.GetType() ) );
            Assert.That( deserializedMessage.Message.Body.Text, Is.EqualTo( message.Body.Text ) );
        }
        public void When_using_the_default_serialization_strategy_messages_are_correctly_round_tripped_when_null()
        {
            var          typeNameSerializer = new DefaultTypeNameSerializer();
            var          serializer         = new JsonSerializer();
            const string correlationId      = "CorrelationId";

            var serializationStrategy = new DefaultMessageSerializationStrategy(typeNameSerializer, serializer, new StaticCorrelationIdGenerationStrategy(correlationId));

            var message             = new Message <MyMessage>();
            var serializedMessage   = serializationStrategy.SerializeMessage(message);
            var deserializedMessage = serializationStrategy.DeserializeMessage(serializedMessage.Properties, serializedMessage.Body);

            Assert.Equal(deserializedMessage.MessageType, message.MessageType);
            Assert.Null(((Message <MyMessage>)deserializedMessage).Body);
        }
        public void When_using_the_default_serialization_strategy_messages_are_correctly_round_tripped()
        {
            var          typeNameSerializer    = new TypeNameSerializer();
            var          serializer            = new JsonSerializer(typeNameSerializer);
            const string correlationId         = "CorrelationId";
            var          serializationStrategy = new DefaultMessageSerializationStrategy(typeNameSerializer, serializer, () => correlationId);

            var messageBody = new MyMessage {
                Text = "Hello world!"
            };
            var message             = new Message <MyMessage>(messageBody);
            var serializedMessage   = serializationStrategy.SerializeMessage(message);
            var deserializedMessage = serializationStrategy.DeserializeMessage(serializedMessage.Properties, serializedMessage.Body);

            Assert.That(deserializedMessage.Message.Body.GetType(), Is.EqualTo(message.Body.GetType()));
            Assert.That(deserializedMessage.Message.Body.Text, Is.EqualTo(message.Body.Text));
        }
        public void Should_be_able_to_store_a_schedule_with_exchange()
        {
            var typeNameSerializer = new TypeNameSerializer();
            var conventions = new Conventions(typeNameSerializer);
            var jsonSerializer = new JsonSerializer(typeNameSerializer);
            var messageSerializationStrategy = new DefaultMessageSerializationStrategy(typeNameSerializer, jsonSerializer, new DefaultCorrelationIdGenerationStrategy());
            var testScheduleMessage = new TestScheduleMessage { Text = "Hello World" };

            var serializedMessage = messageSerializationStrategy.SerializeMessage(new Message<TestScheduleMessage>(testScheduleMessage));

            scheduleRepository.Store(new ScheduleMe
            {
                BindingKey = "",
                CancellationKey = "bcd",
                Exchange = conventions.ExchangeNamingConvention(typeof(TestScheduleMessage)),
                ExchangeType = ExchangeType.Topic,
                RoutingKey = "#",
                WakeTime = DateTime.UtcNow.AddMilliseconds(-1),
                InnerMessage = serializedMessage.Body,
                MessageProperties = serializedMessage.Properties
            });
        }
        public void Should_be_able_to_store_a_schedule_with_exchange()
        {
            var typeNameSerializer           = new TypeNameSerializer();
            var conventions                  = new Conventions(typeNameSerializer);
            var jsonSerializer               = new JsonSerializer(typeNameSerializer);
            var messageSerializationStrategy = new DefaultMessageSerializationStrategy(typeNameSerializer, jsonSerializer, new DefaultCorrelationIdGenerationStrategy());
            var testScheduleMessage          = new TestScheduleMessage {
                Text = "Hello World"
            };

            var serializedMessage = messageSerializationStrategy.SerializeMessage(new Message <TestScheduleMessage>(testScheduleMessage));

            scheduleRepository.Store(new ScheduleMe
            {
                BindingKey        = "",
                CancellationKey   = "bcd",
                Exchange          = conventions.ExchangeNamingConvention(typeof(TestScheduleMessage)),
                ExchangeType      = ExchangeType.Topic,
                RoutingKey        = "#",
                WakeTime          = DateTime.UtcNow.AddMilliseconds(-1),
                InnerMessage      = serializedMessage.Body,
                MessageProperties = serializedMessage.Properties
            });
        }