瀏覽代碼

Added detector that checks if code is being run via unit test

MarcinZiabek 3 年之前
父節點
當前提交
164bdd76d8
共有 1 個文件被更改,包括 20 次插入0 次删除
  1. 20 0
      QuestPDF/Previewer/UnitTestDetector.cs

+ 20 - 0
QuestPDF/Previewer/UnitTestDetector.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Linq;
+
+namespace QuestPDF.Previewer;
+
+internal static class UnitTestDetector
+{
+    public static bool RunningInUnitTest { get; }   
+
+    private static string[] UnitTestAssemblies = { "xunit", "nunit", "mstest" };
+    
+    static UnitTestDetector()
+    {
+        RunningInUnitTest = AppDomain
+            .CurrentDomain
+            .GetAssemblies()
+            .Select(x => x.FullName.ToLowerInvariant())
+            .Any(x => UnitTestAssemblies.Any(x.Contains));
+    }
+}