/ src / modules / previewpane / UnitTests-GcodeThumbnailProvider / GcodeThumbnailProviderTests.cs
GcodeThumbnailProviderTests.cs
 1  // Copyright (c) Microsoft Corporation
 2  // The Microsoft Corporation licenses this file to you under the MIT license.
 3  // See the LICENSE file in the project root for more information.
 4  
 5  using System.Drawing;
 6  using System.IO;
 7  
 8  using Microsoft.PowerToys.ThumbnailHandler.Gcode;
 9  using Microsoft.VisualStudio.TestTools.UnitTesting;
10  
11  namespace GcodeThumbnailProviderUnitTests
12  {
13      [STATestClass]
14      public class GcodeThumbnailProviderTests
15      {
16          [DataTestMethod]
17          [DataRow("HelperFiles/sample.gcode")]
18          [DataRow("HelperFiles/sample_JPG.gcode")]
19          [DataRow("HelperFiles/sample_QOI.gcode")]
20          public void GetThumbnailValidStreamGcode(string filePath)
21          {
22              // Act
23              GcodeThumbnailProvider provider = new GcodeThumbnailProvider(filePath);
24  
25              Bitmap bitmap = provider.GetThumbnail(256);
26  
27              Assert.IsTrue(bitmap != null);
28          }
29  
30          [TestMethod]
31          public void GetThumbnailInValidSizeGcode()
32          {
33              // Act
34              var filePath = "HelperFiles/sample.gcode";
35  
36              GcodeThumbnailProvider provider = new GcodeThumbnailProvider(filePath);
37  
38              Bitmap bitmap = provider.GetThumbnail(0);
39  
40              Assert.IsTrue(bitmap == null);
41          }
42  
43          [TestMethod]
44          public void GetThumbnailToBigGcode()
45          {
46              // Act
47              var filePath = "HelperFiles/sample.gcode";
48  
49              GcodeThumbnailProvider provider = new GcodeThumbnailProvider(filePath);
50  
51              Bitmap bitmap = provider.GetThumbnail(10001);
52  
53              Assert.IsTrue(bitmap == null);
54          }
55  
56          [TestMethod]
57          public void CheckNoGcodeEmptyStringShouldReturnNullBitmap()
58          {
59              using (var reader = new StringReader(string.Empty))
60              {
61                  Bitmap thumbnail = GcodeThumbnailProvider.GetThumbnail(reader, 256);
62                  Assert.IsTrue(thumbnail == null);
63              }
64          }
65  
66          [TestMethod]
67          public void CheckNoGcodeNullStringShouldReturnNullBitmap()
68          {
69              Bitmap thumbnail = GcodeThumbnailProvider.GetThumbnail(null, 256);
70              Assert.IsTrue(thumbnail == null);
71          }
72      }
73  }