Browse Source

Added testAttachment nunit helper

Vicente Penades 3 years ago
parent
commit
a047f8e3f7

+ 9 - 0
NuGet.Config

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configuration>
+
+    <packageSources>
+        <clear /> <!-- ensure only the sources defined below are used -->
+        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
+    </packageSources>
+
+</configuration>

+ 3 - 0
src/SharpGLTF.Core/Memory/MemoryImage.cs

@@ -83,6 +83,9 @@ namespace SharpGLTF.Memory
         /// <param name="mime64content">The Mime64 string source.</param>
         /// <param name="mime64content">The Mime64 string source.</param>
         /// <param name="image">if decoding succeeds, it will contain the image file.</param>
         /// <param name="image">if decoding succeeds, it will contain the image file.</param>
         /// <returns>true if decoding succeeded.</returns>
         /// <returns>true if decoding succeeded.</returns>
+        /// <remarks>
+        /// The string must be haedered with a mime prefix like:     "data:image/png;base64,"
+        /// </remarks>
         public static bool TryParseMime64(string mime64content, out MemoryImage image)
         public static bool TryParseMime64(string mime64content, out MemoryImage image)
         {
         {
             if (mime64content == null) { image = default; return false; }
             if (mime64content == null) { image = default; return false; }

+ 22 - 22
tests/SharpGLTF.ThirdParty.Tests/AceCebovTests.cs

@@ -16,10 +16,10 @@ namespace SharpGLTF.ThirdParty
     using VBColor1Texture1 = VertexBuilder<VertexPosition,VertexColor1Texture1,VertexEmpty>;
     using VBColor1Texture1 = VertexBuilder<VertexPosition,VertexColor1Texture1,VertexEmpty>;
     using VBTexture1 = VertexBuilder<VertexPosition,VertexTexture1,VertexEmpty>;
     using VBTexture1 = VertexBuilder<VertexPosition,VertexTexture1,VertexEmpty>;
 
 
+    [ResourcePathFormat("*\\Assets")]
+    [AttachmentPathFormat("*\\?")]
     internal class AceCebovTests
     internal class AceCebovTests
     {
     {
-        private static string AssetsPath = Path.Combine(TestContext.CurrentContext.TestDirectory, "Assets");
-
         [Test]
         [Test]
         public void TestMorphColorTargets()
         public void TestMorphColorTargets()
         {
         {
@@ -93,13 +93,13 @@ namespace SharpGLTF.ThirdParty
 
 
             // bypassing AttachToCurrentTest until glTFValidator is fixed.
             // bypassing AttachToCurrentTest until glTFValidator is fixed.
 
 
-            var outPath = TestContext.CurrentContext.GetAttachmentPath("ColorMorphing.glb", true);
-            model.Save(outPath);
-            TestContext.AddTestAttachment(outPath);
+            AttachmentInfo
+                .From("ColorMorphing.glb")
+                .WriteFile(f => model.Save(f.FullName));
 
 
-            outPath = TestContext.CurrentContext.GetAttachmentPath("ColorMorphing.gltf", true);
-            model.Save(outPath);
-            TestContext.AddTestAttachment(outPath);
+            AttachmentInfo
+                .From("ColorMorphing.gltf")
+                .WriteFile(f => model.Save(f.FullName));
         }
         }
 
 
         [Test]
         [Test]
@@ -109,7 +109,7 @@ namespace SharpGLTF.ThirdParty
             var material = new MaterialBuilder()
             var material = new MaterialBuilder()
                 .WithDoubleSide(true)
                 .WithDoubleSide(true)
                 .WithMetallicRoughnessShader()
                 .WithMetallicRoughnessShader()
-                .WithChannelImage(KnownChannel.BaseColor, new MemoryImage(Path.Combine(AssetsPath, "texture.png")));
+                .WithChannelImage(KnownChannel.BaseColor, new MemoryImage(new ResourceInfo("texture.png")));
 
 
             // create a mesh with two primitives, one for each material
             // create a mesh with two primitives, one for each material
 
 
@@ -171,13 +171,13 @@ namespace SharpGLTF.ThirdParty
 
 
             // bypassing AttachToCurrentTest until glTFValidator is fixed.
             // bypassing AttachToCurrentTest until glTFValidator is fixed.
 
 
-            var outPath = TestContext.CurrentContext.GetAttachmentPath("TextureMorphing.glb", true);
-            model.Save(outPath);
-            TestContext.AddTestAttachment(outPath);
+            AttachmentInfo
+                .From("TextureMorphing.glb")
+                .WriteFile(f => model.Save(f.FullName));
 
 
-            outPath = TestContext.CurrentContext.GetAttachmentPath("TextureMorphing.gltf", true);
-            model.Save(outPath);
-            TestContext.AddTestAttachment(outPath);
+            AttachmentInfo
+                .From("TextureMorphing.gltf")
+                .WriteFile(f => model.Save(f.FullName));
         }
         }
 
 
         [Test]
         [Test]
@@ -187,7 +187,7 @@ namespace SharpGLTF.ThirdParty
             var material = new MaterialBuilder()
             var material = new MaterialBuilder()
                 .WithDoubleSide(true)
                 .WithDoubleSide(true)
                 .WithMetallicRoughnessShader()
                 .WithMetallicRoughnessShader()
-                .WithChannelImage(KnownChannel.BaseColor, new MemoryImage(Path.Combine(AssetsPath, "texture.png")));
+                .WithChannelImage(KnownChannel.BaseColor, new MemoryImage(new ResourceInfo("texture.png")));
 
 
             // create a mesh with two primitives, one for each material
             // create a mesh with two primitives, one for each material
 
 
@@ -252,13 +252,13 @@ namespace SharpGLTF.ThirdParty
 
 
             // bypassing AttachToCurrentTest until glTFValidator is fixed.
             // bypassing AttachToCurrentTest until glTFValidator is fixed.
 
 
-            var outPath = TestContext.CurrentContext.GetAttachmentPath("ColorAndTextureMorphing.glb", true);
-            model.Save(outPath);
-            TestContext.AddTestAttachment(outPath);
+            AttachmentInfo
+                .From("ColorAndTextureMorphing.glb")
+                .WriteFile(f => model.Save(f.FullName));
 
 
-            outPath = TestContext.CurrentContext.GetAttachmentPath("ColorAndTextureMorphing.gltf", true);
-            model.Save(outPath);
-            TestContext.AddTestAttachment(outPath);
+            AttachmentInfo
+                .From("ColorAndTextureMorphing.gltf")
+                .WriteFile(f => model.Save(f.FullName));
         }
         }
     }
     }
 }
 }

