当前位置: 首页>>代码示例>>C#>>正文


C# AssetItem.CreateChildAsset方法代码示例

本文整理汇总了C#中AssetItem.CreateChildAsset方法的典型用法代码示例。如果您正苦于以下问题:C# AssetItem.CreateChildAsset方法的具体用法?C# AssetItem.CreateChildAsset怎么用?C# AssetItem.CreateChildAsset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AssetItem的用法示例。


在下文中一共展示了AssetItem.CreateChildAsset方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestInheritance

        public void TestInheritance()
        {
            // -----------------------------------------------------------
            // Tests inheritance
            // -----------------------------------------------------------
            // 4 assets
            // [asset1] is referencing [asset2]
            // [asset2]
            // [asset3] is inheriting  [asset1]
            // We create a [project1] with [asset1, asset2, asset3]
            // Check direct inherit dependencies for [asset3]: [asset1]
            // -----------------------------------------------------------

            var asset1 = new AssetObjectTest();
            var asset2 = new AssetObjectTest();
            var assetItem1 = new AssetItem("asset-1", asset1);
            var assetItem2 = new AssetItem("asset-2", asset2);

            var asset3 = assetItem1.CreateChildAsset();
            var assetItem3 = new AssetItem("asset-3", asset3);

            asset1.Reference = new AssetReference<AssetObjectTest>(assetItem2.Id, assetItem2.Location);

            var project = new Package();
            project.Assets.Add(assetItem1);
            project.Assets.Add(assetItem2);
            project.Assets.Add(assetItem3);

            // Create a session with this project
            using (var session = new PackageSession(project))
            {
                var dependencyManager = session.DependencyManager;

                // Verify inheritance
                {
                    var assets = dependencyManager.FindAssetsInheritingFrom(asset1.Id);
                    Assert.AreEqual(1, assets.Count);
                    Assert.AreEqual(asset3.Id, assets[0].Id);
                }

                // Remove the inheritance
                var copyBase = asset3.Base;
                asset3.Base = null;
                assetItem3.IsDirty = true;
                {
                    var assets = dependencyManager.FindAssetsInheritingFrom(asset1.Id);
                    Assert.AreEqual(0, assets.Count);
                }

                // Add back the inheritance
                asset3.Base = copyBase;
                assetItem3.IsDirty = true;
                {
                    var assets = dependencyManager.FindAssetsInheritingFrom(asset1.Id);
                    Assert.AreEqual(1, assets.Count);
                    Assert.AreEqual(asset3.Id, assets[0].Id);
                }
            }
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:59,代码来源:TestDependencyManager.cs

示例2: TestCreateChildAsset

        public void TestCreateChildAsset()
        {
            // Create an Entity child asset

            // base: EA, EB, EC
            // newAsset: EA'(base: EA), EB'(base: EB), EC'(base: EC)

            var entityA = new Entity() { Name = "A" };
            var entityB = new Entity() { Name = "B" };
            var entityC = new Entity() { Name = "C" };

            // Create Base Asset
            var baseAsset = new EntityGroupAsset();
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(entityA, new EntityDesignData()));
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(entityB, new EntityDesignData()));
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(entityC, new EntityDesignData()));
            baseAsset.Hierarchy.RootEntities.Add(entityA.Id);
            baseAsset.Hierarchy.RootEntities.Add(entityB.Id);
            baseAsset.Hierarchy.RootEntities.Add(entityC.Id);

            var baseAssetItem = new AssetItem("base", baseAsset);

            // Create new Asset (from base)
            var newAsset = (EntityGroupAsset)baseAssetItem.CreateChildAsset();

            // On a derive asset all entities must have a base value and base must come from baseAsset
            Assert.True(newAsset.Hierarchy.Entities.All(item => item.Design.BaseId.HasValue && baseAsset.Hierarchy.Entities.ContainsKey(item.Design.BaseId.Value)));

            // Verify that we have exactly the same number of entities
            Assert.AreEqual(baseAsset.Hierarchy.RootEntities.Count, newAsset.Hierarchy.RootEntities.Count);
            Assert.AreEqual(baseAsset.Hierarchy.Entities.Count, newAsset.Hierarchy.Entities.Count);

            // Verify that baseId and newId is correctly setup
            var entityAInNew = newAsset.Hierarchy.Entities.FirstOrDefault(item => item.Design.BaseId.Value == entityA.Id && item.Entity.Id != item.Design.BaseId.Value);
            Assert.NotNull(entityAInNew);

            var entityBInNew = newAsset.Hierarchy.Entities.FirstOrDefault(item => item.Design.BaseId.Value == entityB.Id && item.Entity.Id != item.Design.BaseId.Value);
            Assert.NotNull(entityBInNew);

            var entityCInNew = newAsset.Hierarchy.Entities.FirstOrDefault(item => item.Design.BaseId.Value == entityC.Id && item.Entity.Id != item.Design.BaseId.Value);
            Assert.NotNull(entityCInNew);

            // Verify that RootEntities are also correctly mapped
            Assert.AreEqual(entityAInNew.Entity.Id, newAsset.Hierarchy.RootEntities[0]);
            Assert.AreEqual(entityBInNew.Entity.Id, newAsset.Hierarchy.RootEntities[1]);
            Assert.AreEqual(entityCInNew.Entity.Id, newAsset.Hierarchy.RootEntities[2]);
        }
