public void TestSimpleNestedPropertyChangeInBase()
        {
            var baseAsset = AssetHierarchyHelper.BuildAssetContainer(1, 2, 1, null, x => x.Parts[x.RootParts.Single().Id].Part.Object = new Types.SomeObject {
                Value = "BaseName"
            });
            var derivedAsset  = AssetHierarchyHelper.BuildAssetContainer(1, 2, 1, baseAsset.Container);
            var instances     = baseAsset.Asset.CreatePartInstances();
            var baseRootId    = baseAsset.Asset.Hierarchy.RootParts.Single().Id;
            var derivedRootId = instances.RootParts.Single().Id;

            derivedAsset.Graph.AddPartToAsset(instances.Parts, instances.Parts[derivedRootId], null, 1);
            derivedAsset.Graph.RefreshBase();
            Assert.Equal(2, derivedAsset.Asset.Hierarchy.RootParts.Count);
            Assert.Equal(baseRootId, derivedAsset.Asset.Hierarchy.Parts[derivedRootId].Base?.BasePartId);
            Assert.Equal("BaseName", derivedAsset.Asset.Hierarchy.Parts[derivedRootId].Part.Object.Value);
            var baseRootPartNode    = (IAssetObjectNode)baseAsset.Graph.Container.NodeContainer.GetNode(baseAsset.Asset.Hierarchy.Parts[baseRootId].Part.Object);
            var derivedRootPartNode = (IAssetObjectNode)baseAsset.Graph.Container.NodeContainer.GetNode(derivedAsset.Asset.Hierarchy.Parts[derivedRootId].Part.Object);

            baseRootPartNode[nameof(Types.SomeObject.Value)].Update("NewBaseName");
            Assert.Equal("NewBaseName", derivedAsset.Asset.Hierarchy.Parts[derivedRootId].Part.Object.Value);
            baseRootPartNode[nameof(Types.SomeObject.Value)].Update("NewBaseName2");
            Assert.Equal("NewBaseName2", derivedAsset.Asset.Hierarchy.Parts[derivedRootId].Part.Object.Value);
            derivedRootPartNode[nameof(Types.SomeObject.Value)].Update("NewDerivedName");
            Assert.True(derivedRootPartNode[nameof(Types.SomeObject.Value)].IsContentOverridden());
            Assert.Equal("NewDerivedName", derivedAsset.Asset.Hierarchy.Parts[derivedRootId].Part.Object.Value);
            baseRootPartNode[nameof(Types.SomeObject.Value)].Update("NewBaseName3");
            Assert.True(derivedRootPartNode[nameof(Types.SomeObject.Value)].IsContentOverridden());
            Assert.Equal("NewDerivedName", derivedAsset.Asset.Hierarchy.Parts[derivedRootId].Part.Object.Value);
        }
示例#2
0
        public void TestCloneSubHierarchyInstanceWithRemoveOverrides()
        {
            var baseAsset     = AssetHierarchyHelper.BuildAssetContainer(1, 2, 1, null, x => x.Parts[x.RootParts.Single().Id].Part.Name = "BaseName");
            var container     = baseAsset.Container.NodeContainer;
            var derivedAsset  = AssetHierarchyHelper.BuildAssetContainer(1, 2, 1, baseAsset.Container);
            var instances     = baseAsset.Asset.CreatePartInstances();
            var derivedRootId = instances.RootParts.Single().Id;

            derivedAsset.Graph.AddPartToAsset(instances.Parts, instances.Parts[derivedRootId], derivedAsset.Asset.Hierarchy.RootParts.Single(), 1);
            derivedAsset.Graph.RefreshBase();
            var partToChange = (AssetObjectNode)container.GetNode(instances.Parts.Single(x => x.Value.Part.Name == "BaseName").Value.Part);

            partToChange[nameof(Types.MyPart.Name)].Update("Overridden");
            Debug.Write(AssetHierarchyHelper.PrintHierarchy(derivedAsset.Asset));
            var originalRoot = derivedAsset.Asset.Hierarchy.RootParts.Single();
            Dictionary <Guid, Guid> remapping;
            var clone = AssetCompositeHierarchyPropertyGraph <Types.MyPartDesign, Types.MyPart> .CloneSubHierarchies(container, derivedAsset.Asset, originalRoot.Id.Yield(), SubHierarchyCloneFlags.RemoveOverrides, out remapping);

            var cloneAsset = AssetHierarchyHelper.BuildAssetContainer(0, 0, 0, baseAsset.Container);
            var cloneRoot  = clone.Parts[clone.RootParts.Single().Id];

            cloneAsset.Graph.AddPartToAsset(clone.Parts, cloneRoot, null, 0);
            cloneAsset.Graph.RefreshBase();
            Assert.Empty(remapping);
            Assert.Equal(4, 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 = derivedAsset.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.Id, cloneRoot.Part.Id);
            Assert.NotEqual(originalRoot.Children[0], cloneRoot.Part.Children[0]);
            Assert.NotEqual(originalRoot.Children[1], cloneRoot.Part.Children[1]);
            Assert.Equal(originalRoot.Children[0].Id, cloneRoot.Part.Children[0].Id);
            Assert.Equal(originalRoot.Children[1].Id, cloneRoot.Part.Children[1].Id);
            Assert.NotEqual(originalRoot.Children[0].Parent, cloneRoot.Part.Children[0].Parent);
            Assert.NotEqual(originalRoot.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);
            var clonedChangedPart = (AssetObjectNode)container.GetNode(clone.Parts.Single(x => x.Value.Part.Id == (Guid)partToChange[nameof(IIdentifiable.Id)].Retrieve()).Value.Part);

            // Note: currently, using RemoveOverrides does not clear the base (it just clears the overrides), so we should expect to still have the base linked.
            // This behavior could be changed in the future
            Assert.False(clonedChangedPart[nameof(Types.MyPart.Name)].IsContentOverridden());
            Assert.True(clonedChangedPart[nameof(Types.MyPart.Name)].IsContentInherited());
            Assert.Equal("Overridden", clonedChangedPart[nameof(Types.MyPart.Name)].Retrieve());
            Assert.Equal(partToChange[nameof(Types.MyPart.Name)].BaseNode, clonedChangedPart[nameof(Types.MyPart.Name)].BaseNode);
        }