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); }