开发者ID:hsabaleuski,项目名称:paradox,代码行数:47,代码来源:TestEntityGroupAssetMerge.cs

示例3: TestMergeSimpleHierarchy

        public void TestMergeSimpleHierarchy()
        {
            // Test merging a simple Entity Asset that has 3 entities
            //
            // base: EA, EB, EC
            // newBase: EA, EB, EC, ED
            // newAsset: EA, EB, EC
            //
            // Result Merge: EA, EB, EC, ED

            var entityA = new Entity() { Name = "A" };
            var entityB = new Entity() { Name = "B" };
            var entityC = new Entity() { Name = "C" };

            // Create Base Asset
            var baseAsset = new EntityGroupAsset();
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(entityA, new EntityDesignData()));
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(entityB, new EntityDesignData()));
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(entityC, new EntityDesignData()));
            baseAsset.Hierarchy.RootEntities.Add(entityA.Id);
            baseAsset.Hierarchy.RootEntities.Add(entityB.Id);
            baseAsset.Hierarchy.RootEntities.Add(entityC.Id);

            var baseAssetItem = new AssetItem("base", baseAsset);

            // Create new Base Asset
            var entityD = new Entity() { Name = "D" };
            var newBaseAsset = (EntityGroupAsset)AssetCloner.Clone(baseAsset);
            newBaseAsset.Hierarchy.Entities.Add(new EntityDesign(entityD, new EntityDesignData()));
            newBaseAsset.Hierarchy.RootEntities.Add(entityD.Id);

            // Create new Asset (from base)
            var newAsset = (EntityGroupAsset)baseAssetItem.CreateChildAsset();

            // Merge entities (NOTE: it is important to clone baseAsset/newBaseAsset)
            var result = newAsset.Merge((EntityGroupAssetBase)AssetCloner.Clone(baseAsset), (EntityGroupAssetBase)AssetCloner.Clone(newBaseAsset), null);
            Assert.False(result.HasErrors);

            // Both root and entities must be the same
            Assert.AreEqual(4, newAsset.Hierarchy.RootEntities.Count);
            Assert.AreEqual(4, newAsset.Hierarchy.Entities.Count);

            // All entities must have a base value
            Assert.True(newAsset.Hierarchy.Entities.All(item => item.Design.BaseId.HasValue));

            var entityAInNewAsset = newAsset.Hierarchy.Entities.Where(item => item.Design.BaseId.Value == entityA.Id).Select(item => item.Entity).FirstOrDefault();
            Assert.NotNull(entityAInNewAsset);
            var entityBInNewAsset = newAsset.Hierarchy.Entities.Where(item => item.Design.BaseId.Value == entityB.Id).Select(item => item.Entity).FirstOrDefault();
            Assert.NotNull(entityBInNewAsset);
            var entityCInNewAsset = newAsset.Hierarchy.Entities.Where(item => item.Design.BaseId.Value == entityC.Id).Select(item => item.Entity).FirstOrDefault();
            Assert.NotNull(entityCInNewAsset);

            var entityDInNewAsset = newAsset.Hierarchy.Entities.Where(item => item.Design.BaseId.Value == entityD.Id).Select(item => item.Entity).FirstOrDefault();
            Assert.NotNull(entityDInNewAsset);

            // Hierarchy must be: EA, EB, EC, ED
            Assert.AreEqual(entityAInNewAsset.Id, newAsset.Hierarchy.RootEntities[0]);
            Assert.AreEqual(entityBInNewAsset.Id, newAsset.Hierarchy.RootEntities[1]);
            Assert.AreEqual(entityCInNewAsset.Id, newAsset.Hierarchy.RootEntities[2]);
            Assert.AreEqual(entityDInNewAsset.Id, newAsset.Hierarchy.RootEntities[3]);
        }
