Beispiel #1
0
        public void DeserializesClassWithIList()
        {
            var  serializer = new EventSerializer();
            bool hasMetadata;
            var  obj = new ObjectWithIList {
                Items = new List <int> {
                    1
                }
            };
            var meta = serializer.Serialize(out hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var    deserializer = new EventDeserializer();
            object obj2;

            Assert.False(deserializer.Deserialize(out obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal(obj, obj2);

            deserializer = new EventDeserializer();
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal(obj, obj2);
        }
Beispiel #2
0
        public void DeserializesClassWithIListArray()
        {
            var  serializer = new EventSerializer();
            bool hasMetadata;
            var  obj = new ObjectWithIList2 {
                Items = new ObjectDbTest.Person[] { new ObjectDbTest.Person {
                                                        Name = "A", Age = 1
                                                    } }
            };
            var meta = serializer.Serialize(out hasMetadata, obj).ToAsyncSafe();

            Assert.Equal(99, meta.Length);
            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            serializer = new EventSerializer();
            serializer.ProcessMetadataLog(meta);
            var data2 = serializer.Serialize(out hasMetadata, obj);

            var    deserializer = new EventDeserializer();
            object obj2;

            Assert.False(deserializer.Deserialize(out obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal(obj, obj2);

            deserializer = new EventDeserializer();
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal(obj, obj2);
        }
        public void CanMigrateListInDict()
        {
            var obj = PassThroughEventStorage(new EventDictListRoot
            {
                Items = new Dictionary <ulong, IList <Item> > {
                    { 1, new List <Item> {
                          new Item {
                              Field = "A"
                          }
                      } }
                }
            }, new FullNameTypeMapper());
            var  serializer = new EventSerializer();
            bool hasMetadata;
            var  meta = serializer.Serialize(out hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var    deserializer = new EventDeserializer();
            object obj2;

            Assert.False(deserializer.Deserialize(out obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
        }
        public void CanMigrateListWithNewFields()
        {
            var parentMapper = new FullNameTypeMapper();
            var mapper       = new EventStoreTest.OverloadableTypeMapper(typeof(Item2), parentMapper.ToName(typeof(Item)),
                                                                         new EventStoreTest.OverloadableTypeMapper(typeof(EventRoot2), parentMapper.ToName(typeof(EventRoot)),
                                                                                                                   parentMapper
                                                                                                                   ));
            var obj = PassThroughEventStorage(new EventRoot
            {
                Items = new List <Item> {
                    new Item {
                        Field = "A"
                    }
                }
            }, mapper);
            var  serializer = new EventSerializer(mapper);
            bool hasMetadata;
            var  meta = serializer.Serialize(out hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var    deserializer = new EventDeserializer(mapper);
            object obj2;

            Assert.False(deserializer.Deserialize(out obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
        }
Beispiel #5
0
        public void DeserializeSimpleClass()
        {
            var serializer = new EventSerializer();
            bool hasMetadata;
            var obj = new User { Name = "Boris", Age = 40 };
            var meta = serializer.Serialize(out hasMetadata, obj).ToAsyncSafe();
            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var deserializer = new EventDeserializer();
            object obj2;
            Assert.False(deserializer.Deserialize(out obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal(obj, obj2);
        }
Beispiel #6
0
        public void SerializingBoxedDoubleDoesNotCrash()
        {
            var serializer = new EventSerializer();
            var obj        = new DtoWithObject {
                Something = 1.2
            };
            var meta = serializer.Serialize(out var hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var deserializer = new EventDeserializer();

            Assert.False(deserializer.Deserialize(out var obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal(1.2, ((DtoWithObject)obj2).Something);
        }
Beispiel #7
0
        public void SerializingSkipsNotStoredProperties()
        {
            var serializer = new EventSerializer();
            var obj        = new DtoWithNotStored {
                Name = "Boris", Skip = 1
            };
            var meta = serializer.Serialize(out var hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var deserializer = new EventDeserializer();

            Assert.False(deserializer.Deserialize(out var obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal(0, ((DtoWithNotStored)obj2).Skip);
        }
Beispiel #8
0
        public void SimpleNestedObjects()
        {
            var serializer = new EventSerializer();
            var obj        = new EventWithUser
            {
                User = new User()
            };
            var meta = serializer.Serialize(out var hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var deserializer = new EventDeserializer();

            Assert.False(deserializer.Deserialize(out var obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
        }
Beispiel #9
0
        public void DeserializesClassWithEnum()
        {
            var serializer = new EventSerializer();
            var obj        = new ObjectWithEnum {
                State = StateEnum.Alive
            };
            var meta = serializer.Serialize(out _, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out _, obj);

            var deserializer = new EventDeserializer();

            Assert.False(deserializer.Deserialize(out var obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal(obj, obj2);
        }
Beispiel #10
0
        public void SkipsIIndirect()
        {
            var serializer = new EventSerializer();
            var obj        = new EventWithIIndirect
            {
                Name = "A",
                Ind1 = new DBIndirect <User>(),
                Ind2 = new List <IIndirect <User> >()
            };
            var meta = serializer.Serialize(out var hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var deserializer = new EventDeserializer();

            Assert.False(deserializer.Deserialize(out var obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
        }
Beispiel #11
0
        public void DeserializesAsObjectClassWithList()
        {
            var serializer = new EventSerializer();
            var obj        = new ObjectWithList {
                Items = new List <int> {
                    1
                }
            };
            var meta = serializer.Serialize(out var hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var deserializer = new EventDeserializer(new TypeSerializersTest.ToDynamicMapper());

            Assert.False(deserializer.Deserialize(out dynamic obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal(1, obj2.Items[0]);
        }
Beispiel #12
0
        public void SupportPureArray()
        {
            var serializer = new EventSerializer();
            var obj        = new PureArray {
                A = new[] { "A", "B" }, B = new[] { 42, 7 }
            };
            var meta = serializer.Serialize(out var hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var deserializer = new EventDeserializer();

            Assert.False(deserializer.Deserialize(out var obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            var ev = obj2 as PureArray;

            Assert.Equal(ev.A, new[] { "A", "B" });
            Assert.Equal(ev.B, new[] { 42, 7 });
        }
Beispiel #13
0
        public void DeserializesAsObjectClassWithDictionaryOfSimpleTypes()
        {
            var serializer = new EventSerializer();
            var obj        = new ObjectWithDictionaryOfSimpleType {
                Items = new Dictionary <int, string>()
                {
                    { 1, "Ahoj" }
                }
            };
            var meta = serializer.Serialize(out var hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var deserializer = new EventDeserializer(new TypeSerializersTest.ToDynamicMapper());

            Assert.False(deserializer.Deserialize(out dynamic obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal("Ahoj", obj2.Items[1].ToString());
        }
Beispiel #14
0
        public void DeserializesClassWithDictionaryOfSimpleTypes()
        {
            var serializer = new EventSerializer();
            var obj        = new ObjectWithDictionaryOfSimpleType {
                Items = new Dictionary <int, string>()
                {
                    { 1, "Ahoj" }
                }
            };
            var meta = serializer.Serialize(out var hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var deserializer = new EventDeserializer();

            Assert.False(deserializer.Deserialize(out var obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            Assert.Equal(obj, obj2);
        }
Beispiel #15
0
        public void SupportStrangeVisibilities()
        {
            var serializer = new EventSerializer();
            var obj        = new StrangeVisibilities {
                A = "a", C = "c", D = "d"
            };
            var meta = serializer.Serialize(out var hasMetadata, obj).ToAsyncSafe();

            serializer.ProcessMetadataLog(meta);
            var data = serializer.Serialize(out hasMetadata, obj);

            var deserializer = new EventDeserializer();

            Assert.False(deserializer.Deserialize(out var obj2, data));
            deserializer.ProcessMetadataLog(meta);
            Assert.True(deserializer.Deserialize(out obj2, data));
            var ev = obj2 as StrangeVisibilities;

            Assert.Equal("a", ev.A);
            Assert.Null(ev.B);
            Assert.Equal("c", ev.C);
        }