+ 9 - 3
tests/SharpGLTF.ThirdParty.Tests/EdMackeyTests.cs

@@ -11,7 +11,8 @@ using SharpGLTF.Materials;
 using VERTEX = SharpGLTF.Geometry.VertexTypes.VertexPositionNormal;
 using VERTEX = SharpGLTF.Geometry.VertexTypes.VertexPositionNormal;
 
 
 namespace SharpGLTF.ThirdParty
 namespace SharpGLTF.ThirdParty
-{
+{
+
     public class EdMackeyTests
     public class EdMackeyTests
     {
     {
         [Test]
         [Test]
@@ -51,8 +52,13 @@ namespace SharpGLTF.ThirdParty
 
 
             // save the model in different formats
             // save the model in different formats
 
 
-            scene.AttachToCurrentTest("mesh.glb");
-            scene.AttachToCurrentTest("mesh.gltf");
+            AttachmentInfo
+                .From("mesh.glb")
+                .WriteFile(f => scene.ToGltf2().Save(f.FullName));
+
+            AttachmentInfo
+                .From("mesh.gltf")
+                .WriteFile(f => scene.ToGltf2().Save(f.FullName));
         }
         }
 
 
     }
     }

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

@@ -14,7 +14,8 @@
   <ItemGroup>
   <ItemGroup>
     <PackageReference Include="NUnit" Version="3.13.3" />
     <PackageReference Include="NUnit" Version="3.13.3" />
     <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
     <PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />    
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
+    <PackageReference Include="TestAttachments.NUnit" Version="3.0.0-Preview-20220609-1233" />    
   </ItemGroup>
   </ItemGroup>
 
 
   <ItemGroup>
   <ItemGroup>