开发者ID:hsabaleuski,项目名称:paradox,代码行数:61,代码来源:TestEntityGroupAssetMerge.cs

示例4: TestMergeAddEntityWithLinks2

        public void TestMergeAddEntityWithLinks2()
        {
            // Test merging an EntityGroupAsset with a root entity EA, and 3 child entities
            // - Add a child entity to NewBase that has a link to an another entity + a link to the component of another entity
            //
            //       Base         NewBase                      NewAsset                  NewAsset (Merged)
            //                                                 
            //       EA           EA                           EA'(base: EA)             EA'(base: EA)
            //        |-EA1       |-EA1                        |-EA1'(base: EA1)         |-EA1'(base: EA1)
            //        |-EA2       |-EA2 + link EA4             |-EA2'(base: EA2)         |-EA2'(base: EA2) + link EA4'
            //        |-EA3       |-EA3                        |-EA3'(base: EA3)         |-EA3'(base: EA3)
            //                    |-EA4                                                  |-EA4'(base: EA4)
            //
            var eA = new Entity() { Name = "A" };
            var eA1 = new Entity() { Name = "A1" };
            var eA2 = new Entity() { Name = "A2" };
            var eA3 = new Entity() { Name = "A3" };
            eA.Transform.Children.Add(eA1.Transform);
            eA.Transform.Children.Add(eA2.Transform);
            eA.Transform.Children.Add(eA3.Transform);

            // Create Base Asset
            var baseAsset = new EntityGroupAsset();
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(eA, new EntityDesignData()));
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(eA1, new EntityDesignData()));
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(eA2, new EntityDesignData()));
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(eA3, new EntityDesignData()));
            baseAsset.Hierarchy.RootEntities.Add(eA.Id);

            var baseAssetItem = new AssetItem("base", baseAsset);

            // Create new Base Asset
            var newBaseAsset = (EntityGroupAsset)AssetCloner.Clone(baseAsset);
            var eA4 = new Entity() { Name = "A4" };
            var rootInNewBase = newBaseAsset.Hierarchy.Entities[newBaseAsset.Hierarchy.RootEntities.First()];

            var eA2InNewBaseTransform = rootInNewBase.Entity.Transform.Children.FirstOrDefault(item => item.Entity.Id == eA2.Id);
            Assert.NotNull(eA2InNewBaseTransform);

            // Add EA4 with link to EA1 entity and EA2 component
            var testComponent = new TestEntityComponent
            {
                EntityLink = eA4,
            };

            eA2InNewBaseTransform.Entity.Add(testComponent);
            newBaseAsset.Hierarchy.Entities.Add(new EntityDesign(eA4, new EntityDesignData()));
            rootInNewBase.Entity.Transform.Children.Add(eA4.Transform);

            // Create new Asset (from base)
            var newAsset = (EntityGroupAsset)baseAssetItem.CreateChildAsset();

            // Merge entities (NOTE: it is important to clone baseAsset/newBaseAsset)
            var result = newAsset.Merge((EntityGroupAssetBase)AssetCloner.Clone(baseAsset), (EntityGroupAssetBase)AssetCloner.Clone(newBaseAsset), null);
            Assert.False(result.HasErrors);

            Assert.AreEqual(1, newAsset.Hierarchy.RootEntities.Count);
            Assert.AreEqual(5, newAsset.Hierarchy.Entities.Count); // EA, EA1', EA2', EA3', EA4'

            var rootEntity = newAsset.Hierarchy.Entities[newAsset.Hierarchy.RootEntities.First()];

            Assert.AreEqual(4, rootEntity.Entity.Transform.Children.Count);

            var eA1Merged = rootEntity.Entity.Transform.Children[0].Entity;
            var eA2Merged = rootEntity.Entity.Transform.Children[1].Entity;
            var eA4Merged = rootEntity.Entity.Transform.Children[3].Entity;
            Assert.AreEqual("A1", eA1Merged.Name);
            Assert.AreEqual("A2", eA2Merged.Name);
            Assert.AreEqual("A3", rootEntity.Entity.Transform.Children[2].Entity.Name);
            Assert.AreEqual("A4", eA4Merged.Name);

            var testComponentMerged = eA2Merged.Get<TestEntityComponent>();
            Assert.NotNull(testComponentMerged);

            Assert.AreEqual(eA4Merged, testComponentMerged.EntityLink);
        }
