示例#1
0
        public void Can_deserialize_between_dynamic_generic_and_strict_messages()
        {
            var original = new DynamicMessage
            {
                Id            = Guid.NewGuid(),
                Priority      = 3,
                ReplyTo       = "http://path/to/reply.svc",
                RetryAttempts = 1,
                Type          = typeof(MessageBody),
                Body          = new MessageBody
                {
                    Action    = "Alphabet",
                    Arguments = { "a", "b", "c" }
                }
            };

            var jsv         = TypeSerializer.SerializeToString(original);
            var dynamicType = TypeSerializer.DeserializeFromString <DynamicMessage>(jsv);
            var genericType = TypeSerializer.DeserializeFromString <GenericMessage <MessageBody> >(jsv);
            var strictType  = TypeSerializer.DeserializeFromString <StrictMessage>(jsv);

            AssertHeadersAreEqual(dynamicType, original);
            AssertBodyIsEqual(dynamicType.GetBody(), (MessageBody)original.Body);

            AssertHeadersAreEqual(genericType, original);
            AssertBodyIsEqual(genericType.Body, (MessageBody)original.Body);

            AssertHeadersAreEqual(strictType, original);
            AssertBodyIsEqual(strictType.Body, (MessageBody)original.Body);

            //Debug purposes
            Console.WriteLine(strictType.Dump());

            /*
             *           {
             *                  Id: 891653ea2d0a4626ab0623fc2dc9dce1,
             *                  ReplyTo: http://path/to/reply.svc,
             *                  Priority: 3,
             *                  RetryAttempts: 1,
             *                  Body:
             *                  {
             *                          Action: Alphabet,
             *                          Arguments:
             *                          [
             *                                  a,
             *                                  b,
             *                                  c
             *                          ]
             *                  }
             *          }
             */
        }
示例#2
0
        public void Object_Set_To_Object_Test()
        {
            var original = new DynamicMessage
            {
                Id            = Guid.NewGuid(),
                Priority      = 3,
                ReplyTo       = "http://path/to/reply.svc",
                RetryAttempts = 1,
                Type          = typeof(MessageBody),
                Body          = new Object()
            };

            var jsv             = TypeSerializer.SerializeToString(original);
            var json            = JsonSerializer.SerializeToString(original);
            var jsvDynamicType  = TypeSerializer.DeserializeFromString <DynamicMessage>(jsv);
            var jsonDynamicType = JsonSerializer.DeserializeFromString <DynamicMessage>(json);

            AssertHeadersAreEqual(jsvDynamicType, original);
            AssertHeadersAreEqual(jsonDynamicType, original);
            AssertHeadersAreEqual(jsvDynamicType, jsonDynamicType);
        }