This commit is contained in:
Mike Phares 2023-02-14 10:35:24 -07:00
parent d250651c28
commit 6609772a05
6 changed files with 33 additions and 30 deletions

View File

@ -43,7 +43,7 @@
<PackageReference Include="IKVM.OpenJDK.XML.API" Version="7.2.4630.5"><NoWarn>NU1701</NoWarn></PackageReference> <PackageReference Include="IKVM.OpenJDK.XML.API" Version="7.2.4630.5"><NoWarn>NU1701</NoWarn></PackageReference>
<PackageReference Include="IKVM.Runtime" Version="7.2.4630.5"><NoWarn>NU1701</NoWarn></PackageReference> <PackageReference Include="IKVM.Runtime" Version="7.2.4630.5"><NoWarn>NU1701</NoWarn></PackageReference>
<PackageReference Include="Instances" Version="3.0.0" /> <PackageReference Include="Instances" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.2" /> <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="7.0.0" />
@ -63,7 +63,7 @@
<PackageReference Include="System.Data.OleDb" Version="7.0.0" /> <PackageReference Include="System.Data.OleDb" Version="7.0.0" />
<PackageReference Include="System.Data.SqlClient" Version="4.8.5" /> <PackageReference Include="System.Data.SqlClient" Version="4.8.5" />
<PackageReference Include="System.Drawing.Common" Version="7.0.0" /> <PackageReference Include="System.Drawing.Common" Version="7.0.0" />
<PackageReference Include="System.Text.Json" Version="7.0.1" /> <PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="Tesseract" Version="5.2.0" /> <PackageReference Include="Tesseract" Version="5.2.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -40,7 +40,7 @@ public class EC : EAFLoggingUnitTesting
[ClassCleanup()] [ClassCleanup()]
public static void ClassCleanup() public static void ClassCleanup()
{ {
EAFLoggingUnitTesting.Logger?.LogInformation("Cleanup"); EAFLoggingUnitTesting?.Logger?.LogInformation("Cleanup");
EAFLoggingUnitTesting?.Dispose(); EAFLoggingUnitTesting?.Dispose();
} }

View File

