Skip to content

Commit 18f0367

Browse files
committed
Comments
1 parent b5a6d5b commit 18f0367

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

IPBanCore/Core/IPBan/IPBanService.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ public override DateTime FromSystemTime(DateTime systemTime)
535535
public static T CreateAndStartIPBanTestService<T>(string directory = null, string configFileName = null, string defaultBannedIPAddressHandlerUrl = null,
536536
Func<string, string> configFileModifier = null, bool cleanup = true) where T : IPBanService
537537
{
538+
// if not running tests, do nothing
538539
if (!UnitTestDetector.Running)
539540
{
540541
return default;
@@ -603,6 +604,7 @@ public static T CreateAndStartIPBanTestService<T>(string directory = null, strin
603604
/// </summary>
604605
public static void CleanupIPBanTestFiles()
605606
{
607+
// if not running tests, do nothing
606608
if (!UnitTestDetector.Running)
607609
{
608610
return;
@@ -623,6 +625,7 @@ public static void CleanupIPBanTestFiles()
623625
/// <param name="service">Service to dispose</param>
624626
public static void DisposeIPBanTestService(IPBanService service)
625627
{
628+
// if not running tests, do nothing
626629
if (!UnitTestDetector.Running)
627630
{
628631
return;

IPBanCore/Core/Interfaces/IBannedIPAddressHandler.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public async Task HandleBannedIPAddress(string ipAddress, string source, string
7878

7979
#if DEBUG
8080

81+
// don't run this when debugging app locally outside tests
8182
if (!UnitTestDetector.Running)
8283
{
8384
return;

IPBanCore/Core/Utility/ExtensionMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ public static IReadOnlyCollection<Type> GetAllTypes()
930930
prefix = prefix[..pos];
931931
}
932932

933-
// no filter if running unit tests
933+
// no filter if running unit tests, need to scan all assemblies
934934
if (UnitTestDetector.Running)
935935
{
936936
prefix = null;

IPBanCore/Core/Utility/UnitTestDetector.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2323
*/
2424

2525
using System;
26+
using System.Linq;
2627

2728
namespace DigitalRuby.IPBanCore
2829
{
@@ -43,19 +44,16 @@ static UnitTestDetector()
4344
{
4445
try
4546
{
47+
// test host
4648
if ((System.Reflection.Assembly.GetEntryAssembly()?.GetName().Name ?? string.Empty).StartsWith("testhost", StringComparison.OrdinalIgnoreCase))
4749
{
4850
Running = true;
49-
return;
5051
}
51-
52-
foreach (System.Reflection.Assembly assem in AppDomain.CurrentDomain.GetAssemblies())
52+
else
5353
{
54-
if (assem.FullName.ToLowerInvariant().StartsWith("nunit.framework"))
55-
{
56-
Running = true;
57-
break;
58-
}
54+
// nunit
55+
Running = AppDomain.CurrentDomain.GetAssemblies()
56+
.Any(a => a.FullName.Equals("nunit.framework", StringComparison.OrdinalIgnoreCase));
5957
}
6058
}
6159
catch (Exception ex)

0 commit comments

Comments
 (0)