Ver Fonte

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

MarcinZiabek há 3 anos atrás
pai
commit
164bdd76d8
1 ficheiros alterados com 20 adições e 0 exclusões
  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));
+    }
+}