Browse Source

added support for showing directory from tests

Vicente Penades 6 years ago
parent
commit
7c43df9e02

+ 4 - 2
src/glTF2Sharp.Tests/Geometry/CreateMeshTests.cs

@@ -19,9 +19,9 @@ namespace glTF2Sharp.Geometry
 
             var positions = new[]
             {
-                new Vector3(-10,-10,0),
+                new Vector3(10,-10,0),
                 new Vector3(0,10,0),
-                new Vector3(10,-10,0)                
+                new Vector3(-10,-10,0)                
             };
 
             var normals = new[]
@@ -69,6 +69,8 @@ namespace glTF2Sharp.Geometry
             root.MergeBuffers();
             root.AttachToCurrentTest("Triangle.gltf");
             root.AttachToCurrentTest("Triangle.glb");
+
+            TestContext.CurrentContext.AttachShowDirLink();
         }
     }
 }

+ 31 - 4
src/glTF2Sharp.Tests/TestUtils.cs

@@ -23,12 +23,16 @@ namespace glTF2Sharp
 
         public static string GetAttachmentPath(this NUnit.Framework.TestContext context, string fileName, bool ensureDirectoryExists = false)
         {
-            if (string.IsNullOrWhiteSpace(fileName)) throw new ArgumentNullException(nameof(fileName));
-            if (System.IO.Path.IsPathRooted(fileName)) throw new ArgumentException(nameof(fileName), "path must be a relative path");
+            var path = System.IO.Path.Combine(context.TestDirectory, "TestResults", $"{context.Test.ID}");
+            var dir = path;
 
-            var path = System.IO.Path.Combine(context.TestDirectory, "TestResults", $"{context.Test.ID}.{fileName}");
+            if (!string.IsNullOrWhiteSpace(fileName))
+            {
+                if (System.IO.Path.IsPathRooted(fileName)) throw new ArgumentException(nameof(fileName), "path must be a relative path");
+                path = System.IO.Path.Combine(path, fileName);
 
-            var dir = System.IO.Path.GetDirectoryName(path);
+                dir = System.IO.Path.GetDirectoryName(path);
+            }
 
             System.IO.Directory.CreateDirectory(dir);
 
@@ -77,5 +81,28 @@ namespace glTF2Sharp
                 NUnit.Framework.TestContext.Progress.WriteLine($"{remoteUrl} is {r.Status}");
             }
         }
+
+        public static void AttachShowDirLink(this NUnit.Framework.TestContext context)
+        {
+            context.AttachFileLink("📂 Show Directory", context.GetAttachmentPath(string.Empty));
+        }
+        
+        public static void AttachFileLink(this NUnit.Framework.TestContext context, string linkPath, string targetPath)
+        {
+            var sb = new StringBuilder();
+            sb.AppendLine("[InternetShortcut]");
+            sb.AppendLine("URL=file:///" + targetPath);
+            sb.AppendLine("IconIndex=0");
+            string icon = targetPath.Replace('\\', '/');
+            sb.AppendLine("IconFile=" + icon);
+
+            linkPath = System.IO.Path.ChangeExtension(linkPath, ".url");
+            linkPath = context.GetAttachmentPath(linkPath, true);
+
+            System.IO.File.WriteAllText(linkPath, sb.ToString());
+
+            NUnit.Framework.TestContext.AddTestAttachment(linkPath);
+        }
+        
     }
 }