Bläddra i källkod

tests reorganization

Vicente Penades 6 år sedan
förälder
incheckning
b7fb480077

+ 3 - 3
tests/SharpGLTF.Tests/Geometry/LoadMeshTests.cs

@@ -15,7 +15,7 @@ namespace SharpGLTF.Geometry
         [OneTimeSetUp]
         [OneTimeSetUp]
         public void Setup()
         public void Setup()
         {
         {
-            TestFiles.CheckoutDataDirectories();
+            TestFiles.DownloadReferenceModels();
         }
         }
 
 
         #endregion
         #endregion
@@ -23,7 +23,7 @@ namespace SharpGLTF.Geometry
         [Test]
         [Test]
         public void LoadModels()
         public void LoadModels()
         {
         {
-            foreach (var f in TestFiles.GetSampleFilePaths())
+            foreach (var f in TestFiles.GetSampleModelsPaths())
             {
             {
                 var root = GltfUtils.LoadModel(f);
                 var root = GltfUtils.LoadModel(f);
                 Assert.NotNull(root);
                 Assert.NotNull(root);
@@ -33,7 +33,7 @@ namespace SharpGLTF.Geometry
         [Test]
         [Test]
         public void LoadBrokenFile()
         public void LoadBrokenFile()
         {
         {
-            var f = TestFiles.GetSampleFilePaths().First(item => item.EndsWith(".gltf"));
+            var f = TestFiles.GetSampleModelsPaths().First(item => item.EndsWith(".gltf"));
 
 
             var json = System.IO.File.ReadAllText(f);
             var json = System.IO.File.ReadAllText(f);
 
 

+ 2 - 2
tests/SharpGLTF.Tests/Schema2/AccessorSparseTests.cs

@@ -15,7 +15,7 @@ namespace SharpGLTF.Schema2
         [OneTimeSetUp]
         [OneTimeSetUp]
         public void Setup()
         public void Setup()
         {
         {
-            TestFiles.CheckoutDataDirectories();
+            TestFiles.DownloadReferenceModels();
         }
         }
 
 
         #endregion
         #endregion
@@ -23,7 +23,7 @@ namespace SharpGLTF.Schema2
         [Test]
         [Test]
         public void TestLoadSparseModel()
         public void TestLoadSparseModel()
         {
         {
-            var path = TestFiles.GetSampleFilePaths().FirstOrDefault(item => item.Contains("SimpleSparseAccessor.gltf"));
+            var path = TestFiles.GetSampleModelsPaths().FirstOrDefault(item => item.Contains("SimpleSparseAccessor.gltf"));
             
             
             var model = ModelRoot.Load(path);
             var model = ModelRoot.Load(path);
             Assert.NotNull(model);
             Assert.NotNull(model);

+ 65 - 0
tests/SharpGLTF.Tests/Schema2/LoadAndSave/LoadGeneratedTests.cs

@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using NUnit.Framework;
+
+namespace SharpGLTF.Schema2.LoadAndSave
+{
+    /// <summary>
+    /// Test cases for models found in <see href="https://github.com/bghgary/glTF-Asset-Generator"/>
+    /// </summary>
+    [TestFixture]
+    public class LoadGeneratedTests
+    {
+        #region setup
+
+        [OneTimeSetUp]
+        public void Setup()
+        {
+            TestFiles.DownloadReferenceModels();
+        }
+
+        #endregion        
+
+        [Test]
+        public void TestLoadReferenceModels()
+        {
+            TestContext.CurrentContext.AttachShowDirLink();
+
+            var files = TestFiles.GetReferenceModelPaths();
+
+            foreach (var f in files)
+            {
+                // var errors = _LoadNumErrorsForModel(f);
+                // if (errors > 0) continue;
+
+                try
+                {
+                    var model = ModelRoot.Load(f);
+                    model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".obj"));
+                }
+                catch (IO.UnsupportedExtensionException eex)
+                {
+                    TestContext.WriteLine($"{f.ToShortDisplayPath()} ERROR: {eex.Message}");
+                }
+            }
+        }        
+
+        private static int _LoadNumErrorsForModel(string gltfPath)
+        {
+            var dir = System.IO.Path.GetDirectoryName(gltfPath);
+            var fn = System.IO.Path.GetFileNameWithoutExtension(gltfPath);
+
+            var jsonPath = System.IO.Path.Combine(dir, "ValidatorResults", System.IO.Path.ChangeExtension(fn, "json"));
+
+            var content = System.IO.File.ReadAllText(jsonPath);
+            var doc = Newtonsoft.Json.Linq.JObject.Parse(content);
+
+            var token = doc.SelectToken("issues").SelectToken("numErrors");
+
+            return (int)token;
+        }
+    }
+}

+ 0 - 258
tests/SharpGLTF.Tests/Schema2/LoadAndSave/LoadModelTests.cs

@@ -1,258 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-using NUnit.Framework;
-
-namespace SharpGLTF.Schema2.LoadAndSave
-{
-    [TestFixture]
-    public class LoadModelTests
-    {
-        #region setup
-
-        [OneTimeSetUp]
-        public void Setup()
-        {
-            TestFiles.CheckoutDataDirectories();
-        }
-
-        #endregion
-
-        #region testing models of https://github.com/bghgary/glTF-Asset-Generator.git
-
-        [Test]
-        public void TestLoadReferenceModels()
-        {
-            TestContext.CurrentContext.AttachShowDirLink();
-
-            var files = TestFiles.GetGeneratedFilePaths();
-
-            foreach (var f in files)
-            {
-                var errors = _LoadNumErrorsForModel(f);
-
-                if (errors > 0) continue;
-
-                try
-                {
-                    var model = ModelRoot.Load(f);
-                    model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".obj"));
-                }
-                catch (IO.UnsupportedExtensionException eex)
-                {
-                    TestContext.WriteLine($"{f.ToShortDisplayPath()} ERROR: {eex.Message}");
-                }
-            }
-        }
-
-        // right now this test does not make much sense...
-        // [Test]
-        public void TestLoadInvalidModels()
-        {
-            TestContext.CurrentContext.AttachShowDirLink();
-
-            var files = TestFiles.GetGeneratedFilePaths();
-
-            bool passed = true;
-
-            foreach (var f in files)
-            {
-                var errors = _LoadNumErrorsForModel(f);
-
-                if (errors == 0) continue;
-                
-                try
-                {
-                    var model = GltfUtils.LoadModel(f);
-                    passed = false;
-
-                    TestContext.WriteLine($"FAILED {f.ToShortDisplayPath()}");
-                }
-                catch (Exception ex)
-                {
-                    TestContext.WriteLine($"PASSED {f.ToShortDisplayPath()}");
-                }                
-            }
-
-            Assert.IsTrue(passed);
-        }
-
-        private static int _LoadNumErrorsForModel(string gltfPath)
-        {
-            var dir = System.IO.Path.GetDirectoryName(gltfPath);
-            var fn = System.IO.Path.GetFileNameWithoutExtension(gltfPath);
-
-            var jsonPath = System.IO.Path.Combine(dir, "ValidatorResults", System.IO.Path.ChangeExtension(fn, "json"));
-
-            var content = System.IO.File.ReadAllText(jsonPath);
-            var doc = Newtonsoft.Json.Linq.JObject.Parse(content);
-
-            var token = doc.SelectToken("issues").SelectToken("numErrors");
-
-            return (int)token;
-        }
-        
-        #endregion
-
-        #region testing models of https://github.com/KhronosGroup/glTF-Sample-Models.git
-
-        [TestCase("\\glTF\\")]
-        // [TestCase("\\glTF-Draco\\")] // Not supported
-        [TestCase("\\glTF-IBL\\")]
-        [TestCase("\\glTF-Binary\\")]
-        [TestCase("\\glTF-Embedded\\")]
-        [TestCase("\\glTF-pbrSpecularGlossiness\\")]
-        public void TestLoadSampleModels(string section)
-        {
-            TestContext.CurrentContext.AttachShowDirLink();
-            TestContext.CurrentContext.AttachGltfValidatorLink();
-
-            foreach (var f in TestFiles.GetSampleFilePaths())
-            {
-                if (!f.Contains(section)) continue;
-
-                var model = GltfUtils.LoadModel(f);
-                Assert.NotNull(model);
-
-                // evaluate and save all the triangles to a Wavefront Object
-                model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".obj"));
-                model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".glb"));
-                
-                // do a model clone and compare it
-                _AssertAreEqual(model, model.DeepClone());
-
-                // check extensions used
-                if (!model.ExtensionsUsed.Contains("EXT_lights_image_based"))
-                {
-                    var detectedExtensions = model.RetrieveUsedExtensions().ToArray();
-                    CollectionAssert.AreEquivalent(model.ExtensionsUsed, detectedExtensions);
-                }
-            }
-        }
-
-        private static void _AssertAreEqual(ModelRoot a, ModelRoot b)
-        {
-            var aa = a.GetLogicalChildrenFlattened().ToList();
-            var bb = b.GetLogicalChildrenFlattened().ToList();
-
-            Assert.AreEqual(aa.Count,bb.Count);
-
-            CollectionAssert.AreEqual
-                (
-                aa.Select(item => item.GetType()),
-                bb.Select(item => item.GetType())
-                );
-        }
-
-        [TestCase("SpecGlossVsMetalRough.gltf")]
-        [TestCase(@"UnlitTest\glTF-Binary\UnlitTest.glb")]
-        public void TestLoadSpecialCaseModels(string filePath)
-        {
-            TestContext.CurrentContext.AttachShowDirLink();
-            TestContext.CurrentContext.AttachGltfValidatorLink();
-
-            var f = TestFiles.GetSampleFilePaths()
-                .FirstOrDefault(item => item.EndsWith(filePath));
-
-            var model = GltfUtils.LoadModel(f);
-            Assert.NotNull(model);
-
-            // evaluate and save all the triangles to a Wavefront Object
-            model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".obj"));
-            model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".glb"));
-            model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".gltf"));
-
-            // do a model roundtrip
-            var bytes = model.WriteGLB();
-            var modelBis = ModelRoot.ParseGLB(bytes);
-
-            // clone
-            var cloned = model.DeepClone();
-        }
-
-        [Test]
-        public void TestLoadUnlitModel()
-        {
-            var f = TestFiles.GetSampleFilePaths()
-                .FirstOrDefault(item => item.EndsWith(@"UnlitTest\glTF-Binary\UnlitTest.glb"));
-
-            var model = GltfUtils.LoadModel(f);
-            Assert.NotNull(model);
-
-            Assert.IsTrue(model.LogicalMaterials[0].Unlit);
-
-            // do a model roundtrip
-            var modelBis = ModelRoot.ParseGLB(model.WriteGLB());
-            Assert.NotNull(modelBis);
-
-            Assert.IsTrue(modelBis.LogicalMaterials[0].Unlit);
-        }
-
-        [Test]
-        public void TestLoadLightsModel()
-        {
-            var f = TestFiles.GetSchemaFilePaths()
-                .FirstOrDefault(item => item.EndsWith("lights.gltf"));
-
-            var model = GltfUtils.LoadModel(f);
-            Assert.NotNull(model);
-
-            Assert.AreEqual(3, model.LogicalPunctualLights.Count);
-
-            Assert.AreEqual(1, model.DefaultScene.VisualChildren.ElementAt(0).PunctualLight.LogicalIndex);
-            Assert.AreEqual(0, model.DefaultScene.VisualChildren.ElementAt(1).PunctualLight.LogicalIndex);
-        }
-
-        #endregion
-
-        #region testing polly model
-
-        [Test(Description ="Example of traversing the visual tree all the way to individual vertices and indices")]
-        public void TestLoadPolly()
-        {
-            TestContext.CurrentContext.AttachShowDirLink();
-            
-            // load Polly model
-            var model = GltfUtils.LoadModel( TestFiles.GetPollyFilePath() );
-
-            Assert.NotNull(model);            
-
-            // Save as GLB, and also evaluate all triangles and save as Wavefront OBJ            
-            model.AttachToCurrentTest("polly_out.glb");
-            model.AttachToCurrentTest("polly_out.obj");
-
-            // hierarchically browse some elements of the model:
-
-            var scene = model.DefaultScene;
-
-            var pollyNode = scene.FindNode("Polly_Display");            
-
-            var pollyPrimitive = pollyNode.Mesh.Primitives[0];
-
-            var pollyIndices = pollyPrimitive.GetIndices();
-            var pollyPositions = pollyPrimitive.GetVertices("POSITION").AsVector3Array();
-            var pollyNormals = pollyPrimitive.GetVertices("NORMAL").AsVector3Array();
-
-            for (int i=0; i < pollyIndices.Count; i+=3)
-            {
-                var a = (int)pollyIndices[i + 0];
-                var b = (int)pollyIndices[i + 1];
-                var c = (int)pollyIndices[i + 2];
-
-                var ap = pollyPositions[a];
-                var bp = pollyPositions[b];
-                var cp = pollyPositions[c];
-
-                var an = pollyNormals[a];
-                var bn = pollyNormals[b];
-                var cn = pollyNormals[c];
-
-                TestContext.WriteLine($"Triangle {ap} {an} {bp} {bn} {cp} {cn}");
-            }
-        }
-
-        #endregion        
-    }
-}