开发者ID:hsabaleuski,项目名称:paradox,代码行数:76,代码来源:TestEntityGroupAssetMerge.cs

示例5: TestPackageAnalysis

        public void TestPackageAnalysis()
        {
            var package = new Package();

            var baseAsset = new TestDiffAsset() { Name = "Red", Value = 1 };
            var baseItem = new AssetItem("base", baseAsset);

            var childAsset = (TestDiffAsset)baseItem.CreateChildAsset();
            var childItem = new AssetItem("child", childAsset);

            var newBaseAsset = (TestDiffAsset)AssetCloner.Clone(baseAsset);
            newBaseAsset.Name = "Green";
            var newBaseItem = new AssetItem("base", newBaseAsset);

            package.Assets.Add(newBaseItem);
            package.Assets.Add(childItem);

            var session = new PackageSession();
            session.Packages.Add(package);

            var result = new LoggerResult();
            var analysis = new PackageAssetTemplatingAnalysis(package, result);
            analysis.Run();

            Assert.False(result.HasErrors);

            var assetModified = (TestDiffAsset)package.Assets.Find("child").Asset;
            Assert.AreEqual("Green", assetModified.Name);
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:29,代码来源:TestDiffTemplatingAndMerge.cs

示例6: TestMergeEntityWithChildren

        public void TestMergeEntityWithChildren()
        {
            // Test merging an EntityGroupAsset with a root entity EA, and 3 child entities
            // - Add a child entity to NewBase
            // - Remove a child entity from NewAsset
            //
            //       Base         NewBase       NewAsset                  NewAsset (Merged)
            // 
            //       EA           EA            EA'(base: EA)             EA'(base: EA)
            //        |-EA1       |-EA1         |-EA1'(base: EA1)         |-EA1'(base: EA1)
            //        |-EA2       |-EA2         |                         |
            //        |-EA3       |-EA3         |-EA3'(base: EA3)         |-EA3'(base: EA3)
            //                    |-EA4                                   |-EA4'(base: EA4)
            //

            var eA = new Entity() { Name = "A" };
            var eA1 = new Entity() { Name = "A1" };
            var eA2 = new Entity() { Name = "A2" };
            var eA3 = new Entity() { Name = "A3" };
            eA.Transform.Children.Add(eA1.Transform);
            eA.Transform.Children.Add(eA2.Transform);
            eA.Transform.Children.Add(eA3.Transform);

            // Create Base Asset
            var baseAsset = new EntityGroupAsset();
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(eA, new EntityDesignData()));
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(eA1, new EntityDesignData()));
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(eA2, new EntityDesignData()));
            baseAsset.Hierarchy.Entities.Add(new EntityDesign(eA3, new EntityDesignData()));
            baseAsset.Hierarchy.RootEntities.Add(eA.Id);

            var baseAssetItem = new AssetItem("base", baseAsset);

            // Create new Base Asset
            var newBaseAsset = (EntityGroupAsset)AssetCloner.Clone(baseAsset);
            var eA2FromNewBase = newBaseAsset.Hierarchy.Entities.First(item => item.Entity.Id == eA2.Id);
            newBaseAsset.Hierarchy.Entities[eA.Id].Entity.Transform.Children.Remove(eA2FromNewBase.Entity.Transform);

            // Create new Asset (from base)
            var newAsset = (EntityGroupAsset)baseAssetItem.CreateChildAsset();
            var eA4 = new Entity() { Name = "A4" };
            newAsset.Hierarchy.Entities.Add(new EntityDesign(eA4, new EntityDesignData()));
            newAsset.Hierarchy.Entities[newAsset.Hierarchy.RootEntities.First()].Entity.Transform.Children.Add(eA4.Transform);

            // Merge entities (NOTE: it is important to clone baseAsset/newBaseAsset)
            var result = newAsset.Merge((EntityGroupAssetBase)AssetCloner.Clone(baseAsset), (EntityGroupAssetBase)AssetCloner.Clone(newBaseAsset), null);
            Assert.False(result.HasErrors);

            Assert.AreEqual(1, newAsset.Hierarchy.RootEntities.Count);
            Assert.AreEqual(4, newAsset.Hierarchy.Entities.Count); // EA, EA1', EA3', EA4'

            var rootEntity = newAsset.Hierarchy.Entities[newAsset.Hierarchy.RootEntities.First()];

            Assert.AreEqual(3, rootEntity.Entity.Transform.Children.Count);

            Assert.AreEqual("A1", rootEntity.Entity.Transform.Children[0].Entity.Name);
            Assert.AreEqual("A3", rootEntity.Entity.Transform.Children[1].Entity.Name);
            Assert.AreEqual("A4", rootEntity.Entity.Transform.Children[2].Entity.Name);
        }
