コード例 #1
0
ファイル: TestAssetCollision.cs プロジェクト: glepag1/stride
        public void TestWithPackage()
        {
            var inputs = new List <AssetItem>();

            var asset = new AssetObjectTest();

            var package = new Package();

            package.Assets.Add(new AssetItem("0", asset));
            var session = new PackageSession(package);

            for (int i = 0; i < 10; i++)
            {
                var newAsset = new AssetObjectTest()
                {
                    Id = asset.Id, Reference = new AssetReference(asset.Id, "bad")
                };
                inputs.Add(new AssetItem("0", newAsset));
            }

            // Tries to use existing ids
            var outputs = new List <AssetItem>();

            AssetCollision.Clean(null, inputs, outputs, AssetResolver.FromPackage(package), true, false);

            // Make sure we are generating exactly the same number of elements
            Assert.Equal(inputs.Count, outputs.Count);

            // Make sure that asset has been cloned
            Assert.NotEqual(inputs[0], outputs[0]);

            // First Id should not change
            Assert.NotEqual(inputs[0].Id, outputs[0].Id);

            // Make sure that all ids are different
            var ids = new HashSet <AssetId>(outputs.Select(item => item.Id));

            Assert.Equal(inputs.Count, ids.Count);

            // Make sure that all locations are different
            var locations = new HashSet <UFile>(outputs.Select(item => item.Location));

            Assert.Equal(inputs.Count, locations.Count);

            // Reference location "bad"should be fixed to "0_1" pointing to the first element
            foreach (var output in outputs)
            {
                // Make sure of none of the locations are using "0"
                Assert.NotEqual((UFile)"0", output.Location);

                var assetRef = ((AssetObjectTest)output.Asset).Reference;
                Assert.Equal("0 (2)", assetRef.Location);
                Assert.Equal(outputs[0].Id, assetRef.Id);
            }
        }
コード例 #2
0
        public void TestMoveAssetWithUFile()
        {
            var projectDir   = new UFile(Path.Combine(Environment.CurrentDirectory, "testxk"));
            var rawAssetPath = new UFile("../image.png");
            var assetPath    = new UFile("sub1/sub2/test");

            // Create a project with an asset reference a raw file
            var project = new Package {
                FullPath = projectDir
            };

            project.AssetFolders.Clear();
            project.AssetFolders.Add(new AssetFolder("."));
            var asset = new AssetObjectTest()
            {
                RawAsset = new UFile(rawAssetPath)
            };
            var assetItem = new AssetItem(assetPath, asset);

            project.Assets.Add(assetItem);

            // Run an asset reference analysis on this project
            var analysis = new PackageAnalysis(project,
                                               new PackageAnalysisParameters()
            {
                ConvertUPathTo     = UPathType.Absolute,
                IsProcessingUPaths = true
            });
            var result = analysis.Run();

            Assert.False(result.HasErrors);
            Assert.Equal(UPath.Combine(project.RootDirectory, new UFile("sub1/image.png")), asset.RawAsset);

            project.Assets.Remove(assetItem);
            assetItem = new AssetItem("sub1/test", asset);
            project.Assets.Add(assetItem);
            result = analysis.Run();
            Assert.False(result.HasErrors);
            Assert.Equal(UPath.Combine(project.RootDirectory, new UFile("sub1/image.png")), asset.RawAsset);

            project.Assets.Remove(assetItem);
            assetItem = new AssetItem("test", asset);
            project.Assets.Add(assetItem);
            result = analysis.Run();
            Assert.False(result.HasErrors);
            Assert.Equal(UPath.Combine(project.RootDirectory, new UFile("sub1/image.png")), asset.RawAsset);

            analysis.Parameters.ConvertUPathTo = UPathType.Relative;
            result = analysis.Run();
            Assert.False(result.HasErrors);
            Assert.Equal(new UFile("sub1/image.png"), asset.RawAsset);
        }
コード例 #3
0
        public void TestSimpleNewGuids()
        {
            var inputs = new List <AssetItem>();

            var asset = new AssetObjectTest();

            for (int i = 0; i < 10; i++)
            {
                var newAsset = new AssetObjectTest()
                {
                    Id = asset.Id, Reference = new AssetReference(asset.Id, "bad")
                };
                inputs.Add(new AssetItem("0", newAsset));
            }

            // Force to use new ids
            var outputs = new List <AssetItem>();

            AssetCollision.Clean(null, inputs, outputs, new AssetResolver()
            {
                AlwaysCreateNewId = true
            }, true, false);

            // Make sure we are generating exactly the same number of elements
            Assert.Equal(inputs.Count, outputs.Count);

            // Make sure that asset has been cloned
            Assert.NotEqual(inputs[0], outputs[0]);

            // First Id should not change
            Assert.NotEqual(inputs[0].Id, outputs[0].Id);

            // Make sure that all ids are different
            var ids = new HashSet <AssetId>(outputs.Select(item => item.Id));

            Assert.Equal(inputs.Count, ids.Count);

            // Make sure that all locations are different
            var locations = new HashSet <UFile>(outputs.Select(item => item.Location));

            Assert.Equal(inputs.Count, locations.Count);

            // Reference location "bad"should be fixed to "0"
            foreach (var output in outputs)
            {
                var assetRef = ((AssetObjectTest)output.Asset).Reference;
                Assert.Equal("0", assetRef.Location);
                Assert.Equal(outputs[0].Id, assetRef.Id);
            }
        }
コード例 #4
0
ファイル: TestSerializing.cs プロジェクト: Beefr/xenko-wd
        public void TestAssetItemCollection()
        {
            // Test serialization of asset items.

            var inputs = new List <AssetItem>();

            for (int i = 0; i < 10; i++)
            {
                var newAsset = new AssetObjectTest()
                {
                    Name = "Test" + i
                };
                inputs.Add(new AssetItem("" + i, newAsset));
            }

            var asText  = ToText(inputs);
            var outputs = FromText(asText);

            Assert.Equal(inputs.Select(item => item.Location), outputs.Select(item => item.Location));
            Assert.Equal(inputs.Select(item => item.Asset), outputs.Select(item => item.Asset));
        }
コード例 #5
0
        public void TestUpdateAssetUrl()
        {
            var projectDir = new UFile(Path.Combine(Environment.CurrentDirectory, "testxk"));

            // Create a project with an asset reference a raw file
            var project = new Package {
                FullPath = projectDir
            };
            var assetItem = new AssetItem("test", new AssetObjectTest()
            {
                Reference = new AssetReference(AssetId.Empty, "good/location")
            });

            project.Assets.Add(assetItem);
            var goodAsset = new AssetObjectTest();

            project.Assets.Add(new AssetItem("good/location", goodAsset));

            // Add the project to the session to make sure analysis will run correctly
            var session = new PackageSession(project);

            // Create a session with this project
            var analysis = new PackageAnalysis(project,
                                               new PackageAnalysisParameters()
            {
                IsProcessingAssetReferences = true,
                ConvertUPathTo     = UPathType.Absolute,
                IsProcessingUPaths = true
            });
            var result = analysis.Run();

            Assert.False(result.HasErrors);
            Assert.Equal(1, result.Messages.Count);
            Assert.True(result.Messages[0].ToString().Contains("changed"));

            var asset = (AssetObjectTest)assetItem.Asset;

            Assert.Equal(goodAsset.Id, asset.Reference.Id);
            Assert.Equal("good/location", asset.Reference.Location);
        }