+ 69 - 0
tests/SharpGLTF.Tests/Schema2/LoadAndSave/LoadPollyTest.cs

@@ -0,0 +1,69 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using NUnit.Framework;
+
+namespace SharpGLTF.Schema2.LoadAndSave
+{
+    /// <summary>
+    /// Test cases for models found in <see href="https://github.com/KhronosGroup/glTF-Blender-Exporter"/>
+    /// </summary>
+    [TestFixture]
+    public class LoadPollyTest
+    {
+        #region setup
+
+        [OneTimeSetUp]
+        public void Setup()
+        {
+            TestFiles.DownloadReferenceModels();
+        }
+
+        #endregion
+
+        [Test(Description = "Example of traversing the visual tree all the way to individual vertices and indices")]
+        public void TestLoadPolly()
+        {
+            TestContext.CurrentContext.AttachShowDirLink();
+
+            // load Polly model
+            var model = GltfUtils.LoadModel(TestFiles.GetPollyFileModelPath());
+
+            Assert.NotNull(model);
+
+            // Save as GLB, and also evaluate all triangles and save as Wavefront OBJ            
+            model.AttachToCurrentTest("polly_out.glb");
+            model.AttachToCurrentTest("polly_out.obj");
+
+            // hierarchically browse some elements of the model:
+
+            var scene = model.DefaultScene;
+
+            var pollyNode = scene.FindNode("Polly_Display");
+
+            var pollyPrimitive = pollyNode.Mesh.Primitives[0];
+
+            var pollyIndices = pollyPrimitive.GetIndices();
+            var pollyPositions = pollyPrimitive.GetVertices("POSITION").AsVector3Array();
+            var pollyNormals = pollyPrimitive.GetVertices("NORMAL").AsVector3Array();
+
+            for (int i = 0; i < pollyIndices.Count; i += 3)
+            {
+                var a = (int)pollyIndices[i + 0];
+                var b = (int)pollyIndices[i + 1];
+                var c = (int)pollyIndices[i + 2];
+
+                var ap = pollyPositions[a];
+                var bp = pollyPositions[b];
+                var cp = pollyPositions[c];
+
+                var an = pollyNormals[a];
+                var bn = pollyNormals[b];
+                var cn = pollyNormals[c];
+
+                TestContext.WriteLine($"Triangle {ap} {an} {bp} {bn} {cp} {cn}");
+            }
+        }
+    }
+}