@ -26,7 +26,7 @@ public class LoggingUnitTesting : UnitTesting, IDisposable
base(testContext, declaringType) base(testContext, declaringType)
{ {
_LoggerFactory = new LoggerFactory(); _LoggerFactory = new LoggerFactory();
if (testContext is null || declaringType is null) if (testContext is null || declaringType is null || _IsEnvironment is null)
{ {
_ConfigurationRoot = null; _ConfigurationRoot = null;
_DefaultLogLevel = null; _DefaultLogLevel = null;

View File

@ -29,40 +29,45 @@ public class UnitTesting
{ {
string waitFor = "\"WaitFor\":"; string waitFor = "\"WaitFor\":";
string projectDirectory = GetProjectDirectory(testContext); string projectDirectory = GetProjectDirectory(testContext);
_TestContextPropertiesAsJson = JsonSerializer.Serialize(testContext.Properties, new JsonSerializerOptions { WriteIndented = true }); if (string.IsNullOrEmpty(projectDirectory))
_HasWaitForProperty = _TestContextPropertiesAsJson.Contains(waitFor); _IsEnvironment = null;
string vsCodeDirectory = Path.Combine(projectDirectory, ".vscode"); else
if (!Directory.Exists(vsCodeDirectory))
_ = Directory.CreateDirectory(vsCodeDirectory);
string launchText = GetLaunchText();
File.WriteAllText(Path.Combine(vsCodeDirectory, "launch.json"), launchText);
if (_HasWaitForProperty)
{ {
for (int i = 0; i < int.MaxValue; i++) _TestContextPropertiesAsJson = JsonSerializer.Serialize(testContext.Properties, new JsonSerializerOptions { WriteIndented = true });
_HasWaitForProperty = _TestContextPropertiesAsJson.Contains(waitFor);
string vsCodeDirectory = Path.Combine(projectDirectory, ".vscode");
if (!Directory.Exists(vsCodeDirectory))
_ = Directory.CreateDirectory(vsCodeDirectory);
string launchText = GetLaunchText();
File.WriteAllText(Path.Combine(vsCodeDirectory, "launch.json"), launchText);
if (_HasWaitForProperty)
{ {
if (!_TestContextPropertiesAsJson.Contains($"{waitFor} \"Debugger.IsAttached\"") || Debugger.IsAttached) for (int i = 0; i < int.MaxValue; i++)
break; {
Thread.Sleep(500); if (!_TestContextPropertiesAsJson.Contains($"{waitFor} \"Debugger.IsAttached\"") || Debugger.IsAttached)
break;
Thread.Sleep(500);
}
} }
} MethodBase methodBase = declaringType.GetMethod(testContext.TestName);
MethodBase methodBase = declaringType.GetMethod(testContext.TestName); if (methodBase is not null)
if (methodBase is not null)
{
TestCategoryAttribute testCategoryAttribute = methodBase.GetCustomAttribute<TestCategoryAttribute>();
if (testCategoryAttribute is not null)
{ {
foreach (string testCategory in testCategoryAttribute.TestCategories) TestCategoryAttribute testCategoryAttribute = methodBase.GetCustomAttribute<TestCategoryAttribute>();
_IsEnvironment = new IsEnvironment(testCategory); if (testCategoryAttribute is not null)
{
foreach (string testCategory in testCategoryAttribute.TestCategories)
_IsEnvironment = new IsEnvironment(testCategory);
}
} }
_IsEnvironment ??= new IsEnvironment(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: Debugger.IsAttached, nullASPNetCoreEnvironmentIsProduction: !Debugger.IsAttached);
} }
_IsEnvironment ??= new IsEnvironment(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: Debugger.IsAttached, nullASPNetCoreEnvironmentIsProduction: !Debugger.IsAttached);
} }
} }
internal static string GetProjectDirectory(TestContext testContext) internal static string GetProjectDirectory(TestContext testContext)
{ {
string result; string result;
string[] checkFiles = null; string[] checkFiles;
result = Path.GetDirectoryName(testContext.DeploymentDirectory); result = Path.GetDirectoryName(testContext.DeploymentDirectory);
for (int i = 0; i < int.MaxValue; i++) for (int i = 0; i < int.MaxValue; i++)
{ {
@ -73,8 +78,6 @@ public class UnitTesting
break; break;
result = Path.GetDirectoryName(result); result = Path.GetDirectoryName(result);
} }
if (string.IsNullOrEmpty(result) || checkFiles is null || !checkFiles.Any())
throw new Exception(result);
return result; return result;
} }

View File

@ -34,7 +34,7 @@ public class EC : LoggingUnitTesting, IDisposable
[ClassCleanup()] [ClassCleanup()]
public static void ClassCleanup() public static void ClassCleanup()
{ {
LoggingUnitTesting.Logger?.LogInformation("Cleanup"); LoggingUnitTesting?.Logger?.LogInformation("Cleanup");
LoggingUnitTesting?.Dispose(); LoggingUnitTesting?.Dispose();
} }

View File

@ -11,7 +11,7 @@
<RootNamespace>EC</RootNamespace> <RootNamespace>EC</RootNamespace>
<AssemblyName>EC</AssemblyName> <AssemblyName>EC</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<RuntimeIdentifier Condition="'$(Configuration)' == 'Debug'">win-x64</RuntimeIdentifier> <RuntimeIdentifier Condition="'$(Configuration)' == 'Debug'">win-x86</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(Configuration)' == 'Release'">win</RuntimeIdentifier> <RuntimeIdentifier Condition="'$(Configuration)' == 'Release'">win</RuntimeIdentifier>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
</PropertyGroup> </PropertyGroup>