public void TestDictionaryNonIdentifiableItemsDeserialization() { ShadowObject.Enable = true; var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(YamlDictionaryNonIdentifiable); writer.Flush(); stream.Position = 0; var instance = AssetYamlSerializer.Default.Deserialize(stream); Assert.NotNull(instance); Assert.AreEqual(typeof(ContainerNonIdentifiableDictionary), instance.GetType()); var obj = (ContainerNonIdentifiableDictionary)instance; Assert.AreEqual("Root", obj.Name); Assert.AreEqual(2, obj.Objects.Count); Assert.AreEqual("aaa", obj.Objects["AAA"].Name); Assert.AreEqual(2, obj.Objects["AAA"].Strings.Count); Assert.AreEqual("bbb", obj.Objects["AAA"].Strings[0]); Assert.AreEqual("ccc", obj.Objects["AAA"].Strings[1]); Assert.AreEqual("ddd", obj.Objects["BBB"].Name); Assert.AreEqual(2, obj.Objects["BBB"].Strings.Count); Assert.AreEqual("eee", obj.Objects["BBB"].Strings[0]); Assert.AreEqual("fff", obj.Objects["BBB"].Strings[1]); var objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); Assert.AreEqual(IdentifierGenerator.Get(2), objectIds["AAA"]); Assert.AreEqual(IdentifierGenerator.Get(1), objectIds["BBB"]); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects["AAA"].Strings); Assert.AreEqual(IdentifierGenerator.Get(5), objectIds[0]); Assert.AreEqual(IdentifierGenerator.Get(6), objectIds[1]); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects["BBB"].Strings); Assert.AreEqual(IdentifierGenerator.Get(7), objectIds[0]); Assert.AreEqual(IdentifierGenerator.Get(8), objectIds[1]); Assert.AreEqual(2, obj.NonIdentifiableObjects.Count); Assert.AreEqual("ggg", obj.NonIdentifiableObjects["CCC"].Name); Assert.AreEqual(2, obj.NonIdentifiableObjects["CCC"].Strings.Count); Assert.AreEqual("hhh", obj.NonIdentifiableObjects["CCC"].Strings[0]); Assert.AreEqual("iii", obj.NonIdentifiableObjects["CCC"].Strings[1]); Assert.AreEqual("jjj", obj.NonIdentifiableObjects["DDD"].Name); Assert.AreEqual(2, obj.NonIdentifiableObjects["DDD"].Strings.Count); Assert.AreEqual("kkk", obj.NonIdentifiableObjects["DDD"].Strings[0]); Assert.AreEqual("lll", obj.NonIdentifiableObjects["DDD"].Strings[1]); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj.NonIdentifiableObjects, out objectIds)); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects); Assert.AreEqual(0, objectIds.KeyCount); Assert.AreEqual(0, objectIds.DeletedCount); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects["CCC"].Strings); Assert.AreEqual(IdentifierGenerator.Get(9), objectIds[0]); Assert.AreEqual(IdentifierGenerator.Get(10), objectIds[1]); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects["DDD"].Strings); Assert.AreEqual(IdentifierGenerator.Get(11), objectIds[0]); Assert.AreEqual(IdentifierGenerator.Get(12), objectIds[1]); }
public void TestDictionaryDeserializationOldWay() { ShadowObject.Enable = true; var yaml = @"!SiliconStudio.Assets.Tests.Yaml.TestCollectionIdsSerialization+ContainerDictionary,SiliconStudio.Assets.Tests Name: Root Strings: 000000c8-00c8-0000-c800-0000c8000000: aaa 00000064-0064-0000-6400-000064000000: bbb Objects: key3: ~Id: 00000003-0003-0000-0300-000003000000 Name: obj1 Strings: {} Objects: {} key4: ~Id: 00000004-0004-0000-0400-000004000000 Name: obj2 Strings: {} Objects: {} "; var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(yaml); writer.Flush(); stream.Position = 0; var instance = AssetYamlSerializer.Default.Deserialize(stream); Assert.NotNull(instance); Assert.AreEqual(typeof(ContainerDictionary), instance.GetType()); var obj = (ContainerDictionary)instance; Assert.AreEqual("Root", obj.Name); Assert.AreEqual(2, obj.Strings.Count); Assert.AreEqual("aaa", obj.Strings[GuidGenerator.Get(200)]); Assert.AreEqual("bbb", obj.Strings[GuidGenerator.Get(100)]); Assert.AreEqual(2, obj.Objects.Count); Assert.AreEqual("obj1", obj.Objects["key3"].Name); Assert.AreEqual("obj2", obj.Objects["key4"].Name); var stringIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Strings); var objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); Assert.AreEqual(2, stringIds.KeyCount); Assert.AreEqual(0, stringIds.DeletedCount); Assert.IsTrue(stringIds.ContainsKey(GuidGenerator.Get(200))); Assert.IsTrue(stringIds.ContainsKey(GuidGenerator.Get(100))); Assert.AreEqual(2, objectIds.KeyCount); Assert.AreEqual(0, objectIds.DeletedCount); Assert.IsTrue(objectIds.ContainsKey("key3")); Assert.IsTrue(objectIds.ContainsKey("key4")); Assert.AreEqual(IdentifierGenerator.Get(3), objectIds["key3"]); Assert.AreEqual(IdentifierGenerator.Get(4), objectIds["key4"]); }
public void TestAbstractReferenceableDictionaryDeserialization() { var obj = (CollectionContainer)Deserialize(AbstractReferenceableDictionaryYaml); Assert.NotNull(obj.AbstractRefDictionary); Assert.AreEqual(2, obj.AbstractRefDictionary.Count); Assert.AreEqual(obj.AbstractRefDictionary["Item1"], obj.AbstractRefDictionary["Item2"]); var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.AbstractRefDictionary); Assert.AreEqual(IdentifierGenerator.Get(1), ids["Item1"]); Assert.AreEqual(IdentifierGenerator.Get(2), ids["Item2"]); Assert.AreEqual(GuidGenerator.Get(1), obj.AbstractRefDictionary["Item1"].Id); Assert.AreEqual("Test", obj.AbstractRefDictionary["Item1"].Value); }
public void TestAbstractReferenceableListDeserialization() { var obj = (CollectionContainer)Deserialize(AbstractReferenceableListYaml); Assert.NotNull(obj.AbstractRefList); Assert.AreEqual(2, obj.AbstractRefList.Count); Assert.AreEqual(obj.AbstractRefList[0], obj.AbstractRefList[1]); var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.AbstractRefList); Assert.AreEqual(IdentifierGenerator.Get(1), ids[0]); Assert.AreEqual(IdentifierGenerator.Get(2), ids[1]); Assert.AreEqual(GuidGenerator.Get(1), obj.AbstractRefList[0].Id); Assert.AreEqual("Test", obj.AbstractRefList[0].Value); }
public void TestDictionarySerialization() { ShadowObject.Enable = true; var obj = new ContainerDictionary("Root") { Strings = { { GuidGenerator.Get(200), "aaa" }, { GuidGenerator.Get(100), "bbb" } }, Objects = { { "key3", new ContainerCollection("obj1") }, { "key4", new ContainerCollection("obj2") } }, }; var stringIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Strings); stringIds[GuidGenerator.Get(200)] = IdentifierGenerator.Get(2); stringIds[GuidGenerator.Get(100)] = IdentifierGenerator.Get(1); var objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); objectIds["key3"] = IdentifierGenerator.Get(3); objectIds["key4"] = IdentifierGenerator.Get(4); var yaml = SerializeAsString(obj); Assert.AreEqual(YamlDictionary, yaml); }
public void TestCollectionSerialization() { ShadowObject.Enable = true; var obj = new ContainerCollection("Root") { Strings = { "aaa", "bbb" }, Objects = { new ContainerCollection("obj1"), new ContainerCollection("obj2") } }; var stringIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Strings); stringIds[0] = IdentifierGenerator.Get(2); stringIds[1] = IdentifierGenerator.Get(1); var objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); objectIds[0] = IdentifierGenerator.Get(3); objectIds[1] = IdentifierGenerator.Get(4); var yaml = SerializeAsString(obj); Assert.AreEqual(YamlCollection, yaml); }
public void TestDictionaryNonIdentifiableItemsSerialization() { ShadowObject.Enable = true; var obj = new ContainerNonIdentifiableDictionary("Root") { Objects = { { "AAA", new ContainerCollection { Name = "aaa", Strings ={ "bbb", "ccc" } } },{ "BBB", new ContainerCollection { Name = "ddd", Strings = { "eee", "fff" } } } }, NonIdentifiableObjects = { { "CCC", new ContainerCollection { Name = "ggg", Strings ={ "hhh", "iii" } } },{ "DDD", new ContainerCollection { Name = "jjj", Strings = { "kkk", "lll" } } } }, }; var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); ids["AAA"] = IdentifierGenerator.Get(2); ids["BBB"] = IdentifierGenerator.Get(1); ids = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects["AAA"].Strings); ids[0] = IdentifierGenerator.Get(5); ids[1] = IdentifierGenerator.Get(6); ids = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects["BBB"].Strings); ids[0] = IdentifierGenerator.Get(7); ids[1] = IdentifierGenerator.Get(8); ids = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects); ids["CCC"] = IdentifierGenerator.Get(3); ids["DDD"] = IdentifierGenerator.Get(4); ids = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects["CCC"].Strings); ids[0] = IdentifierGenerator.Get(9); ids[1] = IdentifierGenerator.Get(10); ids = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects["DDD"].Strings); ids[0] = IdentifierGenerator.Get(11); ids[1] = IdentifierGenerator.Get(12); var yaml = SerializeAsString(obj); Assert.AreEqual(YamlDictionaryNonIdentifiable, yaml); }
public void TestDictionaryDeserializationWithDeleted() { ShadowObject.Enable = true; var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(YamlDictionaryWithDeleted); writer.Flush(); stream.Position = 0; var instance = AssetYamlSerializer.Default.Deserialize(stream); Assert.NotNull(instance); Assert.AreEqual(typeof(ContainerDictionary), instance.GetType()); var obj = (ContainerDictionary)instance; Assert.AreEqual("Root", obj.Name); Assert.AreEqual(2, obj.Strings.Count); Assert.AreEqual("aaa", obj.Strings[GuidGenerator.Get(200)]); Assert.AreEqual("bbb", obj.Strings[GuidGenerator.Get(100)]); Assert.AreEqual(2, obj.Objects.Count); Assert.AreEqual("obj1", obj.Objects["key3"].Name); Assert.AreEqual("obj2", obj.Objects["key4"].Name); var stringIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Strings); Assert.AreEqual(IdentifierGenerator.Get(8), stringIds[GuidGenerator.Get(200)]); Assert.AreEqual(IdentifierGenerator.Get(5), stringIds[GuidGenerator.Get(100)]); var objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); Assert.AreEqual(IdentifierGenerator.Get(3), objectIds["key3"]); Assert.AreEqual(IdentifierGenerator.Get(4), objectIds["key4"]); var deletedItems = stringIds.DeletedItems.ToList(); Assert.AreEqual(2, deletedItems.Count); Assert.AreEqual(IdentifierGenerator.Get(1), deletedItems[0]); Assert.AreEqual(IdentifierGenerator.Get(3), deletedItems[1]); deletedItems = objectIds.DeletedItems.ToList(); Assert.AreEqual(2, deletedItems.Count); Assert.AreEqual(IdentifierGenerator.Get(1), deletedItems[0]); Assert.AreEqual(IdentifierGenerator.Get(6), deletedItems[1]); }
public void TestConcreteNonIdentifiableReferenceableDictionarySerialization() { var obj = new NonIdentifiableCollectionContainer(); var item = new Referenceable { Id = GuidGenerator.Get(1), Value = "Test" }; obj.ConcreteRefDictionary.Add("Item1", item); obj.ConcreteRefDictionary.Add("Item2", item); var objectReferences = new YamlAssetMetadata <Guid>(); var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.ConcreteRefDictionary); ids["Item1"] = IdentifierGenerator.Get(1); ids["Item2"] = IdentifierGenerator.Get(2); var path = new YamlAssetPath(); path.PushMember(nameof(CollectionContainer.ConcreteRefDictionary)); path.PushIndex("Item1"); objectReferences.Set(path, GuidGenerator.Get(1)); var yaml = SerializeAsString(obj, objectReferences); Assert.AreEqual(ConcreteNonIdentifiableReferenceableDictionaryYaml, yaml); }
public void TestAbstractReferenceableListSerialization() { var obj = new CollectionContainer(); var item = new Referenceable { Id = GuidGenerator.Get(1), Value = "Test" }; obj.AbstractRefList.Add(item); obj.AbstractRefList.Add(item); var objectReferences = new YamlAssetMetadata <Guid>(); var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.AbstractRefList); ids[0] = IdentifierGenerator.Get(1); ids[1] = IdentifierGenerator.Get(2); var path = new YamlAssetPath(); path.PushMember(nameof(CollectionContainer.AbstractRefList)); path.PushItemId(IdentifierGenerator.Get(1)); objectReferences.Set(path, GuidGenerator.Get(1)); var yaml = SerializeAsString(obj, objectReferences); Assert.AreEqual(AbstractReferenceableListYaml, yaml); }