+ 133 - 0
tests/SharpGLTF.Tests/Schema2/LoadAndSave/LoadSampleTests.cs

@@ -0,0 +1,133 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using NUnit.Framework;
+
+namespace SharpGLTF.Schema2.LoadAndSave
+{
+    /// <summary>
+    /// Test cases for models found in <see href="https://github.com/KhronosGroup/glTF-Sample-Models"/>
+    /// </summary>
+    [TestFixture]
+    public class LoadSampleTests
+    {
+        #region setup
+
+        [OneTimeSetUp]
+        public void Setup()
+        {
+            TestFiles.DownloadReferenceModels();
+        }
+
+        #endregion
+
+        [TestCase("\\glTF\\")]
+        // [TestCase("\\glTF-Draco\\")] // Not supported
+        [TestCase("\\glTF-IBL\\")]
+        [TestCase("\\glTF-Binary\\")]
+        [TestCase("\\glTF-Embedded\\")]
+        [TestCase("\\glTF-pbrSpecularGlossiness\\")]
+        public void TestLoadSampleModels(string section)
+        {
+            TestContext.CurrentContext.AttachShowDirLink();
+            TestContext.CurrentContext.AttachGltfValidatorLink();
+
+            foreach (var f in TestFiles.GetSampleModelsPaths())
+            {
+                if (!f.Contains(section)) continue;
+
+                var model = GltfUtils.LoadModel(f);
+                Assert.NotNull(model);
+
+                // evaluate and save all the triangles to a Wavefront Object
+                model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".obj"));
+                model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".glb"));
+                
+                // do a model clone and compare it
+                _AssertAreEqual(model, model.DeepClone());
+
+                // check extensions used
+                if (!model.ExtensionsUsed.Contains("EXT_lights_image_based"))
+                {
+                    var detectedExtensions = model.RetrieveUsedExtensions().ToArray();
+                    CollectionAssert.AreEquivalent(model.ExtensionsUsed, detectedExtensions);
+                }
+            }
+        }
+
+        private static void _AssertAreEqual(ModelRoot a, ModelRoot b)
+        {
+            var aa = a.GetLogicalChildrenFlattened().ToList();
+            var bb = b.GetLogicalChildrenFlattened().ToList();
+
+            Assert.AreEqual(aa.Count,bb.Count);
+
+            CollectionAssert.AreEqual
+                (
+                aa.Select(item => item.GetType()),
+                bb.Select(item => item.GetType())
+                );
+        }
+
+        [TestCase("SpecGlossVsMetalRough.gltf")]
+        [TestCase(@"UnlitTest\glTF-Binary\UnlitTest.glb")]
+        public void TestLoadSpecialCaseModels(string filePath)
+        {
+            TestContext.CurrentContext.AttachShowDirLink();
+            TestContext.CurrentContext.AttachGltfValidatorLink();
+
+            var f = TestFiles.GetSampleModelsPaths()
+                .FirstOrDefault(item => item.EndsWith(filePath));
+
+            var model = GltfUtils.LoadModel(f);
+            Assert.NotNull(model);
+
+            // evaluate and save all the triangles to a Wavefront Object
+            model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".obj"));
+            model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".glb"));
+            model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(f), ".gltf"));
+
+            // do a model roundtrip
+            var bytes = model.WriteGLB();
+            var modelBis = ModelRoot.ParseGLB(bytes);
+
+            // clone
+            var cloned = model.DeepClone();
+        }
+
+        [Test]
+        public void TestLoadUnlitModel()
+        {
+            var f = TestFiles.GetSampleModelsPaths()
+                .FirstOrDefault(item => item.EndsWith(@"UnlitTest\glTF-Binary\UnlitTest.glb"));
+
+            var model = GltfUtils.LoadModel(f);
+            Assert.NotNull(model);
+
+            Assert.IsTrue(model.LogicalMaterials[0].Unlit);
+
+            // do a model roundtrip
+            var modelBis = ModelRoot.ParseGLB(model.WriteGLB());
+            Assert.NotNull(modelBis);
+
+            Assert.IsTrue(modelBis.LogicalMaterials[0].Unlit);
+        }
+
+        [Test]
+        public void TestLoadLightsModel()
+        {
+            var f = TestFiles.GetSchemaExtensionsModelsPaths()
+                .FirstOrDefault(item => item.EndsWith("lights.gltf"));
+
+            var model = GltfUtils.LoadModel(f);
+            Assert.NotNull(model);
+
+            Assert.AreEqual(3, model.LogicalPunctualLights.Count);
+
+            Assert.AreEqual(1, model.DefaultScene.VisualChildren.ElementAt(0).PunctualLight.LogicalIndex);
+            Assert.AreEqual(0, model.DefaultScene.VisualChildren.ElementAt(1).PunctualLight.LogicalIndex);
+        }
+    }
+}

