Esempio n. 1
0
        public void GetTypeName_ReturnTypeName_ThatIsRecoverable_GenericClassMultiple()
        {
            var result = MessageTypeConverters.GetTypeName(typeof(GenericTestClass <string, IDictionary <object, DateTime>, int>));

            var resultType = Type.GetType(result);

            Assert.True(typeof(GenericTestClass <string, IDictionary <object, DateTime>, int>).Equals(resultType));
        }
Esempio n. 2
0
        public Task ExecuteAsync(OutgoingPipelineContext ctx, Func <Task> next)
        {
            var message = ctx.Load <Messages.Message>();

            message.Headers[MessageHeaders.EventType] = MessageTypeConverters.GetTypeName(message.Body.GetType());

            return(FuncInvoker.Invoke(next));
        }
Esempio n. 3
0
        public void GetTypeName_ReturnTypeName_ThatIsRecoverable_GenericClass()
        {
            var result = MessageTypeConverters.GetTypeName(typeof(GenericTestClass <string>));

            var resultType = Type.GetType(result);

            Assert.True(typeof(GenericTestClass <string>).Equals(resultType));
        }
Esempio n. 4
0
        public void GetTypeName_ReturnTypeName_ThatIsRecoverable_SimpleClass()
        {
            var result = MessageTypeConverters.GetTypeName(typeof(TestClass));

            var resultType = Type.GetType(result);

            Assert.True(typeof(TestClass).Equals(resultType));
        }
Esempio n. 5
0
        private Message Deserialize(TransportMessage message)
        {
            var messageTypeName = message.Headers[MessageHeaders.EventType];
            var messageType     = MessageTypeConverters.GetNameType(messageTypeName);

            var bodyString = DefaultEncoding.GetString(message.Body);

            return(new Message(JsonConvert.DeserializeObject(bodyString, messageType), new Dictionary <string, string>(message.Headers)));
        }
Esempio n. 6
0
        public void GetNameType_ReturnProperType_GenericClassMultiple()
        {
            var typeString = "KDR.Unit.Tests.Messages.MessageTypeConvertersTests+GenericTestClass`3[[System.String, System.Private.CoreLib], [System.Collections.Generic.IDictionary`2[[System.Object, System.Private.CoreLib], [System.DateTime, System.Private.CoreLib]], System.Private.CoreLib], [System.Int32, System.Private.CoreLib]], KDR.Unit.Tests";

            var resultType = MessageTypeConverters.GetNameType(typeString);

            var result = MessageTypeConverters.GetTypeName(resultType);

            Assert.AreEqual(typeString, result);
        }
Esempio n. 7
0
        public void GetNameType_ReturnProperType_GenericClass()
        {
            var typeString = "KDR.Unit.Tests.Messages.MessageTypeConvertersTests+GenericTestClass`1[[System.String, System.Private.CoreLib]], KDR.Unit.Tests";

            var resultType = MessageTypeConverters.GetNameType(typeString);

            var result = MessageTypeConverters.GetTypeName(resultType);

            Assert.AreEqual(typeString, result);
        }
Esempio n. 8
0
        public void GetNameType_ReturnProperType_SimpleClass()
        {
            var typeString = "KDR.Unit.Tests.Messages.MessageTypeConvertersTests+TestClass, KDR.Unit.Tests";

            var resultType = MessageTypeConverters.GetNameType(typeString);

            var result = MessageTypeConverters.GetTypeName(resultType);

            Assert.AreEqual(typeString, result);
        }
Esempio n. 9
0
        private Message Deserialize(TransportMessage message)
        {
            var messageTypeName = message.Headers[MessageHeaders.EventType];
            var messageType     = MessageTypeConverters.GetNameType(messageTypeName);

            var dataContractSerializer = new System.Runtime.Serialization.DataContractSerializer(messageType);

            using (var memoryStream = new MemoryStream(message.Body))
            {
                return(new Message(dataContractSerializer.ReadObject(memoryStream), new Dictionary <string, string>(message.Headers)));
            }
        }
Esempio n. 10
0
        private TransportMessage Serialize(Message message)
        {
            var dataContractSerializer = new System.Runtime.Serialization.DataContractSerializer(message.Body.GetType());

            var headers = new Dictionary <string, string>(message.Headers)
            {
                [MessageHeaders.ContentType] = ContentTypes.XmlContentType,
                [MessageHeaders.EventType]   = MessageTypeConverters.GetTypeName(message.Body.GetType())
            };

            using (var memoryStream = new MemoryStream())
            {
                dataContractSerializer.WriteObject(memoryStream, message.Body);

                return(new TransportMessage(headers, memoryStream.ToArray()));
            }
        }
Esempio n. 11
0
        private TransportMessage Serialize(Message message)
        {
            var body      = JsonConvert.SerializeObject(message.Body, DefaultSettings);
            var bodyBytes = DefaultEncoding.GetBytes(body);

            //TODO: Powinno zostać wyciągnięte
            var headers = new Dictionary <string, string>(message.Headers)
            {
                [MessageHeaders.ContentType] = ContentTypes.JsonUtf8ContentType, [MessageHeaders.EventType] = MessageTypeConverters.GetTypeName(message.Body.GetType())
            };

            return(new TransportMessage(headers, bodyBytes));
        }