开发者ID:hsabaleuski,项目名称:paradox,代码行数:59,代码来源:TestEntityGroupAssetMerge.cs

示例7: TestListWithIdsChangeType

        public void TestListWithIdsChangeType()
        {
            var baseAsset = new TestDiffAsset() { Name = "Red", Value = 1 };
            baseAsset.List.Add(new DiffComponent() { Name = "Test1", Position = new Vector4(1, 0, 0, 0) });
            baseAsset.List.Add(new DiffComponent() { Name = "Test2", Position = new Vector4(1, 0, 0, 0) });
            baseAsset.List.Add(new DiffComponent() { Name = "Test3", Position = new Vector4(1, 0, 0, 0) });

            // Change type of 2nd element in newBase list
            var newBaseAsset = (TestDiffAsset)AssetCloner.Clone(baseAsset);
            newBaseAsset.List[1] = new DiffComponentSub() { Value = 1 };

            var baseItem = new AssetItem("/base", baseAsset);

            var childAsset = (TestDiffAsset)baseItem.CreateChildAsset();

            var diff = new AssetDiff(baseAsset, childAsset, newBaseAsset) { UseOverrideMode = true };
            var diffResult = diff.Compute();

            var diffList = diffResult.Members.First(node => ((DataVisitMember)node.Asset1Node).MemberDescriptor.Name == "List");

            // Check that we have only 3 items
            Assert.AreEqual(3, diffList.Items.Count);
            Assert.AreEqual(Diff3ChangeType.MergeFromAsset2, diffList.Items[1].ChangeType);

            var mergeResult = AssetMerge.Merge(diff, AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1);
            Assert.False(mergeResult.HasErrors);

            Assert.AreEqual(3, childAsset.List.Count);
            Assert.AreEqual("Test1", childAsset.List[0].Name);
            Assert.True(childAsset.List[1] is DiffComponentSub);
            Assert.AreEqual("Test3", childAsset.List[2].Name);
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:32,代码来源:TestDiffTemplatingAndMerge.cs

示例8: TestListDiffWithIdsOrderChanged

        public void TestListDiffWithIdsOrderChanged()
        {
            var baseAsset = new TestDiffAsset() { Name = "Red", Value = 1 };
            baseAsset.List.Add(new DiffComponent() { Name = "Test1", Position = new Vector4(1, 0, 0, 0) });
            baseAsset.List.Add(new DiffComponent() { Name = "Test2", Position = new Vector4(1, 0, 0, 0) });
            baseAsset.List.Add(new DiffComponent() { Name = "Test3", Position = new Vector4(1, 0, 0, 0) });

            var newBaseAsset = (TestDiffAsset)AssetCloner.Clone(baseAsset);

            var baseItem = new AssetItem("/base", baseAsset);

            var childAsset = (TestDiffAsset)baseItem.CreateChildAsset();

            // Swap elements in child asset
            var temp = childAsset.List[0];
            childAsset.List[0] = childAsset.List[1];
            childAsset.List[1] = temp;
            childAsset.List[0].Name = "Test21";

            // Make New on Name value on first element
            var objDesc = TypeDescriptorFactory.Default.Find(typeof(DiffComponent));
            var memberDesc = objDesc.Members.First(t => t.Name == "Name");
            childAsset.List[0].SetOverride(memberDesc, OverrideType.New);

            // Perform the diff
            var diff = new AssetDiff(baseAsset, childAsset, newBaseAsset) { UseOverrideMode = true };

            var diffResult = diff.Compute();

            var diffResultStripped = diffResult.FindLeafDifferences().ToList();

            // Expecting only one field to be merged from asset1 (the new on Name property)
            var mergeFromAsset1 = diffResultStripped.Where(item => item.ChangeType == Diff3ChangeType.MergeFromAsset1).ToList();
            Assert.AreEqual(1, mergeFromAsset1.Count);
            var nameMember = mergeFromAsset1[0].Asset1Node as DataVisitMember;
            Assert.NotNull(nameMember);
            Assert.AreEqual("Name", nameMember.MemberDescriptor.Name);

            // Check that DiffComponent are swapped for Asset1 but diff is able to recover this
            foreach (var node in diffResultStripped.Where(item => item.BaseNode.Parent.Instance is DiffComponent))
            {
                var base1 = (DiffComponent)node.BaseNode.Parent.Instance;
                var asset1 = (DiffComponent)node.Asset1Node.Parent.Instance;
                var asset2 = (DiffComponent)node.Asset2Node.Parent.Instance;

                var baseIndex = baseAsset.List.IndexOf(base1);
                var asset1Index = childAsset.List.IndexOf(asset1);
                var asset2Index = newBaseAsset.List.IndexOf(asset2);

                Assert.AreEqual(baseIndex, asset2Index);
                switch (baseIndex)
                {
                    // element 0 and 1 are swapped
                    case 0:
                        Assert.AreEqual(1, asset1Index);
                        break;
                    case 1:
                        Assert.AreEqual(0, asset1Index);
                        break;
                    default:
                        Assert.AreEqual(baseIndex, asset1Index);
                        break;
                }
            }
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:65,代码来源:TestDiffTemplatingAndMerge.cs

示例9: TestListWithIdsNoConflicts

        public void TestListWithIdsNoConflicts()
        {
            var baseAsset = new TestDiffAsset() { Name = "Red", Value = 1 };
            baseAsset.List.Add(new DiffComponent() { Name=  "Test1", Position = new Vector4(1, 0, 0, 0)});
            baseAsset.List.Add(new DiffComponent() { Name = "Test2", Position = new Vector4(1, 0, 0, 0) });
            baseAsset.List.Add(new DiffComponent() { Name = "Test3", Position = new Vector4(1, 0, 0, 0) });

            var newBaseAsset = (TestDiffAsset)AssetCloner.Clone(baseAsset);

            var baseItem = new AssetItem("/base", baseAsset);

            var childAsset = (TestDiffAsset)baseItem.CreateChildAsset();

            var diff = new AssetDiff(baseAsset, childAsset, newBaseAsset) { UseOverrideMode = true };

            var diffResult = diff.Compute();

            var diffResultStripped = diffResult.FindLeafDifferences().ToList();

            // Expecting only 2 diff from TestDiffAsset (3 properties + BuildOrder)
            Assert.AreEqual(4, diffResultStripped.Where(item => item.BaseNode.Parent?.Instance is TestDiffAsset).Count());

            // Expecting 6 diffs for DiffComponent (3 elements, 5 properties (Name + Vector4))
            Assert.AreEqual(3 * 5, diffResultStripped.Where(item => item.BaseNode.Parent?.Instance is DiffComponent || item.BaseNode.Parent?.Parent?.Instance is DiffComponent).Count());

            // All changes must be from asset2 (considered as new base), as everything is setting base
            Assert.True(diffResultStripped.All(item => item.ChangeType == Diff3ChangeType.MergeFromAsset2));

            foreach (var node in diffResultStripped.Where(item => item.BaseNode.Parent.Instance is DiffComponent))
            {
                var base1 = (DiffComponent)node.BaseNode.Parent.Instance;
                var asset1 = (DiffComponent)node.Asset1Node.Parent.Instance;
                var asset2 = (DiffComponent)node.Asset2Node.Parent.Instance;

                var baseIndex = baseAsset.List.IndexOf(base1);
                var asset1Index = childAsset.List.IndexOf(asset1);
                var asset2Index = newBaseAsset.List.IndexOf(asset2);

                Assert.AreEqual(baseIndex, asset1Index);
                Assert.AreEqual(baseIndex, asset2Index);
            }
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:42,代码来源:TestDiffTemplatingAndMerge.cs

示例10: TestChangeOverrideToBaseSealed

        public void TestChangeOverrideToBaseSealed()
        {
            var baseAsset = new TestDiffAsset() { Name = "Red", Value = 1 };
            var newBaseAsset = (TestDiffAsset)AssetCloner.Clone(baseAsset);
            newBaseAsset.Value = 3;

            var baseItem = new AssetItem("/base", baseAsset);
            var childAsset = (TestDiffAsset)baseItem.CreateChildAsset();

            // Change base: Name to Base|Sealed
            // This should result into a reset of the value overriden in child

            // Make New on Name value on first element
            var objDesc = TypeDescriptorFactory.Default.Find(typeof(TestDiffAsset));
            var memberDesc = objDesc.Members.First(t => t.Name == "Value");
            newBaseAsset.SetOverride(memberDesc, OverrideType.Base|OverrideType.Sealed);

            var diff = new AssetDiff(baseAsset, childAsset, newBaseAsset) { UseOverrideMode = true };

            var diffResult = diff.Compute();

            // Check that merged result on Dynamic property is instance from asset2
            var mergeResult = AssetMerge.Merge(diff, AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1);
            Assert.AreEqual(3, childAsset.Value); // Value is coming from base
            Assert.AreEqual(OverrideType.Base|OverrideType.Sealed, childAsset.GetOverride(memberDesc)); // Value is coming from base
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:26,代码来源:TestDiffTemplatingAndMerge.cs

示例11: TestWithNewTypeFromChild

        public void TestWithNewTypeFromChild()
        {
            var baseAsset = new TestDiffAsset() { Name = "Red", Value = 1, Dynamic = new DiffValueTypeA() { Text = "Test1" } };
            var newBaseAsset = (TestDiffAsset)AssetCloner.Clone(baseAsset);

            var baseItem = new AssetItem("/base", baseAsset);
            var childAsset = (TestDiffAsset)baseItem.CreateChildAsset();

            // Make New on Name value on first element
            var objDesc = TypeDescriptorFactory.Default.Find(typeof(TestDiffAsset));
            var memberDesc = objDesc.Members.First(t => t.Name == "Dynamic");
            childAsset.SetOverride(memberDesc, OverrideType.New); // Override Dynamic and change type
            childAsset.Dynamic = new DiffValueTypeB() { Value = 2 };

            var diff = new AssetDiff(baseAsset, childAsset, newBaseAsset) { UseOverrideMode = true };

            var diffResult = diff.Compute();

            var diffResultStripped = diffResult.FindLeafDifferences().ToList();

            // Check at least one field has merge from asset 1 (Dynamic)
            Assert.True(diffResultStripped.Any(node => node.ChangeType == Diff3ChangeType.MergeFromAsset1));

            // Check that merged result on Dynamic property is instance from asset2
            var mergeResult = AssetMerge.Merge(diff, AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1);
            Assert.True(childAsset.Dynamic is DiffValueTypeB);
            Assert.AreEqual(2, ((DiffValueTypeB)childAsset.Dynamic).Value);
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:28,代码来源:TestDiffTemplatingAndMerge.cs

示例12: TestWithNewTypeFromNewBase

        public void TestWithNewTypeFromNewBase()
        {
            var baseAsset = new TestDiffAsset() { Name = "Red", Value = 1, Dynamic = new DiffValueTypeA() { Text = "Test1"} };
            var newBaseAsset = (TestDiffAsset)AssetCloner.Clone(baseAsset);
            newBaseAsset.Dynamic = new DiffValueTypeB() { Value = 1 };

            var baseItem = new AssetItem("/base", baseAsset);
            var childAsset = (TestDiffAsset)baseItem.CreateChildAsset();

            var diff = new AssetDiff(baseAsset, childAsset, newBaseAsset) { UseOverrideMode = true };

            var diffResult = diff.Compute();

            var diffResultStripped = diffResult.FindLeafDifferences().ToList();

            // Check that everything is merging from asset2
            Assert.True(diffResultStripped.All(node => node.ChangeType == Diff3ChangeType.MergeFromAsset2));

            // Check that merged result on Dynamic property is instance from asset2
            var mergeResult = AssetMerge.Merge(diff, AssetMergePolicies.MergePolicyAsset2AsNewBaseOfAsset1);
            Assert.True(childAsset.Dynamic is DiffValueTypeB);
            Assert.AreEqual(1, ((DiffValueTypeB)childAsset.Dynamic).Value);
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:23,代码来源:TestDiffTemplatingAndMerge.cs

示例13: TestNoChanges

        public void TestNoChanges()
        {
            var baseAsset = new TestDiffAsset() { Name = "Red", Value = 1, Dynamic = new DiffValueTypeA() { Text = "Test1" } };
            var newBaseAsset = (TestDiffAsset)AssetCloner.Clone(baseAsset);
            var baseItem = new AssetItem("/base", baseAsset);
            var childAsset = (TestDiffAsset)baseItem.CreateChildAsset();

            var diff = new AssetDiff(baseAsset, childAsset, newBaseAsset) { UseOverrideMode = true };

            var diffResult = diff.Compute();

            var diffResultStripped = diffResult.FindLeafDifferences().ToList();

            // 6: BuildOrder+Name+Value+(Dynamic: Text+Text2+Text3)
            Assert.AreEqual(6, diffResultStripped.Count);

            // Check that everything is merging from asset2
            Assert.True(diffResultStripped.All(node => node.ChangeType == Diff3ChangeType.MergeFromAsset2));
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:19,代码来源:TestDiffTemplatingAndMerge.cs


注:本文中的AssetItem.CreateChildAsset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。