+ 1 - 1
tests/SharpGLTF.Tests/SharpGLTF.Tests.csproj

@@ -1,7 +1,7 @@
 <Project Sdk="Microsoft.NET.Sdk">
 <Project Sdk="Microsoft.NET.Sdk">
 
 
   <PropertyGroup>
   <PropertyGroup>
-    <TargetFramework>netcoreapp2.1</TargetFramework>
+    <TargetFramework>netcoreapp2.2</TargetFramework>
 
 
     <IsPackable>false</IsPackable>
     <IsPackable>false</IsPackable>
 
 

+ 39 - 53
tests/SharpGLTF.Tests/TestFiles.cs

@@ -3,6 +3,8 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using System.Text;
 using System.Text;
 
 
+using NUnit.Framework;
+
 namespace SharpGLTF
 namespace SharpGLTF
 {
 {
     /// <summary>
     /// <summary>
@@ -14,100 +16,84 @@ namespace SharpGLTF
 
 
         static TestFiles()
         static TestFiles()
         {
         {
-            var workingDir = System.IO.Path.GetDirectoryName(typeof(TestFiles).Assembly.Location);
+            var workingDir = TestContext.CurrentContext.WorkDirectory;
 
 
             _SchemaDir = System.IO.Path.Combine(workingDir, "glTF-Schema");
             _SchemaDir = System.IO.Path.Combine(workingDir, "glTF-Schema");
-
             _SampleModelsDir = System.IO.Path.Combine(workingDir, "glTF-Sample-Models");
             _SampleModelsDir = System.IO.Path.Combine(workingDir, "glTF-Sample-Models");
             _PollyModelsDir = System.IO.Path.Combine(workingDir, "glTF-Blender-Exporter");
             _PollyModelsDir = System.IO.Path.Combine(workingDir, "glTF-Blender-Exporter");
-            _GeneratedAssetsDir = System.IO.Path.Combine(workingDir, "glTF-Asset-Generator");
-
-            _CustomAssetsDir = System.IO.Path.Combine(workingDir, "CustomAssets");
         }
         }
 
 
-        public static void CheckoutDataDirectories()
+        public static void DownloadReferenceModels()
         {
         {
-            if (_RemotesChecked) return;
-            _RemotesChecked = true;
+            if (_DonwloadCompleted) return;
+            _DonwloadCompleted = true;
+            
+            TestContext.Progress.WriteLine("Downloading reference files... It might take a while, please, wait...");            
 
 
-            NUnit.Framework.TestContext.Progress.WriteLine("...");
-            NUnit.Framework.TestContext.Progress.WriteLine("Checking out test files... It might take a while, please, wait.");
-            NUnit.Framework.TestContext.Progress.WriteLine("...");
+            var dstPath = System.IO.Path.Combine(TestContext.CurrentContext.WorkDirectory, "GeneratedReferenceModels", "v_0_6_0.zip");
+            _GeneratedModelsDir = DownloadUtils.DownloadFile("https://github.com/KhronosGroup/glTF-Asset-Generator/releases/download/v0.6.0/GeneratedAssets-0.6.0.zip", dstPath);
+            
+            TestContext.Progress.WriteLine("Checking out test files... It might take a while, please, wait...");            
 
 
-            TestUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF-Sample-Models.git", _SampleModelsDir);
-            TestUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF-Blender-Exporter.git", _PollyModelsDir);
-            TestUtils.SyncronizeGitRepository("https://github.com/bghgary/glTF-Asset-Generator.git", _GeneratedAssetsDir);
-            TestUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF.git", _SchemaDir);
+            DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF-Sample-Models.git", _SampleModelsDir);
+            DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF-Blender-Exporter.git", _PollyModelsDir);            
+            DownloadUtils.SyncronizeGitRepository("https://github.com/KhronosGroup/glTF.git", _SchemaDir);
+
+            TestContext.Progress.WriteLine("... Download Completed.");
         }
         }
 
 
         #endregion
         #endregion
 
 
         #region data
         #region data
 
 
-        private static Boolean _RemotesChecked = false;
+        private static Boolean _DonwloadCompleted = false;
 
 
         private static readonly string _SchemaDir;
         private static readonly string _SchemaDir;
         private static readonly string _SampleModelsDir;
         private static readonly string _SampleModelsDir;
         private static readonly string _PollyModelsDir;
         private static readonly string _PollyModelsDir;
-        private static readonly string _GeneratedAssetsDir;
 
 
-        private static readonly string _CustomAssetsDir;
+        private static string _GeneratedModelsDir;        
 
 
         #endregion
         #endregion
 
 
         #region API
         #region API
 
 
-        public static IReadOnlyList<string> GetSchemaFilePaths()
+        public static IReadOnlyList<string> GetSchemaExtensionsModelsPaths()
         {
         {
-            var dir = System.IO.Path.Combine(_SchemaDir, "extensions", "2.0");
-
-            var gltf = System.IO.Directory.GetFiles(dir, "*.gltf", System.IO.SearchOption.AllDirectories);
-            var glbb = System.IO.Directory.GetFiles(dir, "*.glb", System.IO.SearchOption.AllDirectories);
-
-            return gltf.Concat(glbb).ToList();            
+            return GetModelPathsInDirectory(_SchemaDir, "extensions", "2.0");         
         }
         }
 
 
-        public static IReadOnlyList<string> GetSampleFilePaths()
+        public static IReadOnlyList<string> GetReferenceModelPaths()
         {
         {
-            var dir = System.IO.Path.Combine(_SampleModelsDir, "2.0");
-
-            var gltf = System.IO.Directory.GetFiles(dir, "*.gltf", System.IO.SearchOption.AllDirectories);
-            var glbb = System.IO.Directory.GetFiles(dir, "*.glb" , System.IO.SearchOption.AllDirectories);
-
-            var files = gltf.Concat(glbb);
-
-            if (System.IO.Directory.Exists(_CustomAssetsDir))
-            {
-                var custom = System.IO.Directory.GetFiles(_CustomAssetsDir, "*.glb", System.IO.SearchOption.AllDirectories);
-                files = files.Concat(custom);
+            return GetModelPathsInDirectory(_GeneratedModelsDir);
+        }
 
 
-                custom = System.IO.Directory.GetFiles(_CustomAssetsDir, "*.gltf", System.IO.SearchOption.AllDirectories);
-                files = files.Concat(custom);
-            }            
+        public static IReadOnlyList<string> GetSampleModelsPaths()
+        {
+            var files = GetModelPathsInDirectory(_SampleModelsDir, "2.0");
 
 
             return files
             return files
                 .OrderBy(item => item)
                 .OrderBy(item => item)
                 .Where(item => !item.Contains("\\glTF-Draco\\"))
                 .Where(item => !item.Contains("\\glTF-Draco\\"))
                 .ToList();
                 .ToList();
+        }        
+
+        public static string GetPollyFileModelPath()
+        {
+            return System.IO.Path.Combine(_PollyModelsDir, "polly", "project_polly.glb");
         }
         }
 
 
-        public static IReadOnlyList<string> GetGeneratedFilePaths()
+        private static IReadOnlyList<string> GetModelPathsInDirectory(params string[] paths)
         {
         {
-            var dir = System.IO.Path.Combine(_GeneratedAssetsDir, "Output");
+            var dirPath = System.IO.Path.Combine(paths);
 
 
-            var gltf = System.IO.Directory
-                .GetFiles(dir, "*.gltf", System.IO.SearchOption.AllDirectories);
+            if (!System.IO.Path.IsPathFullyQualified(dirPath)) throw new ArgumentException(nameof(dirPath));
 
 
-            var glbb = System.IO.Directory
-                .GetFiles(dir, "*.glb", System.IO.SearchOption.AllDirectories);                
+            var gltf = System.IO.Directory.GetFiles(dirPath, "*.gltf", System.IO.SearchOption.AllDirectories);
+            var glbb = System.IO.Directory.GetFiles(dirPath, "*.glb", System.IO.SearchOption.AllDirectories);
 
 
-            return gltf.Concat(glbb).OrderBy(item => item).ToList();
-        }
-
-        public static string GetPollyFilePath()
-        {
-            return System.IO.Path.Combine(_PollyModelsDir, "polly", "project_polly.glb");
-        }
+            return gltf.Concat(glbb).ToList();
+        }        
 
 
         #endregion
         #endregion
     }
     }

