public void SerializationRunsAndDoesNotLeak1Byte() { var serializer = new EventSerializer(); bool hasMetadata; var meta = serializer.Serialize(out hasMetadata, new User()); serializer.ProcessMetadataLog(meta); long baselineMemory = 0; for (int i = 0; i < 100; i++) { serializer.Serialize(out hasMetadata, new User()); Assert.False(hasMetadata); if (i == 2) { GC.Collect(2); GC.WaitForPendingFinalizers(); GC.Collect(2); baselineMemory = GC.GetTotalMemory(false); } } GC.Collect(2); GC.WaitForPendingFinalizers(); GC.Collect(2); Assert.InRange(GC.GetTotalMemory(false), 0, baselineMemory+400); }
public void ParsingMetadataStopsGeneratingThem() { var serializer = new EventSerializer(); bool hasMetadata; var meta = serializer.Serialize(out hasMetadata, new User()); serializer.ProcessMetadataLog(meta); var data = serializer.Serialize(out hasMetadata, new User()); Assert.False(hasMetadata); Assert.InRange(data.Length, 1, 10); }
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); }
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 SerializingNewObjectsWritesNewMetadata() { var serializer = new EventSerializer(); bool hasMetadata; var data = serializer.Serialize(out hasMetadata, new User()); Assert.True(hasMetadata); Assert.InRange(data.Length, 1, 100); }
public void CanMigrateListWithChangedEnum() { var parentMapper = new FullNameTypeMapper(); var mapper = new EventStoreTest.OverloadableTypeMapper(typeof(ItemEn2), parentMapper.ToName(typeof(ItemEn)), new EventStoreTest.OverloadableTypeMapper(typeof(EventRootEn2), parentMapper.ToName(typeof(EventRootEn)), parentMapper )); var obj = PassThroughEventStorage(new EventRootEn { Items = new List<ItemEn> { ItemEn.One } }, 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)); }