public void TestCollectionMismatchId() { const string baseYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAsset2,Stride.Core.Assets.Quantum.Tests Id: 10000000-0000-0000-0000-000000000000 Tags: [] Struct: MyStrings: {} MyStrings: 0a0000000a0000000a0000000a000000: String1 14000000140000001400000014000000: String2 "; const string derivedYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAsset2,Stride.Core.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 10000000-0000-0000-0000-000000000000:MyAsset Tags: [] Struct: MyStrings: {} MyStrings: 1a0000001a0000001a0000001a000000: String1 14000000140000001400000014000000: String2 "; var context = DeriveAssetTest <Types.MyAsset2, Types.MyAssetBasePropertyGraph> .LoadFromYaml(baseYaml, derivedYaml); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyStrings); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyStrings); Assert.Equal(2, context.BaseAsset.MyStrings.Count); Assert.Equal("String1", context.BaseAsset.MyStrings[0]); Assert.Equal("String2", context.BaseAsset.MyStrings[1]); Assert.Equal(2, context.DerivedAsset.MyStrings.Count); Assert.Equal("String1", context.DerivedAsset.MyStrings[0]); Assert.Equal("String2", context.DerivedAsset.MyStrings[1]); Assert.Equal(2, baseIds.KeyCount); Assert.Equal(0, baseIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), baseIds[0]); Assert.Equal(IdentifierGenerator.Get(20), baseIds[1]); Assert.Equal(2, derivedIds.KeyCount); Assert.Equal(0, derivedIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(26), derivedIds[0]); Assert.Equal(IdentifierGenerator.Get(20), derivedIds[1]); context.DerivedGraph.ReconcileWithBase(); Assert.Equal(2, context.BaseAsset.MyStrings.Count); Assert.Equal("String1", context.BaseAsset.MyStrings[0]); Assert.Equal("String2", context.BaseAsset.MyStrings[1]); Assert.Equal(2, context.DerivedAsset.MyStrings.Count); Assert.Equal("String1", context.DerivedAsset.MyStrings[0]); Assert.Equal("String2", context.DerivedAsset.MyStrings[1]); Assert.Equal(2, baseIds.KeyCount); Assert.Equal(0, baseIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), baseIds[0]); Assert.Equal(IdentifierGenerator.Get(20), baseIds[1]); Assert.Equal(2, derivedIds.KeyCount); Assert.Equal(0, derivedIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), derivedIds[0]); Assert.Equal(IdentifierGenerator.Get(20), derivedIds[1]); }
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.Equal(typeof(ContainerNonIdentifiableDictionary), instance.GetType()); var obj = (ContainerNonIdentifiableDictionary)instance; Assert.Equal("Root", obj.Name); Assert.Equal(2, obj.Objects.Count); Assert.Equal("aaa", obj.Objects["AAA"].Name); Assert.Equal(2, obj.Objects["AAA"].Strings.Count); Assert.Equal("bbb", obj.Objects["AAA"].Strings[0]); Assert.Equal("ccc", obj.Objects["AAA"].Strings[1]); Assert.Equal("ddd", obj.Objects["BBB"].Name); Assert.Equal(2, obj.Objects["BBB"].Strings.Count); Assert.Equal("eee", obj.Objects["BBB"].Strings[0]); Assert.Equal("fff", obj.Objects["BBB"].Strings[1]); var objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); Assert.Equal(IdentifierGenerator.Get(2), objectIds["AAA"]); Assert.Equal(IdentifierGenerator.Get(1), objectIds["BBB"]); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects["AAA"].Strings); Assert.Equal(IdentifierGenerator.Get(5), objectIds[0]); Assert.Equal(IdentifierGenerator.Get(6), objectIds[1]); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects["BBB"].Strings); Assert.Equal(IdentifierGenerator.Get(7), objectIds[0]); Assert.Equal(IdentifierGenerator.Get(8), objectIds[1]); Assert.Equal(2, obj.NonIdentifiableObjects.Count); Assert.Equal("ggg", obj.NonIdentifiableObjects["CCC"].Name); Assert.Equal(2, obj.NonIdentifiableObjects["CCC"].Strings.Count); Assert.Equal("hhh", obj.NonIdentifiableObjects["CCC"].Strings[0]); Assert.Equal("iii", obj.NonIdentifiableObjects["CCC"].Strings[1]); Assert.Equal("jjj", obj.NonIdentifiableObjects["DDD"].Name); Assert.Equal(2, obj.NonIdentifiableObjects["DDD"].Strings.Count); Assert.Equal("kkk", obj.NonIdentifiableObjects["DDD"].Strings[0]); Assert.Equal("lll", obj.NonIdentifiableObjects["DDD"].Strings[1]); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj.NonIdentifiableObjects, out objectIds)); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects); Assert.Equal(0, objectIds.KeyCount); Assert.Equal(0, objectIds.DeletedCount); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects["CCC"].Strings); Assert.Equal(IdentifierGenerator.Get(9), objectIds[0]); Assert.Equal(IdentifierGenerator.Get(10), objectIds[1]); objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.NonIdentifiableObjects["DDD"].Strings); Assert.Equal(IdentifierGenerator.Get(11), objectIds[0]); Assert.Equal(IdentifierGenerator.Get(12), objectIds[1]); }
public void TestDictionaryRemovedItemFromBase() { const string baseYaml = @"!SiliconStudio.Assets.Quantum.Tests.Types+MyAsset3,SiliconStudio.Assets.Quantum.Tests Id: 10000000-0000-0000-0000-000000000000 Tags: [] MyDictionary: 0a0000000a0000000a0000000a000000~Key1: String1 14000000140000001400000014000000~Key3: String3 "; const string derivedYaml = @"!SiliconStudio.Assets.Quantum.Tests.Types+MyAsset3,SiliconStudio.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 10000000-0000-0000-0000-000000000000:MyAsset Tags: [] MyDictionary: 0a0000000a0000000a0000000a000000~Key1: String1 24000000240000002400000024000000~Key2: String2 14000000140000001400000014000000~Key3: String3 "; var context = DeriveAssetTest <Types.MyAsset3> .LoadFromYaml(baseYaml, derivedYaml); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyDictionary); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyDictionary); Assert.AreEqual(2, context.BaseAsset.MyDictionary.Count); Assert.AreEqual("String1", context.BaseAsset.MyDictionary["Key1"]); Assert.AreEqual("String3", context.BaseAsset.MyDictionary["Key3"]); Assert.AreEqual(3, context.DerivedAsset.MyDictionary.Count); Assert.AreEqual("String1", context.DerivedAsset.MyDictionary["Key1"]); Assert.AreEqual("String2", context.DerivedAsset.MyDictionary["Key2"]); Assert.AreEqual("String3", context.DerivedAsset.MyDictionary["Key3"]); Assert.AreEqual(2, baseIds.KeyCount); Assert.AreEqual(0, baseIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), baseIds["Key1"]); Assert.AreEqual(IdentifierGenerator.Get(20), baseIds["Key3"]); Assert.AreEqual(3, derivedIds.KeyCount); Assert.AreEqual(0, derivedIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), derivedIds["Key1"]); Assert.AreEqual(IdentifierGenerator.Get(36), derivedIds["Key2"]); Assert.AreEqual(IdentifierGenerator.Get(20), derivedIds["Key3"]); context.DerivedGraph.ReconcileWithBase(); Assert.AreEqual(2, context.BaseAsset.MyDictionary.Count); Assert.AreEqual("String1", context.BaseAsset.MyDictionary["Key1"]); Assert.AreEqual("String3", context.BaseAsset.MyDictionary["Key3"]); Assert.AreEqual(2, context.DerivedAsset.MyDictionary.Count); Assert.AreEqual("String1", context.DerivedAsset.MyDictionary["Key1"]); Assert.AreEqual("String3", context.DerivedAsset.MyDictionary["Key3"]); Assert.AreEqual(2, baseIds.KeyCount); Assert.AreEqual(0, baseIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), baseIds["Key1"]); Assert.AreEqual(IdentifierGenerator.Get(20), baseIds["Key3"]); Assert.AreEqual(2, derivedIds.KeyCount); Assert.AreEqual(0, derivedIds.DeletedCount); Assert.AreEqual(IdentifierGenerator.Get(10), derivedIds["Key1"]); Assert.AreEqual(IdentifierGenerator.Get(20), derivedIds["Key3"]); }
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 override void VisitDictionary(object dictionary, DictionaryDescriptor descriptor) { if (ShouldGenerateItemIdCollection(dictionary)) { var itemIds = CollectionItemIdHelper.GetCollectionItemIds(dictionary); foreach (var element in descriptor.GetEnumerator(dictionary)) { itemIds.Add(element.Key, ItemId.New()); } } }
public override void VisitArray(Array array, ArrayDescriptor descriptor) { if (ShouldGenerateItemIdCollection(array)) { var itemIds = CollectionItemIdHelper.GetCollectionItemIds(array); for (var i = 0; i < array.Length; ++i) { itemIds.Add(i, ItemId.New()); } } base.VisitArray(array, descriptor); }
public void TestDictionaryKeyCollision() { const string baseYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAsset3,Stride.Core.Assets.Quantum.Tests Id: 10000000-0000-0000-0000-000000000000 Tags: [] MyDictionary: 0a0000000a0000000a0000000a000000~Key1: String1 14000000140000001400000014000000~Key2: String2 "; const string derivedYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAsset3,Stride.Core.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 10000000-0000-0000-0000-000000000000:MyAsset Tags: [] MyDictionary: 0a0000000a0000000a0000000a000000~Key1: String1 15000000150000001500000015000000*~Key2: String3 "; var context = DeriveAssetTest <Types.MyAsset3, Types.MyAssetBasePropertyGraph> .LoadFromYaml(baseYaml, derivedYaml); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyDictionary); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyDictionary); Assert.Equal(2, context.BaseAsset.MyDictionary.Count); Assert.Equal("String1", context.BaseAsset.MyDictionary["Key1"]); Assert.Equal("String2", context.BaseAsset.MyDictionary["Key2"]); Assert.Equal(2, context.DerivedAsset.MyDictionary.Count); Assert.Equal("String1", context.DerivedAsset.MyDictionary["Key1"]); Assert.Equal("String3", context.DerivedAsset.MyDictionary["Key2"]); Assert.Equal(2, baseIds.KeyCount); Assert.Equal(0, baseIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), baseIds["Key1"]); Assert.Equal(IdentifierGenerator.Get(20), baseIds["Key2"]); Assert.Equal(2, derivedIds.KeyCount); Assert.Equal(0, derivedIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), derivedIds["Key1"]); Assert.Equal(IdentifierGenerator.Get(21), derivedIds["Key2"]); context.DerivedGraph.ReconcileWithBase(); Assert.Equal(2, context.BaseAsset.MyDictionary.Count); Assert.Equal("String1", context.BaseAsset.MyDictionary["Key1"]); Assert.Equal("String2", context.BaseAsset.MyDictionary["Key2"]); Assert.Equal(2, context.DerivedAsset.MyDictionary.Count); Assert.Equal("String1", context.DerivedAsset.MyDictionary["Key1"]); Assert.Equal("String3", context.DerivedAsset.MyDictionary["Key2"]); Assert.Equal(2, baseIds.KeyCount); Assert.Equal(0, baseIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), baseIds["Key1"]); Assert.Equal(IdentifierGenerator.Get(20), baseIds["Key2"]); Assert.Equal(2, derivedIds.KeyCount); Assert.Equal(1, derivedIds.DeletedCount); Assert.Equal(IdentifierGenerator.Get(10), derivedIds["Key1"]); Assert.Equal(IdentifierGenerator.Get(21), derivedIds["Key2"]); Assert.Equal(IdentifierGenerator.Get(20), derivedIds.DeletedItems.Single()); }
public void TestCollectionDeserializationOldWay() { ShadowObject.Enable = true; var yaml = @"!SiliconStudio.Assets.Tests.Yaml.TestCollectionIdsSerialization+ContainerCollection,SiliconStudio.Assets.Tests Name: Root Strings: - aaa - bbb Objects: - ~Id: 00000004-0004-0000-0400-000004000000 Name: obj1 Strings: {} Objects: {} - ~Id: 00000003-0003-0000-0300-000003000000 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(ContainerCollection), instance.GetType()); var obj = (ContainerCollection)instance; Assert.AreEqual("Root", obj.Name); Assert.AreEqual(2, obj.Strings.Count); Assert.AreEqual("aaa", obj.Strings[0]); Assert.AreEqual("bbb", obj.Strings[1]); Assert.AreEqual(2, obj.Objects.Count); Assert.AreEqual("obj1", obj.Objects[0].Name); Assert.AreEqual("obj2", obj.Objects[1].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(0)); Assert.IsTrue(stringIds.ContainsKey(1)); Assert.AreEqual(2, objectIds.KeyCount); Assert.AreEqual(0, objectIds.DeletedCount); Assert.IsTrue(objectIds.ContainsKey(0)); Assert.IsTrue(objectIds.ContainsKey(1)); Assert.AreEqual(new ItemId(GuidGenerator.Get(4).ToByteArray()), objectIds[0]); Assert.AreEqual(new ItemId(GuidGenerator.Get(3).ToByteArray()), objectIds[1]); }
public override void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor) { if (ShouldGenerateItemIdCollection(collection)) { var itemIds = CollectionItemIdHelper.GetCollectionItemIds(collection); var count = descriptor.GetCollectionCount(collection); for (var i = 0; i < count; ++i) { itemIds.Add(i, ItemId.New()); } } base.VisitCollection(collection, descriptor); }
public override void VisitSet(IEnumerable set, SetDescriptor descriptor) { if (ShouldGenerateItemIdCollection(set)) { IEnumerator enumerator = (set as IEnumerable).GetEnumerator(); var itemIds = CollectionItemIdHelper.GetCollectionItemIds(set); while (enumerator.MoveNext()) { itemIds.Add(enumerator.Current, ItemId.New()); } } base.VisitSet(set, descriptor); }
public void TestRemoveBaseAddDerivedWithSubDerived() { var asset = new Types.MyAsset2 { MyStrings = { "String1", "String2" } }; var context = DeriveAssetTest <Types.MyAsset2, Types.MyAssetBasePropertyGraph> .DeriveAsset(asset); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyStrings); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyStrings); var subDerivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.SubDerivedAsset.MyStrings); var basePropertyNode = context.BaseGraph.RootNode[nameof(Types.MyAsset2.MyStrings)]; var derivedPropertyNode = context.DerivedGraph.RootNode[nameof(Types.MyAsset2.MyStrings)]; var subDerivedPropertyNode = context.SubDerivedGraph.RootNode[nameof(Types.MyAsset2.MyStrings)]; // Delete an item from the derived and then update the same from the base var derivedDeletedId = derivedIds[1]; derivedPropertyNode.Target.Remove("String2", new NodeIndex(1)); basePropertyNode.Target.Add("String3"); Assert.Equal(3, context.BaseAsset.MyStrings.Count); Assert.Equal(2, context.DerivedAsset.MyStrings.Count); Assert.Equal(2, context.SubDerivedAsset.MyStrings.Count); Assert.Equal("String1", basePropertyNode.Retrieve(new NodeIndex(0))); Assert.Equal("String2", basePropertyNode.Retrieve(new NodeIndex(1))); Assert.Equal("String3", basePropertyNode.Retrieve(new NodeIndex(2))); Assert.Equal("String1", derivedPropertyNode.Retrieve(new NodeIndex(0))); Assert.Equal("String3", derivedPropertyNode.Retrieve(new NodeIndex(1))); Assert.Equal("String1", subDerivedPropertyNode.Retrieve(new NodeIndex(0))); Assert.Equal("String3", subDerivedPropertyNode.Retrieve(new NodeIndex(1))); Assert.Equal(OverrideType.Base, basePropertyNode.GetContentOverride()); Assert.Equal(OverrideType.Base, basePropertyNode.Target.GetItemOverride(new NodeIndex(0))); Assert.Equal(OverrideType.Base, basePropertyNode.Target.GetItemOverride(new NodeIndex(1))); Assert.Equal(OverrideType.Base, basePropertyNode.Target.GetItemOverride(new NodeIndex(2))); Assert.Equal(OverrideType.Base, derivedPropertyNode.GetContentOverride()); Assert.Equal(OverrideType.Base, derivedPropertyNode.Target.GetItemOverride(new NodeIndex(0))); Assert.Equal(OverrideType.Base, derivedPropertyNode.Target.GetItemOverride(new NodeIndex(1))); Assert.Equal(OverrideType.Base, subDerivedPropertyNode.GetContentOverride()); Assert.Equal(OverrideType.Base, subDerivedPropertyNode.Target.GetItemOverride(new NodeIndex(0))); Assert.Equal(OverrideType.Base, subDerivedPropertyNode.Target.GetItemOverride(new NodeIndex(1))); Assert.Equal(3, baseIds.KeyCount); Assert.Equal(0, baseIds.DeletedCount); Assert.Equal(2, derivedIds.KeyCount); Assert.Equal(1, derivedIds.DeletedCount); Assert.Equal(2, subDerivedIds.KeyCount); Assert.Equal(0, subDerivedIds.DeletedCount); Assert.Equal(baseIds[0], derivedIds[0]); Assert.Equal(baseIds[2], derivedIds[1]); Assert.Equal(derivedIds[0], subDerivedIds[0]); Assert.Equal(derivedIds[1], subDerivedIds[1]); Assert.True(derivedIds.IsDeleted(derivedDeletedId)); }
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 override void VisitArray(Array array, ArrayDescriptor descriptor) { CollectionItemIdentifiers itemIds; if (inNonIdentifiableType == 0 && !CollectionItemIdHelper.TryGetCollectionItemIds(array, out itemIds)) { itemIds = CollectionItemIdHelper.GetCollectionItemIds(array); for (var i = 0; i < array.Length; ++i) { itemIds.Add(i, ItemId.New()); } } base.VisitArray(array, descriptor); }
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 override void VisitDictionary(object dictionary, DictionaryDescriptor descriptor) { CollectionItemIdentifiers itemIds; if (inNonIdentifiableType == 0 && !CollectionItemIdHelper.TryGetCollectionItemIds(dictionary, out itemIds)) { itemIds = CollectionItemIdHelper.GetCollectionItemIds(dictionary); foreach (var element in descriptor.GetEnumerator(dictionary)) { itemIds.Add(element.Key, ItemId.New()); } } base.VisitDictionary(dictionary, descriptor); }
public override void VisitCollection(IEnumerable collection, CollectionDescriptor descriptor) { CollectionItemIdentifiers itemIds; if (inNonIdentifiableType == 0 && !CollectionItemIdHelper.TryGetCollectionItemIds(collection, out itemIds)) { itemIds = CollectionItemIdHelper.GetCollectionItemIds(collection); var count = descriptor.GetCollectionCount(collection); for (var i = 0; i < count; ++i) { itemIds.Add(i, ItemId.New()); } } base.VisitCollection(collection, descriptor); }
public void TestSimpleDictionaryRemoveDeleted() { var asset = new Types.MyAsset3 { MyDictionary = { { "Key1", "String1" }, { "Key2", "String2" }, { "Key3", "String3" }, { "Key4", "String4" } } }; var context = DeriveAssetTest <Types.MyAsset3> .DeriveAsset(asset); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyDictionary); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyDictionary); var basePropertyNode = (AssetNode)((IGraphNode)context.BaseGraph.RootNode).TryGetChild(nameof(Types.MyAsset3.MyDictionary)); var derivedPropertyNode = (AssetNode)((IGraphNode)context.DerivedGraph.RootNode).TryGetChild(nameof(Types.MyAsset3.MyDictionary)); // Delete an item from the derived and then delete the same from the base var derivedDeletedId = derivedIds["Key3"]; derivedPropertyNode.Content.Remove("String3", new Index("Key3")); var baseDeletedId = baseIds["Key3"]; basePropertyNode.Content.Remove("String3", new Index("Key3")); Assert.AreEqual(3, context.BaseAsset.MyDictionary.Count); Assert.AreEqual(3, context.DerivedAsset.MyDictionary.Count); Assert.AreEqual("String1", basePropertyNode.Content.Retrieve(new Index("Key1"))); Assert.AreEqual("String2", basePropertyNode.Content.Retrieve(new Index("Key2"))); Assert.AreEqual("String4", basePropertyNode.Content.Retrieve(new Index("Key4"))); Assert.AreEqual("String1", derivedPropertyNode.Content.Retrieve(new Index("Key1"))); Assert.AreEqual("String2", derivedPropertyNode.Content.Retrieve(new Index("Key2"))); Assert.AreEqual("String4", derivedPropertyNode.Content.Retrieve(new Index("Key4"))); Assert.AreEqual(OverrideType.Base, basePropertyNode.GetContentOverride()); Assert.AreEqual(OverrideType.Base, basePropertyNode.GetItemOverride(new Index("Key1"))); Assert.AreEqual(OverrideType.Base, basePropertyNode.GetItemOverride(new Index("Key2"))); Assert.AreEqual(OverrideType.Base, basePropertyNode.GetItemOverride(new Index("Key4"))); Assert.AreEqual(OverrideType.Base, derivedPropertyNode.GetContentOverride()); Assert.AreEqual(OverrideType.Base, derivedPropertyNode.GetItemOverride(new Index("Key1"))); Assert.AreEqual(OverrideType.Base, derivedPropertyNode.GetItemOverride(new Index("Key2"))); Assert.AreEqual(OverrideType.Base, derivedPropertyNode.GetItemOverride(new Index("Key4"))); Assert.AreEqual(3, baseIds.Count); Assert.AreEqual(3, baseIds.KeyCount); Assert.AreEqual(0, baseIds.DeletedCount); Assert.AreEqual(3, derivedIds.Count); Assert.AreEqual(3, derivedIds.KeyCount); Assert.AreEqual(0, derivedIds.DeletedCount); Assert.AreEqual(baseIds["Key1"], derivedIds["Key1"]); Assert.AreEqual(baseIds["Key2"], derivedIds["Key2"]); Assert.AreEqual(baseIds["Key4"], derivedIds["Key4"]); Assert.False(derivedIds.IsDeleted(derivedDeletedId)); Assert.False(baseIds.IsDeleted(baseDeletedId)); }
public void TestSimpleCollectionRemoveDeleted() { var asset = new Types.MyAsset2 { MyStrings = { "String1", "String2", "String3", "String4" } }; var context = DeriveAssetTest <Types.MyAsset2> .DeriveAsset(asset); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyStrings); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyStrings); var basePropertyNode = (AssetNode)((IGraphNode)context.BaseGraph.RootNode).TryGetChild(nameof(Types.MyAsset2.MyStrings)); var derivedPropertyNode = (AssetNode)((IGraphNode)context.DerivedGraph.RootNode).TryGetChild(nameof(Types.MyAsset2.MyStrings)); // Delete an item from the derived and then delete the same from the base var derivedDeletedId = derivedIds[2]; var baseDeletedId = baseIds[2]; derivedPropertyNode.Content.Remove("String3", new Index(2)); basePropertyNode.Content.Remove("String3", new Index(2)); Assert.AreEqual(3, context.BaseAsset.MyStrings.Count); Assert.AreEqual(3, context.DerivedAsset.MyStrings.Count); Assert.AreEqual("String1", basePropertyNode.Content.Retrieve(new Index(0))); Assert.AreEqual("String2", basePropertyNode.Content.Retrieve(new Index(1))); Assert.AreEqual("String4", basePropertyNode.Content.Retrieve(new Index(2))); Assert.AreEqual("String1", derivedPropertyNode.Content.Retrieve(new Index(0))); Assert.AreEqual("String2", derivedPropertyNode.Content.Retrieve(new Index(1))); Assert.AreEqual("String4", derivedPropertyNode.Content.Retrieve(new Index(2))); Assert.AreEqual(OverrideType.Base, basePropertyNode.GetContentOverride()); Assert.AreEqual(OverrideType.Base, basePropertyNode.GetItemOverride(new Index(0))); Assert.AreEqual(OverrideType.Base, basePropertyNode.GetItemOverride(new Index(1))); Assert.AreEqual(OverrideType.Base, basePropertyNode.GetItemOverride(new Index(2))); Assert.AreEqual(OverrideType.Base, derivedPropertyNode.GetContentOverride()); Assert.AreEqual(OverrideType.Base, derivedPropertyNode.GetItemOverride(new Index(0))); Assert.AreEqual(OverrideType.Base, derivedPropertyNode.GetItemOverride(new Index(1))); Assert.AreEqual(OverrideType.Base, derivedPropertyNode.GetItemOverride(new Index(2))); Assert.AreEqual(3, baseIds.Count); Assert.AreEqual(3, baseIds.KeyCount); Assert.AreEqual(0, baseIds.DeletedCount); Assert.AreEqual(3, derivedIds.Count); Assert.AreEqual(3, derivedIds.KeyCount); Assert.AreEqual(0, derivedIds.DeletedCount); Assert.AreEqual(baseIds[0], derivedIds[0]); Assert.AreEqual(baseIds[1], derivedIds[1]); Assert.AreEqual(baseIds[2], derivedIds[2]); Assert.False(derivedIds.IsDeleted(derivedDeletedId)); Assert.False(baseIds.IsDeleted(baseDeletedId)); }
public void TestSimpleDictionaryUpdateDeleted() { var asset = new Types.MyAsset3 { MyDictionary = { { "Key1", "String1" }, { "Key2", "String2" }, { "Key3", "String3" }, { "Key4", "String4" } } }; var context = DeriveAssetTest <Types.MyAsset3, Types.MyAssetBasePropertyGraph> .DeriveAsset(asset); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyDictionary); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyDictionary); var basePropertyNode = context.BaseGraph.RootNode[nameof(Types.MyAsset3.MyDictionary)]; var derivedPropertyNode = context.DerivedGraph.RootNode[nameof(Types.MyAsset3.MyDictionary)]; // Delete an item from the derived and then update the same from the base var derivedDeletedId = derivedIds["Key3"]; derivedPropertyNode.Target.Remove("String3", new NodeIndex("Key3")); basePropertyNode.Target.Update("String3.5", new NodeIndex("Key3")); Assert.Equal(4, context.BaseAsset.MyDictionary.Count); Assert.Equal(3, context.DerivedAsset.MyDictionary.Count); Assert.Equal("String1", basePropertyNode.Retrieve(new NodeIndex("Key1"))); Assert.Equal("String2", basePropertyNode.Retrieve(new NodeIndex("Key2"))); Assert.Equal("String3.5", basePropertyNode.Retrieve(new NodeIndex("Key3"))); Assert.Equal("String4", basePropertyNode.Retrieve(new NodeIndex("Key4"))); Assert.Equal("String1", derivedPropertyNode.Retrieve(new NodeIndex("Key1"))); Assert.Equal("String2", derivedPropertyNode.Retrieve(new NodeIndex("Key2"))); Assert.Equal("String4", derivedPropertyNode.Retrieve(new NodeIndex("Key4"))); Assert.Equal(OverrideType.Base, basePropertyNode.GetContentOverride()); Assert.Equal(OverrideType.Base, basePropertyNode.Target.GetItemOverride(new NodeIndex("Key1"))); Assert.Equal(OverrideType.Base, basePropertyNode.Target.GetItemOverride(new NodeIndex("Key2"))); Assert.Equal(OverrideType.Base, basePropertyNode.Target.GetItemOverride(new NodeIndex("Key3"))); Assert.Equal(OverrideType.Base, basePropertyNode.Target.GetItemOverride(new NodeIndex("Key4"))); Assert.Equal(OverrideType.Base, derivedPropertyNode.GetContentOverride()); Assert.Equal(OverrideType.Base, derivedPropertyNode.Target.GetItemOverride(new NodeIndex("Key1"))); Assert.Equal(OverrideType.Base, derivedPropertyNode.Target.GetItemOverride(new NodeIndex("Key2"))); Assert.Equal(OverrideType.Base, derivedPropertyNode.Target.GetItemOverride(new NodeIndex("Key4"))); Assert.Equal(4, baseIds.KeyCount); Assert.Equal(0, baseIds.DeletedCount); Assert.Equal(3, derivedIds.KeyCount); Assert.Equal(1, derivedIds.DeletedCount); Assert.Equal(baseIds["Key1"], derivedIds["Key1"]); Assert.Equal(baseIds["Key2"], derivedIds["Key2"]); Assert.Equal(baseIds["Key4"], derivedIds["Key4"]); Assert.True(derivedIds.IsDeleted(derivedDeletedId)); }
public void TestSimpleDictionaryAddWithCollision() { var asset = new Types.MyAsset3 { MyDictionary = { { "Key1", "String1" }, { "Key2", "String2" } } }; var context = DeriveAssetTest <Types.MyAsset3, Types.MyAssetBasePropertyGraph> .DeriveAsset(asset); var baseIds = CollectionItemIdHelper.GetCollectionItemIds(context.BaseAsset.MyDictionary); var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyDictionary); var basePropertyNode = context.BaseGraph.RootNode[nameof(Types.MyAsset3.MyDictionary)]; var derivedPropertyNode = context.DerivedGraph.RootNode[nameof(Types.MyAsset3.MyDictionary)]; // Update a key to derived and then the same key to the base derivedPropertyNode.Target.Add("String3", new NodeIndex("Key3")); basePropertyNode.Target.Add("String4", new NodeIndex("Key3")); Assert.Equal(3, context.BaseAsset.MyDictionary.Count); Assert.Equal(3, context.DerivedAsset.MyDictionary.Count); Assert.Equal("String1", basePropertyNode.Retrieve(new NodeIndex("Key1"))); Assert.Equal("String2", basePropertyNode.Retrieve(new NodeIndex("Key2"))); Assert.Equal("String4", basePropertyNode.Retrieve(new NodeIndex("Key3"))); Assert.Equal("String1", derivedPropertyNode.Retrieve(new NodeIndex("Key1"))); Assert.Equal("String2", derivedPropertyNode.Retrieve(new NodeIndex("Key2"))); Assert.Equal("String3", derivedPropertyNode.Retrieve(new NodeIndex("Key3"))); Assert.Equal(OverrideType.Base, basePropertyNode.GetContentOverride()); Assert.Equal(OverrideType.Base, basePropertyNode.Target.GetItemOverride(new NodeIndex("Key1"))); Assert.Equal(OverrideType.Base, basePropertyNode.Target.GetItemOverride(new NodeIndex("Key2"))); Assert.Equal(OverrideType.Base, basePropertyNode.Target.GetItemOverride(new NodeIndex("Key3"))); Assert.Equal(OverrideType.Base, derivedPropertyNode.GetContentOverride()); Assert.Equal(OverrideType.Base, derivedPropertyNode.Target.GetItemOverride(new NodeIndex("Key1"))); Assert.Equal(OverrideType.Base, derivedPropertyNode.Target.GetItemOverride(new NodeIndex("Key2"))); Assert.Equal(OverrideType.New, derivedPropertyNode.Target.GetItemOverride(new NodeIndex("Key3"))); Assert.NotEqual(baseIds, derivedIds); Assert.Equal(3, baseIds.KeyCount); Assert.Equal(0, baseIds.DeletedCount); Assert.Equal(3, derivedIds.KeyCount); Assert.Equal(1, derivedIds.DeletedCount); Assert.Equal(baseIds["Key1"], derivedIds["Key1"]); Assert.Equal(baseIds["Key2"], derivedIds["Key2"]); Assert.NotEqual(baseIds["Key3"], derivedIds["Key3"]); Assert.Equal(baseIds["Key3"], derivedIds.DeletedItems.Single()); Assert.Equal(3, context.BaseAsset.MyDictionary.Count); Assert.Equal(3, context.DerivedAsset.MyDictionary.Count); }
/// <inheritdoc/> protected override void TransformObjectAfterRead(ref ObjectContext objectContext) { if (!AreCollectionItemsIdentifiable(ref objectContext)) { base.TransformObjectAfterRead(ref objectContext); return; } var info = (InstanceInfo)objectContext.Properties[InstanceInfoKey]; // This is to be backward compatible with previous serialization. We fetch ids from the ~Id member of each item if (info.Instance != null) { ICollection <ItemId> deletedItems; objectContext.Properties.TryGetValue(DeletedItemsKey, out deletedItems); TransformAfterDeserialization((IDictionary)objectContext.Instance, info.Descriptor, info.Instance, deletedItems); } objectContext.Instance = info.Instance; var enumerable = objectContext.Instance as IEnumerable; if (enumerable != null) { var ids = CollectionItemIdHelper.GetCollectionItemIds(objectContext.Instance); var descriptor = (DictionaryDescriptor)info.Descriptor; foreach (var item in descriptor.GetEnumerator(objectContext.Instance)) { ItemId id; if (ids.TryGet(item.Key, out id) && id != ItemId.Empty) { continue; } var guid = item.Value != null?IdentifiableHelper.GetId(item.Value) : Guid.NewGuid(); ids[item.Key] = guid != Guid.Empty ? new ItemId(guid.ToByteArray()) : ItemId.New(); } } base.TransformObjectAfterRead(ref objectContext); }
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.Equal(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.Equal(YamlCollection, 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.Equal(typeof(ContainerDictionary), instance.GetType()); var obj = (ContainerDictionary)instance; Assert.Equal("Root", obj.Name); Assert.Equal(2, obj.Strings.Count); Assert.Equal("aaa", obj.Strings[GuidGenerator.Get(200)]); Assert.Equal("bbb", obj.Strings[GuidGenerator.Get(100)]); Assert.Equal(2, obj.Objects.Count); Assert.Equal("obj1", obj.Objects["key3"].Name); Assert.Equal("obj2", obj.Objects["key4"].Name); var stringIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Strings); Assert.Equal(IdentifierGenerator.Get(8), stringIds[GuidGenerator.Get(200)]); Assert.Equal(IdentifierGenerator.Get(5), stringIds[GuidGenerator.Get(100)]); var objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); Assert.Equal(IdentifierGenerator.Get(3), objectIds["key3"]); Assert.Equal(IdentifierGenerator.Get(4), objectIds["key4"]); var deletedItems = stringIds.DeletedItems.ToList(); Assert.Equal(2, deletedItems.Count); Assert.Equal(IdentifierGenerator.Get(1), deletedItems[0]); Assert.Equal(IdentifierGenerator.Get(3), deletedItems[1]); deletedItems = objectIds.DeletedItems.ToList(); Assert.Equal(2, deletedItems.Count); Assert.Equal(IdentifierGenerator.Get(1), deletedItems[0]); Assert.Equal(IdentifierGenerator.Get(6), deletedItems[1]); }
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.Equal(YamlDictionaryNonIdentifiable, yaml); }
private void OnObjectDeserialized(int i, object newObject) { if (objectReferences != null && newObject != null) { var previousObject = objectReferences[i]; //// If the object is an attached reference, there is no need to copy the shadow object //if (AttachedReferenceManager.GetAttachedReference(previousObject) != null) //{ // return; //} ShadowObject.Copy(previousObject, newObject); // NOTE: we don't use Add because of strings that might be duplicated clonedObjectMapping[previousObject] = newObject; if ((flags & AssetClonerFlags.RemoveItemIds) != AssetClonerFlags.RemoveItemIds) { CollectionItemIdentifiers sourceIds; if (CollectionItemIdHelper.TryGetCollectionItemIds(previousObject, out sourceIds)) { var newIds = CollectionItemIdHelper.GetCollectionItemIds(newObject); sourceIds.CloneInto(newIds, clonedObjectMapping); } } if ((flags & AssetClonerFlags.GenerateNewIdsForIdentifiableObjects) == AssetClonerFlags.GenerateNewIdsForIdentifiableObjects) { var identifiable = newObject as IIdentifiable; if (identifiable != null) { cloningIdRemapping = cloningIdRemapping ?? new Dictionary <Guid, Guid>(); var newId = Guid.NewGuid(); cloningIdRemapping[identifiable.Id] = newId; identifiable.Id = newId; } } } }
public void TestSimpleSerialization() { var asset = new MyAsset { Strings = { "aa", "bb" } }; var asset1Ids = CollectionItemIdHelper.GetCollectionItemIds(asset.Strings); asset1Ids.Add(0, new ItemId(MakeArray(1))); asset1Ids.Add(1, new ItemId(MakeArray(2))); var serializer = new YamlAssetSerializer(); var stream = new MemoryStream(); serializer.Save(stream, asset, null); stream.Position = 0; bool aliasOccurred; AttachedYamlAssetMetadata metadata; var loadedAsset = (MyAsset)serializer.Load(stream, null, null, true, out aliasOccurred, out metadata); var asset2Ids = CollectionItemIdHelper.GetCollectionItemIds(loadedAsset.Strings); Assert.Equal(2, asset2Ids.KeyCount); Assert.Equal(asset1Ids[0], asset2Ids[0]); Assert.Equal(asset1Ids[1], asset2Ids[1]); }
public void TestSimpleSerialization() { var asset = new MyAsset { Strings = { "aa", "bb" } }; var asset1Ids = CollectionItemIdHelper.GetCollectionItemIds(asset.Strings); asset1Ids.Add(0, new ItemId(MakeArray(1))); asset1Ids.Add(1, new ItemId(MakeArray(2))); var serializer = new YamlAssetSerializer(); var stream = new MemoryStream(); serializer.Save(stream, asset); stream.Position = 0; bool aliasOccurred; Dictionary <YamlAssetPath, OverrideType> overrides; var loadedAsset = (MyAsset)serializer.Load(stream, null, null, out aliasOccurred, out overrides); var asset2Ids = CollectionItemIdHelper.GetCollectionItemIds(loadedAsset.Strings); Assert.AreEqual(2, asset2Ids.KeyCount); Assert.AreEqual(asset1Ids[0], asset2Ids[0]); Assert.AreEqual(asset1Ids[1], asset2Ids[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); }