+ 70 - 26
tests/SharpGLTF.Tests/TestUtils.cs

@@ -63,32 +63,6 @@ namespace SharpGLTF
             NUnit.Framework.TestContext.AddTestAttachment(fileName);
             NUnit.Framework.TestContext.AddTestAttachment(fileName);
         }
         }
 
 
-        public static void SyncronizeGitRepository(string remoteUrl, string localDirectory)
-        {
-            if (LibGit2Sharp.Repository.Discover(localDirectory) == null)
-            {
-                NUnit.Framework.TestContext.Progress.WriteLine($"Cloning {remoteUrl} can take several minutes; Please wait...");
-
-                LibGit2Sharp.Repository.Clone(remoteUrl, localDirectory);
-
-                NUnit.Framework.TestContext.Progress.WriteLine($"... Clone Completed");
-
-                return;
-            }
-
-            using (var repo = new LibGit2Sharp.Repository(localDirectory))
-            {
-                var options = new LibGit2Sharp.PullOptions
-                {
-                    FetchOptions = new LibGit2Sharp.FetchOptions()
-                };
-
-                var r = LibGit2Sharp.Commands.Pull(repo, new LibGit2Sharp.Signature("Anonymous", "[email protected]", new DateTimeOffset(DateTime.Now)), options);
-
-                NUnit.Framework.TestContext.Progress.WriteLine($"{remoteUrl} is {r.Status}");
-            }
-        }
-
         public static void AttachShowDirLink(this NUnit.Framework.TestContext context)
         public static void AttachShowDirLink(this NUnit.Framework.TestContext context)
         {
         {
             context.AttachFileLink("📂 Show Directory", context.GetAttachmentPath(string.Empty));
             context.AttachFileLink("📂 Show Directory", context.GetAttachmentPath(string.Empty));
@@ -129,6 +103,76 @@ namespace SharpGLTF
 
 
             NUnit.Framework.TestContext.AddTestAttachment(linkPath);
             NUnit.Framework.TestContext.AddTestAttachment(linkPath);
         }
         }
