Exemplo n.º 1
0
        public void DefaultDeserializerFactory_CreateForType_ReturnsCorrectDeserializer(Type Deserializeable, Type DeserializerType)
        {
            var factory      = DeserializerFactory.CreateDefault();
            var Deserializer = factory.Create(Deserializeable);

            Assert.IsInstanceOf(DeserializerType, Deserializer);
        }
Exemplo n.º 2
0
        private TContract CreateProxyContract(Transporter light)
        {
            var memebers   = ProxyContractFactory.ParseContractInterface(typeof(TContract));
            var dispatcher = _contractBuilder.ReceiveDispatcherFactory();

            var outputMessages = memebers.GetMethods().Select(m => new MessageTypeInfo
            {
                ReturnType    = m.Value.ReturnType,
                ArgumentTypes = m.Value.GetParameters().Select(p => p.ParameterType).ToArray(),
                MessageId     = (short)m.Key
            });

            var inputMessages = memebers.GetProperties().Select(m => new MessageTypeInfo
            {
                ArgumentTypes = ReflectionHelper.GetDelegateInfoOrNull(m.Value.PropertyType).ParameterTypes,
                ReturnType    = ReflectionHelper.GetDelegateInfoOrNull(m.Value.PropertyType).ReturnType,
                MessageId     = (short)m.Key
            });

            var messenger = new Messenger(
                light,
                SerializerFactory.CreateDefault(_contractBuilder.UserSerializationRules.ToArray()),
                DeserializerFactory.CreateDefault(_contractBuilder.UserDeserializationRules.ToArray()),
                outputMessages: outputMessages.ToArray(),
                inputMessages: inputMessages.ToArray()
                );

            var interlocutor = new Interlocutor(messenger, dispatcher, _contractBuilder.MaxAnswerTimeoutDelay);

            var contract = ProxyContractFactory.CreateProxyContract <TContract>(interlocutor);

            return(contract);
        }
        public void DeserializationThrowsRule_throws()
        {
            //Just check the Moq generator behaves as expected
            var rule         = IntegrationTestsHelper.GetThrowsDeserializationRuleFor <string>();
            var deserializer = rule.GetDeserializer(typeof(string), DeserializerFactory.CreateDefault());

            Assert.Throws <Exception>(() => deserializer.Deserialize(new MemoryStream(), 0));
        }
Exemplo n.º 4
0
        private static object SerializeAndDeserializeBack(object origin)
        {
            var serializer   = SerializerFactory.CreateDefault().Create(origin.GetType());
            var deserializer = DeserializerFactory.CreateDefault().Create(origin.GetType());
            var stream       = new MemoryStream();

            serializer.Serialize(origin, stream);
            stream.Position = 0;
            var deserialized = deserializer.Deserialize(stream, (int)stream.Length);

            return(deserialized);
        }
Exemplo n.º 5
0
        private static T SerializeAndDeserializeBack <T>(T origin)
        {
            var type         = typeof(T);
            var serializer   = SerializerFactory.CreateDefault().Create(type);
            var deserializer = DeserializerFactory.CreateDefault().Create(type);
            var stream       = new MemoryStream();

            serializer.Serialize(origin, stream);
            stream.Position = 0;
            var deserialized = (T)deserializer.Deserialize(stream, (int)stream.Length);

            return(deserialized);
        }
Exemplo n.º 6
0
        public void ComplexTypesSequence_SerializeAndDeserializeBack_OriginAndDeserializedAreEqual()
        {
            var origin = new object[]
            {
                "fortyTwo",
                "",
                new int[] { 1, 2, 3, 4 },
                new User
                {
                    Age      = 18,
                    IsFemale = true,
                    Name     = "Kate"
                },
                new MyStruct()
                {
                    MyBool = true,
                    MyDate = DateTime.Now,
                    MyInt  = 42,
                    MyLong = 42,
                }
            };

            var sequenceTypes = origin.Select(o => o.GetType()).ToArray();

            var serializer   = SerializerFactory.CreateDefault().Create(sequenceTypes);
            var deserializer = DeserializerFactory.CreateDefault().Create(sequenceTypes);
            var stream       = new MemoryStream();

            serializer.Serialize(origin, stream);
            stream.Position = 0;
            var deserialized = (object[])deserializer.Deserialize(stream, (int)stream.Length);

            Assert.Multiple(() =>
            {
                Assert.AreEqual(origin[0], deserialized[0]);
                Assert.AreEqual(origin[1], deserialized[1]);
                CollectionAssert.AreEqual((IEnumerable)origin[2], (IEnumerable)deserialized[2]);
                Assert.IsTrue(((User)origin[3]).IsSameTo((User)deserialized[3]));
                Assert.IsTrue(((MyStruct)origin[4]).IsSameTo((MyStruct)deserialized[4]));
                Assert.AreEqual(origin.Length, deserialized.Length);
            });
        }
Exemplo n.º 7
0
        public void PrimitiveTypesSequence_SerializeAndDeserializeBack_OriginAndDeserializedAreEqual()
        {
            var origin = new object[]
            {
                "fortyTwo",
                42,
                42d,
                MyEnumDefType.Two,
                MyEnumULongType.Max
            };
            var sequenceTypes = origin.Select(o => o.GetType()).ToArray();

            var serializer   = SerializerFactory.CreateDefault().Create(sequenceTypes);
            var deserializer = DeserializerFactory.CreateDefault().Create(sequenceTypes);
            var stream       = new MemoryStream();

            serializer.Serialize(origin, stream);
            stream.Position = 0;
            var deserialized = (object[])deserializer.Deserialize(stream, (int)stream.Length);

            CollectionAssert.AreEqual(origin, deserialized);
        }