public void TestNestedSerialization() { //var asset = AssetFileSerializer.Load<Types.MyAssetHierarchy>(AssetTestContainer.ToStream(text), $"MyAsset{Types.FileExtension}"); var asset = new Types.MyAssetHierarchy(); asset.Hierarchy.Parts.Add(new Types.MyPartDesign { Part = new Types.MyPart { Id = GuidGenerator.Get(1) } }); asset.Hierarchy.Parts.Add(new Types.MyPartDesign { Part = new Types.MyPart { Id = GuidGenerator.Get(2) } }); asset.Hierarchy.Parts.Add(new Types.MyPartDesign { Part = new Types.MyPart { Id = GuidGenerator.Get(3), Children = { asset.Hierarchy.Parts[GuidGenerator.Get(2)].Part } } }); asset.Hierarchy.Parts.Add(new Types.MyPartDesign { Part = new Types.MyPart { Id = GuidGenerator.Get(4), Children = { asset.Hierarchy.Parts[GuidGenerator.Get(1)].Part } } }); asset.Hierarchy.RootParts.Add(asset.Hierarchy.Parts[GuidGenerator.Get(2)].Part); asset.Hierarchy.RootParts.Add(asset.Hierarchy.Parts[GuidGenerator.Get(1)].Part); var context = new AssetTestContainer <Types.MyAssetHierarchy, Types.MyAssetHierarchyPropertyGraph>(asset); context.BuildGraph(); SerializationHelper.SerializeAndCompare(context.AssetItem, context.Graph, NestedHierarchyYaml, false); }
public void TestDictionaryDeserialization() { ShadowObject.Enable = true; var stream = new MemoryStream(); var writer = new StreamWriter(stream); writer.Write(YamlDictionary); 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(2), stringIds[GuidGenerator.Get(200)]); Assert.Equal(IdentifierGenerator.Get(1), stringIds[GuidGenerator.Get(100)]); var objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); Assert.Equal(IdentifierGenerator.Get(3), objectIds["key3"]); Assert.Equal(IdentifierGenerator.Get(4), objectIds["key4"]); }
public void TestDictionarySerializationWithDeleted() { 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(8); stringIds[GuidGenerator.Get(100)] = IdentifierGenerator.Get(5); stringIds.MarkAsDeleted(IdentifierGenerator.Get(3)); stringIds.MarkAsDeleted(IdentifierGenerator.Get(1)); var objectIds = CollectionItemIdHelper.GetCollectionItemIds(obj.Objects); objectIds["key3"] = IdentifierGenerator.Get(3); objectIds["key4"] = IdentifierGenerator.Get(4); objectIds.MarkAsDeleted(IdentifierGenerator.Get(1)); objectIds.MarkAsDeleted(IdentifierGenerator.Get(6)); var yaml = SerializeAsString(obj); Assert.Equal(YamlDictionaryWithDeleted, yaml); }
public void TestAllMissingInList() { const string baseYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAssetWithRef,Stride.Core.Assets.Quantum.Tests Id: 00000001-0001-0000-0100-000001000000 MyObjects: 0a0000000a0000000a0000000a000000: Value: MyInstance Id: 00000002-0002-0000-0200-000002000000 0a0000000b0000000b0000000b000000: ref!! 00000002-0002-0000-0200-000002000000 "; const string derivedYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAssetWithRef,Stride.Core.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 00000001-0001-0000-0100-000001000000:MyAsset "; Types.AssetWithRefPropertyGraphDefinition.IsObjectReferenceFunc = (targetNode, index) => index.IsInt && index.Int == 1; var context = DeriveAssetTest <Types.MyAssetWithRef, Types.MyAssetBasePropertyGraph> .LoadFromYaml(baseYaml, derivedYaml); context.DerivedGraph.ReconcileWithBase(); Assert.Equal(GuidGenerator.Get(2), context.BaseAsset.MyObjects[0].Id); Assert.Equal(context.BaseAsset.MyObjects[1], context.BaseAsset.MyObjects[0]); Assert.Equal(2, context.DerivedAsset.MyObjects.Count); Assert.NotEqual(GuidGenerator.Get(2), context.DerivedAsset.MyObjects[0].Id); Assert.Equal(context.DerivedAsset.MyObjects[1], context.DerivedAsset.MyObjects[0]); }
public void TestWithCorrectObjectReferences() { const string baseYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAssetWithRef,Stride.Core.Assets.Quantum.Tests Id: 00000001-0001-0000-0100-000001000000 MyObject1: Value: MyInstance Id: 00000002-0002-0000-0200-000002000000 MyObject2: ref!! 00000002-0002-0000-0200-000002000000 "; const string derivedYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAssetWithRef,Stride.Core.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 00000001-0001-0000-0100-000001000000:MyAsset MyObject1: Value: MyModifiedInstance Id: 00000003-0003-0000-0300-000003000000 MyObject2: ref!! 00000003-0003-0000-0300-000003000000 "; Types.AssetWithRefPropertyGraphDefinition.IsObjectReferenceFunc = (targetNode, index) => (targetNode as IMemberNode)?.Name == nameof(Types.MyAssetWithRef.MyObject2); var context = DeriveAssetTest <Types.MyAssetWithRef, Types.MyAssetBasePropertyGraph> .LoadFromYaml(baseYaml, derivedYaml); var prevInstance = context.DerivedAsset.MyObject2; context.DerivedGraph.ReconcileWithBase(); Assert.Equal(GuidGenerator.Get(2), context.BaseAsset.MyObject1.Id); Assert.Equal(context.BaseAsset.MyObject1, context.BaseAsset.MyObject2); Assert.Equal(GuidGenerator.Get(3), context.DerivedAsset.MyObject1.Id); Assert.Equal(context.DerivedAsset.MyObject1, context.DerivedAsset.MyObject2); Assert.Equal(prevInstance, context.DerivedAsset.MyObject2); }
public void TestWithCorrectObjectReferencesInList() { const string baseYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAssetWithRef,Stride.Core.Assets.Quantum.Tests Id: 00000001-0001-0000-0100-000001000000 MyObject1: Value: MyInstance Id: 00000002-0002-0000-0200-000002000000 MyObjects: 0a0000000a0000000a0000000a000000: ref!! 00000002-0002-0000-0200-000002000000 "; const string derivedYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAssetWithRef,Stride.Core.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 00000001-0001-0000-0100-000001000000:MyAsset MyObject1: Value: MyInstance Id: 00000003-0003-0000-0300-000003000000 MyObjects: 0a0000000a0000000a0000000a000000: ref!! 00000003-0003-0000-0300-000003000000 "; var context = DeriveAssetTest <Types.MyAssetWithRef, Types.MyAssetBasePropertyGraph> .LoadFromYaml(baseYaml, derivedYaml); var prevInstance = context.DerivedAsset.MyObjects[0]; context.DerivedGraph.ReconcileWithBase(); Assert.Equal(GuidGenerator.Get(2), context.BaseAsset.MyObject1.Id); Assert.Equal(context.BaseAsset.MyObject1, context.BaseAsset.MyObjects[0]); Assert.Equal(GuidGenerator.Get(3), context.DerivedAsset.MyObject1.Id); Assert.Equal(context.DerivedAsset.MyObject1, context.DerivedAsset.MyObjects[0]); Assert.Equal(prevInstance, context.DerivedAsset.MyObjects[0]); }
public void TestCopyPasteEntityAtRoot() { var sceneAsset = new SceneAsset(); var entity = new EntityDesign { Entity = new Entity { Id = GuidGenerator.Get(1) } }; entity.Entity.Transform.Position = Vector3.UnitZ; sceneAsset.Hierarchy.RootParts.Add(entity.Entity); sceneAsset.Hierarchy.Parts.Add(entity); var assetTest = new CopyPasteTest <SceneAsset>(sceneAsset); var service = TestHelper.CreateCopyPasteService(); service.PropertyGraphContainer.RegisterGraph(assetTest.AssetGraph); var clipboard = Copy(service, assetTest.AssetGraph, new[] { entity }); Paste(service, clipboard, assetTest.AssetGraph, null, null); Assert.Equal(2, assetTest.Asset.Hierarchy.Parts.Count); Assert.True(assetTest.Asset.Hierarchy.Parts.Values.Contains(entity)); var pastedEntity = assetTest.Asset.Hierarchy.Parts.Values.Single(x => x != entity); Assert.Equal(2, assetTest.Asset.Hierarchy.RootParts.Count); Assert.Contains(pastedEntity.Entity, assetTest.Asset.Hierarchy.RootParts); Assert.Equal(string.Empty, pastedEntity.Folder); Assert.NotEqual(entity.Entity.Id, pastedEntity.Entity.Id); Assert.NotEqual(entity.Entity.Transform.Id, pastedEntity.Entity.Transform.Id); Assert.Equal(Vector3.UnitZ, pastedEntity.Entity.Transform.Position); }
public void TestAbstractNonIdentifiableReferenceableDictionaryDeserialization() { var obj = (NonIdentifiableCollectionContainer)Deserialize(AbstractNonIdentifiableReferenceableDictionaryYaml); Assert.NotNull(obj.AbstractRefDictionary); Assert.Equal(2, obj.AbstractRefDictionary.Count); Assert.Equal(obj.AbstractRefDictionary["Item1"], obj.AbstractRefDictionary["Item2"]); Assert.Equal(GuidGenerator.Get(1), obj.AbstractRefDictionary["Item1"].Id); Assert.Equal("Test", obj.AbstractRefDictionary["Item1"].Value); }
public void TestAbstractNonIdentifiableReferenceableListDeserialization() { var obj = (NonIdentifiableCollectionContainer)Deserialize(AbstractNonIdentifiableReferenceableListYaml); Assert.NotNull(obj.AbstractRefList); Assert.Equal(2, obj.AbstractRefList.Count); Assert.Equal(obj.AbstractRefList[0], obj.AbstractRefList[1]); Assert.Equal(GuidGenerator.Get(1), obj.AbstractRefList[0].Id); Assert.Equal("Test", obj.AbstractRefList[0].Value); }
private static PrefabAsset CreateOriginAsset() { // Basic test of entity serialization with links between entities (entity-entity, entity-component) // E1 // | E2 + link to E1 via TestEntityComponent // E3 // E4 + link to E3.Transform component via TestEntityComponent var originAsset = new PrefabAsset(); { var entity1 = new Entity() { Name = "E1", Id = GuidGenerator.Get(200) }; var entity2 = new Entity() { Name = "E2", Id = GuidGenerator.Get(400) }; // Use group property to make sure that it is properly serialized var entity3 = new Entity() { Name = "E3", Id = GuidGenerator.Get(100) }; var entity4 = new Entity() { Name = "E4", Id = GuidGenerator.Get(300) }; // TODO: Add script link entity1.Transform.Children.Add(entity2.Transform); // Test a link between entity1 and entity2 entity2.Add(new TestEntityComponent() { EntityLink = entity1 }); // Test a component link between entity4 and entity 3 entity4.Add(new TestEntityComponent() { EntityComponentLink = entity3.Transform }); originAsset.Hierarchy.Parts.Add(new EntityDesign(entity1)); originAsset.Hierarchy.Parts.Add(new EntityDesign(entity2)); originAsset.Hierarchy.Parts.Add(new EntityDesign(entity3)); originAsset.Hierarchy.Parts.Add(new EntityDesign(entity4)); originAsset.Hierarchy.RootParts.Add(entity1); originAsset.Hierarchy.RootParts.Add(entity3); originAsset.Hierarchy.RootParts.Add(entity4); } return(originAsset); }
public void TestExpandObjectDeserialization() { var obj = (Container)Deserialize(ExpandedObjectYaml); Assert.NotNull(obj.Referenceable1); Assert.Null(obj.Referenceable2); Assert.Null(obj.Referenceable3); Assert.Null(obj.Referenceable4); Assert.Equal(GuidGenerator.Get(1), obj.Referenceable1.Id); Assert.Equal("Test", obj.Referenceable1.Value); }
public void TestSimpleDeserialization() { var asset = AssetFileSerializer.Load <Types.MyAssetHierarchy>(AssetTestContainer.ToStream(SimpleHierarchyYaml), $"MyAsset{Types.FileExtension}"); Assert.Equal(2, asset.Asset.Hierarchy.RootParts.Count); Assert.Equal(GuidGenerator.Get(2), asset.Asset.Hierarchy.RootParts[0].Id); Assert.Equal(GuidGenerator.Get(1), asset.Asset.Hierarchy.RootParts[1].Id); Assert.Equal(2, asset.Asset.Hierarchy.Parts.Count); Assert.True(asset.Asset.Hierarchy.Parts.ContainsKey(GuidGenerator.Get(1))); Assert.True(asset.Asset.Hierarchy.Parts.ContainsKey(GuidGenerator.Get(2))); }
public void TestAbstracteferenceObjectAbstractDeserialization() { var obj = (Container)Deserialize(AbstractReferenceAbstractObjectYaml); Assert.NotNull(obj.Referenceable3); Assert.NotNull(obj.Referenceable4); Assert.Equal(obj.Referenceable3, obj.Referenceable4); Assert.Null(obj.Referenceable1); Assert.Null(obj.Referenceable2); Assert.Equal(GuidGenerator.Get(1), obj.Referenceable3.Id); Assert.Equal("Test", obj.Referenceable3.Value); }
public void TestExpandObjectSerialization() { var obj = new Container { Referenceable1 = new Referenceable { Id = GuidGenerator.Get(1), Value = "Test" } }; var yaml = SerializeAsString(obj, null); Assert.Equal(ExpandedObjectYaml, yaml); yaml = SerializeAsString(obj, new YamlAssetMetadata <Guid>()); Assert.Equal(ExpandedObjectYaml, yaml); }
public void TestAbstractReferenceableListDeserialization() { var obj = (CollectionContainer)Deserialize(AbstractReferenceableListYaml); Assert.NotNull(obj.AbstractRefList); Assert.Equal(2, obj.AbstractRefList.Count); Assert.Equal(obj.AbstractRefList[0], obj.AbstractRefList[1]); var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.AbstractRefList); Assert.Equal(IdentifierGenerator.Get(1), ids[0]); Assert.Equal(IdentifierGenerator.Get(2), ids[1]); Assert.Equal(GuidGenerator.Get(1), obj.AbstractRefList[0].Id); Assert.Equal("Test", obj.AbstractRefList[0].Value); }
public void TestAbstractReferenceableDictionaryDeserialization() { var obj = (CollectionContainer)Deserialize(AbstractReferenceableDictionaryYaml); Assert.NotNull(obj.AbstractRefDictionary); Assert.Equal(2, obj.AbstractRefDictionary.Count); Assert.Equal(obj.AbstractRefDictionary["Item1"], obj.AbstractRefDictionary["Item2"]); var ids = CollectionItemIdHelper.GetCollectionItemIds(obj.AbstractRefDictionary); Assert.Equal(IdentifierGenerator.Get(1), ids["Item1"]); Assert.Equal(IdentifierGenerator.Get(2), ids["Item2"]); Assert.Equal(GuidGenerator.Get(1), obj.AbstractRefDictionary["Item1"].Id); Assert.Equal("Test", obj.AbstractRefDictionary["Item1"].Value); }
public void TestMissortedPartsDeserialization() { var asset = AssetFileSerializer.Load <Types.MyAssetHierarchy>(AssetTestContainer.ToStream(MissortedHierarchyYaml), $"MyAsset{Types.FileExtension}"); Assert.Equal(2, asset.Asset.Hierarchy.RootParts.Count); Assert.Equal(GuidGenerator.Get(2), asset.Asset.Hierarchy.RootParts[0].Id); Assert.Equal(GuidGenerator.Get(1), asset.Asset.Hierarchy.RootParts[1].Id); Assert.Equal(4, asset.Asset.Hierarchy.Parts.Count); Assert.True(asset.Asset.Hierarchy.Parts.ContainsKey(GuidGenerator.Get(1))); Assert.True(asset.Asset.Hierarchy.Parts.ContainsKey(GuidGenerator.Get(2))); Assert.True(asset.Asset.Hierarchy.Parts.ContainsKey(GuidGenerator.Get(3))); Assert.True(asset.Asset.Hierarchy.Parts.ContainsKey(GuidGenerator.Get(4))); Assert.Single(asset.Asset.Hierarchy.Parts[GuidGenerator.Get(3)].Part.Children); Assert.Equal(asset.Asset.Hierarchy.Parts[GuidGenerator.Get(2)].Part, asset.Asset.Hierarchy.Parts[GuidGenerator.Get(3)].Part.Children[0]); Assert.Single(asset.Asset.Hierarchy.Parts[GuidGenerator.Get(4)].Part.Children); Assert.Equal(asset.Asset.Hierarchy.Parts[GuidGenerator.Get(1)].Part, asset.Asset.Hierarchy.Parts[GuidGenerator.Get(4)].Part.Children[0]); }
public void TestAbstracteferenceObjectAbstractSerialization() { var obj = new Container { Referenceable3 = new Referenceable { Id = GuidGenerator.Get(1), Value = "Test" } }; obj.Referenceable4 = (Referenceable)obj.Referenceable3; var objectReferences = new YamlAssetMetadata <Guid>(); var path = new YamlAssetPath(); path.PushMember(nameof(Container.Referenceable4)); objectReferences.Set(path, obj.Referenceable4.Id); var yaml = SerializeAsString(obj, objectReferences); Assert.Equal(AbstractReferenceAbstractObjectYaml, yaml); }
public void TestConcreteReferenceConcreteObjectSerialization() { var obj = new Container { Referenceable1 = new Referenceable { Id = GuidGenerator.Get(1), Value = "Test" } }; obj.Referenceable2 = obj.Referenceable1; var objectReferences = new YamlAssetMetadata <Guid>(); var path = new YamlAssetPath(); path.PushMember(nameof(Container.Referenceable2)); objectReferences.Set(path, obj.Referenceable2.Id); var yaml = SerializeAsString(obj, objectReferences); Assert.Equal(ConcreteReferenceConcreteObjectYaml, yaml); }
public void TestAbstractNonIdentifiableReferenceableDictionarySerialization() { var obj = new NonIdentifiableCollectionContainer(); var item = new Referenceable { Id = GuidGenerator.Get(1), Value = "Test" }; obj.AbstractRefDictionary.Add("Item1", item); obj.AbstractRefDictionary.Add("Item2", item); var objectReferences = new YamlAssetMetadata <Guid>(); var path = new YamlAssetPath(); path.PushMember(nameof(CollectionContainer.AbstractRefDictionary)); path.PushIndex("Item1"); objectReferences.Set(path, GuidGenerator.Get(1)); var yaml = SerializeAsString(obj, objectReferences); Assert.Equal(AbstractNonIdentifiableReferenceableDictionaryYaml, yaml); }
public void TestConcreteNonIdentifiableReferenceableListSerialization() { var obj = new NonIdentifiableCollectionContainer(); var item = new Referenceable { Id = GuidGenerator.Get(1), Value = "Test" }; obj.ConcreteRefList.Add(item); obj.ConcreteRefList.Add(item); var objectReferences = new YamlAssetMetadata <Guid>(); var path = new YamlAssetPath(); path.PushMember(nameof(CollectionContainer.ConcreteRefList)); path.PushIndex(0); objectReferences.Set(path, GuidGenerator.Get(1)); var yaml = SerializeAsString(obj, objectReferences); Assert.Equal(ConcreteNonIdentifiableReferenceableListYaml, yaml); }
public void TestWithOverriddenObjectReferencesInList() { const string baseYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAssetWithRef,Stride.Core.Assets.Quantum.Tests Id: 00000001-0001-0000-0100-000001000000 MyObject1: Value: MyInstance Id: 00000002-0002-0000-0200-000002000000 MyObject2: Value: MyInstance Id: 00000003-0003-0003-0300-000003000000 MyObjects: 0a0000000a0000000a0000000a000000: ref!! 00000002-0002-0000-0200-000002000000 "; const string derivedYaml = @"!Stride.Core.Assets.Quantum.Tests.Helpers.Types+MyAssetWithRef,Stride.Core.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 00000001-0001-0000-0100-000001000000:MyAsset MyObject1: Value: MyModifiedInstance Id: 00000003-0003-0003-0300-000003000000 MyObject2: Value: MyInstance Id: 00000004-0004-0000-0400-000004000000 MyObjects: 0a0000000a0000000a0000000a000000*: ref!! 00000004-0004-0000-0400-000004000000 "; Types.AssetWithRefPropertyGraphDefinition.IsObjectReferenceFunc = (targetNode, index) => (targetNode as IObjectNode)?.ItemReferences != null; var context = DeriveAssetTest <Types.MyAssetWithRef, Types.MyAssetBasePropertyGraph> .LoadFromYaml(baseYaml, derivedYaml); var prevInstance = context.DerivedAsset.MyObjects[0]; Assert.Equal(context.DerivedAsset.MyObject2, context.DerivedAsset.MyObjects[0]); context.DerivedGraph.ReconcileWithBase(); Assert.Equal(prevInstance, context.DerivedAsset.MyObjects[0]); Assert.NotEqual(context.BaseAsset.MyObject1, context.DerivedAsset.MyObject1); Assert.NotEqual(context.BaseAsset.MyObjects[0], context.DerivedAsset.MyObjects[0]); Assert.NotEqual(context.BaseAsset.MyObject2, context.DerivedAsset.MyObject2); Assert.NotEqual(context.DerivedAsset.MyObject1, context.DerivedAsset.MyObjects[0]); Assert.Equal(context.DerivedAsset.MyObject2, context.DerivedAsset.MyObjects[0]); Assert.Equal(GuidGenerator.Get(4), context.DerivedAsset.MyObject2.Id); }
private static Types.MyPartDesign BuildPart(Types.MyAssetHierarchy asset, string name, int depth, int childPerPart, ref int guidCount) { var part = new Types.MyPartDesign { Part = new Types.MyPart { Id = GuidGenerator.Get(++guidCount), Name = name } }; asset.Hierarchy.Parts.Add(part); if (depth <= 0) { return(part); } for (var i = 0; i < childPerPart; ++i) { var child = BuildPart(asset, name + $"-{i + 1}", depth - 1, childPerPart, ref guidCount); part.Part.AddChild(child.Part); } return(part); }
public void TestCollectionObjectReferenceGraph() { var obj = new Types.MyReferenceable { Id = GuidGenerator.Get(2), Value = "MyInstance" }; var asset = new Types.MyAssetWithRef2 { NonReference = obj, References = { obj } }; var context = DeriveAssetTest <Types.MyAssetWithRef2, Types.MyAssetBasePropertyGraph> .DeriveAsset(asset); Assert.Equal(Types.MyAssetWithRef2.MemberCount, context.BaseGraph.RootNode.Members.Count); Assert.True(context.BaseGraph.RootNode[nameof(Types.MyAssetWithRef2.NonReference)].IsReference); Assert.Equal(obj, context.BaseGraph.RootNode[nameof(Types.MyAssetWithRef2.NonReference)].Target.Retrieve()); Assert.True(context.BaseGraph.RootNode[nameof(Types.MyAssetWithRef2.References)].IsReference); Assert.Equal(obj, context.BaseGraph.RootNode[nameof(Types.MyAssetWithRef2.References)].Target.Retrieve(new Index(0))); Assert.Equal(context.BaseGraph.RootNode[nameof(Types.MyAssetWithRef2.NonReference)].Target, context.BaseGraph.RootNode[nameof(Types.MyAssetWithRef2.References)].Target.IndexedTarget(new Index(0))); Assert.Equal(context.BaseGraph.RootNode[nameof(Types.MyAssetWithRef2.References)], context.DerivedGraph.RootNode[nameof(Types.MyAssetWithRef2.References)].BaseNode); Assert.Equal(context.BaseGraph.RootNode[nameof(Types.MyAssetWithRef2.References)].Target, context.DerivedGraph.RootNode[nameof(Types.MyAssetWithRef2.References)].Target.BaseNode); Assert.Equal(context.BaseGraph.RootNode[nameof(Types.MyAssetWithRef2.NonReference)].Target, context.DerivedGraph.RootNode[nameof(Types.MyAssetWithRef2.References)].Target.IndexedTarget(new Index(0)).BaseNode); }
public void TestSimpleReference() { Types.AssetWithRefPropertyGraphDefinition.IsObjectReferenceFunc = (targetNode, index) => { return((targetNode as IMemberNode)?.Name == nameof(Types.MyAssetWithRef.MyObject2)); }; var obj = new Types.MyReferenceable { Id = GuidGenerator.Get(2), Value = "MyInstance" }; var asset = new Types.MyAssetWithRef { MyObject1 = obj, MyObject2 = obj }; var context = new AssetTestContainer <Types.MyAssetWithRef, Types.MyAssetBasePropertyGraph>(asset); context.BuildGraph(); SerializationHelper.SerializeAndCompare(context.AssetItem, context.Graph, SimpleReferenceYaml, false); context = AssetTestContainer <Types.MyAssetWithRef, Types.MyAssetBasePropertyGraph> .LoadFromYaml(SimpleReferenceYaml); Assert.Equal(context.Asset.MyObject1, context.Asset.MyObject2); Assert.Equal(GuidGenerator.Get(2), context.Asset.MyObject1.Id); }
public void TestCloneSubHierarchyWithExternalReferencesWithCleanExternalReferences() { var graph = AssetHierarchyHelper.BuildAssetAndGraph(2, 2, 2, x => x.Parts[GuidGenerator.Get(5)].Part.MyReferences = new List <Types.MyPart> { x.Parts[GuidGenerator.Get(2)].Part }); Debug.Write(AssetHierarchyHelper.PrintHierarchy(graph.Asset)); var originalRoot = graph.Asset.Hierarchy.Parts[graph.Asset.Hierarchy.RootParts[1].Id]; Dictionary <Guid, Guid> remapping; var clone = AssetCompositeHierarchyPropertyGraph <Types.MyPartDesign, Types.MyPart> .CloneSubHierarchies(graph.Container.NodeContainer, graph.Asset, originalRoot.Part.Id.Yield(), SubHierarchyCloneFlags.CleanExternalReferences, out remapping); var cloneRoot = clone.Parts[clone.RootParts.Single().Id]; Assert.Empty(remapping); Assert.Equal(3, clone.Parts.Count); Assert.Single(clone.RootParts); foreach (var rootPart in clone.RootParts) { Assert.Contains(rootPart, clone.Parts.Values.Select(x => x.Part)); } foreach (var part in clone.Parts.Values) { var matchingPart = graph.Asset.Hierarchy.Parts[part.Part.Id]; Assert.NotEqual(matchingPart, part); Assert.NotEqual(matchingPart.Part, part.Part); Assert.Equal(matchingPart.Part.Id, part.Part.Id); Assert.Equal(matchingPart.Part.Name, part.Part.Name); } Assert.Equal(originalRoot.Part.Id, cloneRoot.Part.Id); Assert.NotEqual(originalRoot.Part.Children[0], cloneRoot.Part.Children[0]); Assert.NotEqual(originalRoot.Part.Children[1], cloneRoot.Part.Children[1]); Assert.Equal(originalRoot.Part.Children[0].Id, cloneRoot.Part.Children[0].Id); Assert.Equal(originalRoot.Part.Children[1].Id, cloneRoot.Part.Children[1].Id); Assert.NotEqual(originalRoot.Part.Children[0].Parent, cloneRoot.Part.Children[0].Parent); Assert.NotEqual(originalRoot.Part.Children[1].Parent, cloneRoot.Part.Children[1].Parent); Assert.Equal(cloneRoot.Part, cloneRoot.Part.Children[0].Parent); Assert.Equal(cloneRoot.Part, cloneRoot.Part.Children[1].Parent); Assert.Null(cloneRoot.Part.Children[0].MyReferences[0]); }
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.Equal(AbstractReferenceableListYaml, yaml); }
public void TestConcreteReferenceableDictionarySerialization() { var obj = new CollectionContainer(); 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.PushItemId(IdentifierGenerator.Get(1)); objectReferences.Set(path, GuidGenerator.Get(1)); var yaml = SerializeAsString(obj, objectReferences); Assert.Equal(ConcreteReferenceableDictionaryYaml, yaml); }
public void TestAllMissingInvertOrder() { const string baseYaml = @"!Xenko.Core.Assets.Quantum.Tests.Helpers.Types+MyAssetWithRef,Xenko.Core.Assets.Quantum.Tests Id: 00000001-0001-0000-0100-000001000000 MyObject1: ref!! 00000002-0002-0000-0200-000002000000 MyObject2: Value: MyInstance Id: 00000002-0002-0000-0200-000002000000 "; const string derivedYaml = @"!Xenko.Core.Assets.Quantum.Tests.Helpers.Types+MyAssetWithRef,Xenko.Core.Assets.Quantum.Tests Id: 20000000-0000-0000-0000-000000000000 Archetype: 00000001-0001-0000-0100-000001000000:MyAsset "; Types.AssetWithRefPropertyGraphDefinition.IsObjectReferenceFunc = (targetNode, index) => (targetNode as IMemberNode)?.Name == nameof(Types.MyAssetWithRef.MyObject1); var context = DeriveAssetTest <Types.MyAssetWithRef, Types.MyAssetBasePropertyGraph> .LoadFromYaml(baseYaml, derivedYaml); context.DerivedGraph.ReconcileWithBase(); Assert.Equal(GuidGenerator.Get(2), context.BaseAsset.MyObject1.Id); Assert.Equal(context.BaseAsset.MyObject1, context.BaseAsset.MyObject2); Assert.NotEqual(GuidGenerator.Get(2), context.DerivedAsset.MyObject1.Id); Assert.Equal(context.DerivedAsset.MyObject1, context.DerivedAsset.MyObject2); }
public void TestIdsGeneration() { ShadowObject.Enable = true; CollectionItemIdentifiers ids; var obj1 = new ContainerCollection("Root") { Strings = { "aaa", "bbb", "ccc" }, Objects = { new ContainerCollection("obj1"), new ContainerCollection("obj2") } }; var hashSet = new HashSet <ItemId>(); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj1.Strings, out ids)); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj1.Strings, out ids)); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj1.Objects, out ids)); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj1.Objects, out ids)); AssetCollectionItemIdHelper.GenerateMissingItemIds(obj1); Assert.True(CollectionItemIdHelper.TryGetCollectionItemIds(obj1.Strings, out ids)); Assert.Equal(3, ids.KeyCount); Assert.Equal(0, ids.DeletedCount); Assert.True(ids.ContainsKey(0)); Assert.True(ids.ContainsKey(1)); Assert.True(ids.ContainsKey(2)); hashSet.Add(ids[0]); hashSet.Add(ids[1]); hashSet.Add(ids[2]); Assert.True(CollectionItemIdHelper.TryGetCollectionItemIds(obj1.Objects, out ids)); Assert.Equal(2, ids.KeyCount); Assert.Equal(0, ids.DeletedCount); Assert.True(ids.ContainsKey(0)); Assert.True(ids.ContainsKey(1)); hashSet.Add(ids[0]); hashSet.Add(ids[1]); Assert.Equal(5, hashSet.Count); var obj2 = new ContainerDictionary("Root") { Strings = { { GuidGenerator.Get(200), "aaa" }, { GuidGenerator.Get(100), "bbb" }, { GuidGenerator.Get(300), "ccc" } }, Objects = { { "key3", new ContainerCollection("obj1") }, { "key4", new ContainerCollection("obj2") } }, }; hashSet.Clear(); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj2.Strings, out ids)); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj2.Strings, out ids)); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj2.Objects, out ids)); Assert.False(CollectionItemIdHelper.TryGetCollectionItemIds(obj2.Objects, out ids)); AssetCollectionItemIdHelper.GenerateMissingItemIds(obj2); Assert.True(CollectionItemIdHelper.TryGetCollectionItemIds(obj2.Strings, out ids)); Assert.Equal(3, ids.KeyCount); Assert.Equal(0, ids.DeletedCount); Assert.True(ids.ContainsKey(GuidGenerator.Get(200))); Assert.True(ids.ContainsKey(GuidGenerator.Get(100))); Assert.True(ids.ContainsKey(GuidGenerator.Get(300))); hashSet.Add(ids[GuidGenerator.Get(200)]); hashSet.Add(ids[GuidGenerator.Get(100)]); hashSet.Add(ids[GuidGenerator.Get(300)]); Assert.True(CollectionItemIdHelper.TryGetCollectionItemIds(obj2.Objects, out ids)); Assert.Equal(2, ids.KeyCount); Assert.Equal(0, ids.DeletedCount); Assert.True(ids.ContainsKey("key3")); Assert.True(ids.ContainsKey("key4")); hashSet.Add(ids["key3"]); hashSet.Add(ids["key4"]); Assert.Equal(5, hashSet.Count); }