+    }
+
+
+    static class DownloadUtils
+    {
+        private static readonly Object _DownloadMutex = new object();
+
+        public static void SyncronizeGitRepository(string remoteUrl, string localDirectoryPath)
+        {
+            if (!System.IO.Path.IsPathRooted(localDirectoryPath)) throw new ArgumentException(nameof(localDirectoryPath));
+
+            lock (_DownloadMutex)
+            {
+                if (LibGit2Sharp.Repository.Discover(localDirectoryPath) == null)
+                {
+                    NUnit.Framework.TestContext.Progress.WriteLine($"Cloning {remoteUrl} can take several minutes; Please wait...");
+
+                    LibGit2Sharp.Repository.Clone(remoteUrl, localDirectoryPath);
+
+                    NUnit.Framework.TestContext.Progress.WriteLine($"... Clone Completed");
+
+                    return;
+                }
+
+                using (var repo = new LibGit2Sharp.Repository(localDirectoryPath))
+                {
+                    var options = new LibGit2Sharp.PullOptions
+                    {
+                        FetchOptions = new LibGit2Sharp.FetchOptions()
+                    };
+
+                    var r = LibGit2Sharp.Commands.Pull(repo, new LibGit2Sharp.Signature("Anonymous", "[email protected]", new DateTimeOffset(DateTime.Now)), options);
+
+                    NUnit.Framework.TestContext.Progress.WriteLine($"{remoteUrl} is {r.Status}");
+                }
+            }
+        }
+
+        public static string DownloadFile(string remoteUri, string localFilePath)
+        {
+            if (!System.IO.Path.IsPathRooted(localFilePath)) throw new ArgumentException(nameof(localFilePath));
+
+            lock (_DownloadMutex)
+            {
+                if (System.IO.File.Exists(localFilePath)) return localFilePath; // we check again because we could have downloaded the file while waiting.
+
+                NUnit.Framework.TestContext.Progress.WriteLine($"Downloading {remoteUri}... Please Wait...");
+
+                var dir = System.IO.Path.GetDirectoryName(localFilePath);
+                System.IO.Directory.CreateDirectory(dir);
+
+                using (var wc = new System.Net.WebClient())
+                {
+                    wc.DownloadFile(remoteUri, localFilePath);
+                }
+
+                if (localFilePath.ToLower().EndsWith(".zip"))
+                {
+                    NUnit.Framework.TestContext.Progress.WriteLine($"Extracting {localFilePath}...");
+
+                    var extractPath = System.IO.Path.Combine(dir, System.IO.Path.GetFileNameWithoutExtension(localFilePath));
+
+                    System.IO.Compression.ZipFile.ExtractToDirectory(localFilePath, extractPath);
+
+                    return extractPath;
+                }
+
+                return localFilePath;
+            }
+        }
 
 
     }
     }
 }
 }