public static TestArchetypesRun PrepareObjectCollectionUpdate()
        {
            var asset = new Types.MyAsset4 { MyObjects = { new Types.SomeObject { Value = "String1" }, new Types.SomeObject { Value = "String2" } } };
            var context = DeriveAssetTest<Types.MyAsset4>.DeriveAsset(asset);
            var baseIds = CollectionItemIdHelper.GetCollectionItemIds(asset.MyObjects);
            var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyObjects);
            var basePropertyNode = (AssetNode)((IGraphNode)context.BaseGraph.RootNode).TryGetChild(nameof(Types.MyAsset4.MyObjects));
            var derivedPropertyNode = (AssetNode)((IGraphNode)context.DerivedGraph.RootNode).TryGetChild(nameof(Types.MyAsset4.MyObjects));

            var objB0 = asset.MyObjects[0];
            var objB1 = asset.MyObjects[1];
            var objD0 = context.DerivedAsset.MyObjects[0];
            var objD1 = context.DerivedAsset.MyObjects[1];
            var newObjB = new Types.SomeObject { Value = "MyBaseString" };
            var newObjD = new Types.SomeObject { Value = "MyDerivedString" };

            var test = new TestArchetypesRun(context)
            {
                InitialCheck = () =>
                {
                    Assert.AreEqual(2, context.BaseAsset.MyObjects.Count);
                    Assert.AreEqual(2, context.DerivedAsset.MyObjects.Count);
                    Assert.AreEqual(objB0, basePropertyNode.Content.Retrieve(new Index(0)));
                    Assert.AreEqual(objB1, basePropertyNode.Content.Retrieve(new Index(1)));
                    Assert.AreEqual(objD0, derivedPropertyNode.Content.Retrieve(new Index(0)));
                    Assert.AreEqual(objD1, derivedPropertyNode.Content.Retrieve(new Index(1)));
                    Assert.AreEqual("String1", ((Types.SomeObject)basePropertyNode.Content.Retrieve(new Index(0))).Value);
                    Assert.AreEqual("String2", ((Types.SomeObject)basePropertyNode.Content.Retrieve(new Index(1))).Value);
                    Assert.AreEqual("String1", ((Types.SomeObject)derivedPropertyNode.Content.Retrieve(new Index(0))).Value);
                    Assert.AreEqual("String2", ((Types.SomeObject)derivedPropertyNode.Content.Retrieve(new Index(1))).Value);
                    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, ((AssetNode)basePropertyNode.Content.Reference.AsEnumerable[new Index(0)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    Assert.AreEqual(OverrideType.Base, ((AssetNode)basePropertyNode.Content.Reference.AsEnumerable[new Index(1)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    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, ((AssetNode)derivedPropertyNode.Content.Reference.AsEnumerable[new Index(0)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    Assert.AreEqual(OverrideType.Base, ((AssetNode)derivedPropertyNode.Content.Reference.AsEnumerable[new Index(1)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    Assert.AreEqual(0, derivedPropertyNode.GetOverriddenItemIndices().Count());
                    Assert.AreEqual(0, derivedPropertyNode.GetOverriddenKeyIndices().Count());
                    Assert.AreNotSame(baseIds, derivedIds);
                    Assert.AreEqual(2, baseIds.KeyCount);
                    Assert.AreEqual(0, baseIds.DeletedCount);
                    Assert.AreEqual(2, derivedIds.KeyCount);
                    Assert.AreEqual(0, derivedIds.DeletedCount);
                    Assert.AreEqual(baseIds[0], derivedIds[0]);
                    Assert.AreEqual(baseIds[1], derivedIds[1]);
                },
                FirstChange = () =>
                {
                    basePropertyNode.Content.Update(newObjB, new Index(1));
                },
                FirstChangeCheck = () =>
                {
                    Assert.AreEqual(2, context.BaseAsset.MyObjects.Count);
                    Assert.AreEqual(2, context.DerivedAsset.MyObjects.Count);
                    Assert.AreEqual(objB0, basePropertyNode.Content.Retrieve(new Index(0)));
                    Assert.AreEqual(newObjB, basePropertyNode.Content.Retrieve(new Index(1)));
                    Assert.AreEqual(objD0, derivedPropertyNode.Content.Retrieve(new Index(0)));
                    Assert.AreEqual(objD1, derivedPropertyNode.Content.Retrieve(new Index(1)));
                    Assert.AreEqual("String1", ((Types.SomeObject)basePropertyNode.Content.Retrieve(new Index(0))).Value);
                    Assert.AreEqual("MyBaseString", ((Types.SomeObject)basePropertyNode.Content.Retrieve(new Index(1))).Value);
                    Assert.AreEqual("String1", ((Types.SomeObject)derivedPropertyNode.Content.Retrieve(new Index(0))).Value);
                    Assert.AreEqual("MyBaseString", ((Types.SomeObject)derivedPropertyNode.Content.Retrieve(new Index(1))).Value);
                    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, ((AssetNode)basePropertyNode.Content.Reference.AsEnumerable[new Index(0)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    Assert.AreEqual(OverrideType.Base, ((AssetNode)basePropertyNode.Content.Reference.AsEnumerable[new Index(1)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    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, ((AssetNode)derivedPropertyNode.Content.Reference.AsEnumerable[new Index(0)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    Assert.AreEqual(OverrideType.Base, ((AssetNode)derivedPropertyNode.Content.Reference.AsEnumerable[new Index(1)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    Assert.AreEqual(0, derivedPropertyNode.GetOverriddenItemIndices().Count());
                    Assert.AreEqual(0, derivedPropertyNode.GetOverriddenKeyIndices().Count());
                    Assert.AreNotSame(baseIds, derivedIds);
                    Assert.AreEqual(2, baseIds.KeyCount);
                    Assert.AreEqual(0, baseIds.DeletedCount);
                    Assert.AreEqual(2, derivedIds.KeyCount);
                    Assert.AreEqual(0, derivedIds.DeletedCount);
                    Assert.AreEqual(baseIds[0], derivedIds[0]);
                    Assert.AreEqual(baseIds[1], derivedIds[1]);
                },
                SecondChange = () =>
                {
                    derivedPropertyNode.Content.Update(newObjD, new Index(0));
                },
                SecondChangeCheck = () =>
                {
                    Assert.AreEqual(2, context.BaseAsset.MyObjects.Count);
                    Assert.AreEqual(2, context.DerivedAsset.MyObjects.Count);
                    Assert.AreEqual(objB0, basePropertyNode.Content.Retrieve(new Index(0)));
                    Assert.AreEqual(newObjB, basePropertyNode.Content.Retrieve(new Index(1)));
                    Assert.AreEqual(newObjD, derivedPropertyNode.Content.Retrieve(new Index(0)));
                    Assert.AreEqual(objD1, derivedPropertyNode.Content.Retrieve(new Index(1)));
                    Assert.AreEqual("String1", ((Types.SomeObject)basePropertyNode.Content.Retrieve(new Index(0))).Value);
                    Assert.AreEqual("MyBaseString", ((Types.SomeObject)basePropertyNode.Content.Retrieve(new Index(1))).Value);
                    Assert.AreEqual("MyDerivedString", ((Types.SomeObject)derivedPropertyNode.Content.Retrieve(new Index(0))).Value);
                    Assert.AreEqual("MyBaseString", ((Types.SomeObject)derivedPropertyNode.Content.Retrieve(new Index(1))).Value);
                    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, ((AssetNode)basePropertyNode.Content.Reference.AsEnumerable[new Index(0)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    Assert.AreEqual(OverrideType.Base, ((AssetNode)basePropertyNode.Content.Reference.AsEnumerable[new Index(1)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    Assert.AreEqual(OverrideType.Base, derivedPropertyNode.GetContentOverride());
                    Assert.AreEqual(OverrideType.New, derivedPropertyNode.GetItemOverride(new Index(0)));
                    Assert.AreEqual(OverrideType.Base, derivedPropertyNode.GetItemOverride(new Index(1)));
                    Assert.AreEqual(OverrideType.Base, ((AssetNode)derivedPropertyNode.Content.Reference.AsEnumerable[new Index(0)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    Assert.AreEqual(OverrideType.Base, ((AssetNode)derivedPropertyNode.Content.Reference.AsEnumerable[new Index(1)].TargetNode.TryGetChild(nameof(Types.SomeObject.Value))).GetContentOverride());
                    Assert.AreEqual(1, derivedPropertyNode.GetOverriddenItemIndices().Count());
                    Assert.AreEqual(0, derivedPropertyNode.GetOverriddenKeyIndices().Count());
                    Assert.AreNotSame(baseIds, derivedIds);
                    Assert.AreEqual(2, baseIds.KeyCount);
                    Assert.AreEqual(0, baseIds.DeletedCount);
                    Assert.AreEqual(2, derivedIds.KeyCount);
                    Assert.AreEqual(0, derivedIds.DeletedCount);
                    Assert.AreEqual(baseIds[0], derivedIds[0]);
                    Assert.AreEqual(baseIds[1], derivedIds[1]);
                }
            };
            return test;
        }
        public void TestObjectCollectionPropertyUpdateSerialization()
        {
            var asset = new Types.MyAsset4 { MyObjects = { new Types.SomeObject { Value = "String1" }, new Types.SomeObject { Value = "String2" } } };
            var baseIds = CollectionItemIdHelper.GetCollectionItemIds(asset.MyObjects);
            baseIds.Add(0, IdentifierGenerator.Get(10));
            baseIds.Add(1, IdentifierGenerator.Get(20));
            var context = DeriveAssetTest<Types.MyAsset4>.DeriveAsset(asset);
            var basePropertyNode = (AssetNode)((IGraphNode)context.BaseGraph.RootNode).TryGetChild(nameof(Types.MyAsset4.MyObjects));
            var derivedPropertyNode = (AssetNode)((IGraphNode)context.DerivedGraph.RootNode).TryGetChild(nameof(Types.MyAsset4.MyObjects));

            basePropertyNode.IndexedTarget(new Index(1))[nameof(Types.SomeObject.Value)].Content.Update("MyBaseString");
            derivedPropertyNode.IndexedTarget(new Index(0))[nameof(Types.SomeObject.Value)].Content.Update("MyDerivedString");
            SerializeAndCompare(context.BaseAssetItem, context.BaseGraph, ObjectCollectionPropertyUpdateBaseYaml, false);
            SerializeAndCompare(context.DerivedAssetItem, context.DerivedGraph, ObjectCollectionPropertyUpdateDerivedYaml, true);
        }
        public void TestGenerateOverridesForSerializationOfCollectionItem()
        {
            const string expectedYaml = @"!SiliconStudio.Assets.Quantum.Tests.Types+SomeObject,SiliconStudio.Assets.Quantum.Tests
Value*: OverriddenString
";
            var asset = new Types.MyAsset4 { MyObjects = { new Types.SomeObject { Value = "String1" }, new Types.SomeObject { Value = "String2" } } };
            var context = DeriveAssetTest<Types.MyAsset4>.DeriveAsset(asset);
            var derivedPropertyNode = (AssetNode)((IGraphNode)context.DerivedGraph.RootNode)[nameof(Types.MyAsset4.MyObjects)].IndexedTarget(new Index(1));
            derivedPropertyNode[nameof(Types.SomeObject.Value)].Content.Update("OverriddenString");
            var expectedPath = new YamlAssetPath();
            expectedPath.PushMember(nameof(Types.SomeObject.Value));

            var overrides = AssetPropertyGraph.GenerateOverridesForSerialization(derivedPropertyNode);
            Assert.AreEqual(1, overrides.Count);
            Assert.True(overrides.ContainsKey(expectedPath));
            Assert.AreEqual(OverrideType.New, overrides[expectedPath]);

            // Test deserialization
            SerializeAndCompare(context.DerivedAsset.MyObjects[1], overrides, expectedYaml);
            bool aliasOccurred;
            var instance = (Types.SomeObject)AssetFileSerializer.Default.Load(DeriveAssetTest<Types.MyAsset9>.ToStream(expectedYaml), null, null, out aliasOccurred, out overrides);
            Assert.AreEqual("OverriddenString", instance.Value);
            Assert.AreEqual(1, overrides.Count);
            Assert.True(overrides.ContainsKey(expectedPath));
            Assert.AreEqual(OverrideType.New, overrides[expectedPath]);
        }
        public void TestObjectCollectionAddSerialization()
        {
            var asset = new Types.MyAsset4 { MyObjects = { new Types.SomeObject { Value = "String1" }, new Types.SomeObject { Value = "String2" } } };
            var baseIds = CollectionItemIdHelper.GetCollectionItemIds(asset.MyObjects);
            baseIds.Add(0, IdentifierGenerator.Get(10));
            baseIds.Add(1, IdentifierGenerator.Get(20));
            var context = DeriveAssetTest<Types.MyAsset4>.DeriveAsset(asset);
            var derivedIds = CollectionItemIdHelper.GetCollectionItemIds(context.DerivedAsset.MyObjects);
            var basePropertyNode = (AssetNode)((IGraphNode)context.BaseGraph.RootNode).TryGetChild(nameof(Types.MyAsset4.MyObjects));
            var derivedPropertyNode = (AssetNode)((IGraphNode)context.DerivedGraph.RootNode).TryGetChild(nameof(Types.MyAsset4.MyObjects));

            derivedPropertyNode.Content.Add(new Types.SomeObject { Value = "String3" });
            basePropertyNode.Content.Add(new Types.SomeObject { Value = "String4" });
            var expectedBaseYaml = string.Format(ObjectCollectionAddBaseYaml.Replace("{}", "{{}}"), baseIds[2]);
            var expectedDerivedYaml = string.Format(ObjectCollectionAddDerivedYaml.Replace("{}", "{{}}"), baseIds[2], derivedIds[3]);
            SerializeAndCompare(context.BaseAssetItem, context.BaseGraph, expectedBaseYaml, false);
            SerializeAndCompare(context.DerivedAssetItem, context.DerivedGraph, expectedDerivedYaml, true);
        }