Match TFS Changeset 303361
This commit is contained in:
40
APC Viewer.Tests/APC Viewer.Tests.csproj
Normal file
40
APC Viewer.Tests/APC Viewer.Tests.csproj
Normal file
@ -0,0 +1,40 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup Label="Globals">
|
||||
<SccProjectName>SAK</SccProjectName>
|
||||
<SccProvider>SAK</SccProvider>
|
||||
<SccAuxPath>SAK</SccAuxPath>
|
||||
<SccLocalPath>SAK</SccLocalPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>APCViewer.Tests</RootNamespace>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<VSTestLogger>trx</VSTestLogger>
|
||||
<VSTestResultsDirectory>../../../Trunk/APC Viewer/05_TestResults/TestResults</VSTestResultsDirectory>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
|
||||
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
|
||||
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsWindows)'=='true'">
|
||||
<DefineConstants>Windows</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsOSX)'=='true'">
|
||||
<DefineConstants>OSX</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(IsLinux)'=='true'">
|
||||
<DefineConstants>Linux</DefineConstants>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../APC Viewer/APC Viewer.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
173
APC Viewer.Tests/BackgroundTests.cs
Normal file
173
APC Viewer.Tests/BackgroundTests.cs
Normal file
@ -0,0 +1,173 @@
|
||||
using APCViewer.Models;
|
||||
using Helper.Log;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Shared;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
|
||||
namespace APCViewer.Tests
|
||||
{
|
||||
|
||||
[TestClass]
|
||||
public class BackgroundTests : LoggingUnitTesting, IBackground
|
||||
{
|
||||
|
||||
private static WebClient _WebClient;
|
||||
private static string _WorkingDirectory;
|
||||
private static Singleton.IBackground _Background;
|
||||
private static BackgroundTests _LoggingUnitTesting;
|
||||
internal static BackgroundTests LoggingUnitTesting => _LoggingUnitTesting;
|
||||
|
||||
public BackgroundTests() : base(testContext: null, declaringType: null)
|
||||
{
|
||||
if (_LoggingUnitTesting is null)
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public BackgroundTests(TestContext testContext) : base(testContext, new StackFrame().GetMethod().DeclaringType)
|
||||
{
|
||||
}
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext testContext)
|
||||
{
|
||||
if (_LoggingUnitTesting is null)
|
||||
_LoggingUnitTesting = new BackgroundTests(testContext);
|
||||
_LoggingUnitTesting.Logger.LogInformation(string.Concat(testContext.TestName, " - ClassInitialize"));
|
||||
_WebClient = new WebClient();
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
_WorkingDirectory = Log.GetWorkingDirectory(assembly.GetName().Name, "IFXApps");
|
||||
Type type = new StackFrame().GetMethod().DeclaringType;
|
||||
_Background = new Singleton.Background(_LoggingUnitTesting.IsEnvironment, _LoggingUnitTesting.ConfigurationRoot, _WorkingDirectory);
|
||||
_Background.Update(_LoggingUnitTesting.Logger, _WebClient);
|
||||
Assert.IsNotNull(_Background);
|
||||
Assert.IsFalse(string.IsNullOrEmpty(_Background.AppSettings.URLs));
|
||||
Assert.IsFalse(string.IsNullOrEmpty(_Background.AppSettings.Server));
|
||||
Assert.IsFalse(string.IsNullOrEmpty(_Background.AppSettings.MonARessource));
|
||||
}
|
||||
|
||||
[ClassCleanup()]
|
||||
public static void ClassCleanup()
|
||||
{
|
||||
if (!(_LoggingUnitTesting.Logger is null))
|
||||
_LoggingUnitTesting.Logger.LogInformation("Cleanup");
|
||||
if (!(_LoggingUnitTesting is null))
|
||||
_LoggingUnitTesting.Dispose();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(nameof(IsEnvironment.Name.WindowsDevelopment))]
|
||||
public void APCDataCallback_WindowsDevelopment()
|
||||
{
|
||||
MethodBase methodBase = new StackFrame().GetMethod();
|
||||
_Logger.LogInformation($"Skipped - {methodBase.Name}");
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(nameof(IsEnvironment.Name.WindowsStaging))]
|
||||
public void APCDataCallback_WindowsStaging()
|
||||
{
|
||||
MethodBase methodBase = new StackFrame().GetMethod();
|
||||
_Logger.LogInformation($"Skipped - {methodBase.Name}");
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(nameof(IsEnvironment.Name.WindowsProduction))]
|
||||
public void APCDataCallback_WindowsProduction()
|
||||
{
|
||||
_Background.APCDataCallback();
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
void IBackground.APCDataCallback()
|
||||
{
|
||||
APCDataCallback_WindowsDevelopment();
|
||||
APCDataCallback_WindowsStaging();
|
||||
APCDataCallback_WindowsProduction();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(nameof(IsEnvironment.Name.WindowsDevelopment))]
|
||||
public void EAFLogDataCallback_WindowsDevelopment()
|
||||
{
|
||||
MethodBase methodBase = new StackFrame().GetMethod();
|
||||
_Logger.LogInformation($"Skipped - {methodBase.Name}");
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(nameof(IsEnvironment.Name.WindowsStaging))]
|
||||
public void EAFLogDataCallback_WindowsStaging()
|
||||
{
|
||||
MethodBase methodBase = new StackFrame().GetMethod();
|
||||
_Logger.LogInformation($"Skipped - {methodBase.Name}");
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(nameof(IsEnvironment.Name.WindowsProduction))]
|
||||
public void EAFLogDataCallback_WindowsProduction()
|
||||
{
|
||||
_Background.EAFLogDataCallback();
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
void IBackground.EAFLogDataCallback()
|
||||
{
|
||||
EAFLogDataCallback_WindowsDevelopment();
|
||||
EAFLogDataCallback_WindowsStaging();
|
||||
EAFLogDataCallback_WindowsProduction();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(nameof(IsEnvironment.Name.WindowsDevelopment))]
|
||||
public void EDADataCallback_WindowsDevelopment()
|
||||
{
|
||||
MethodBase methodBase = new StackFrame().GetMethod();
|
||||
_Logger.LogInformation($"Skipped - {methodBase.Name}");
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(nameof(IsEnvironment.Name.WindowsStaging))]
|
||||
public void EDADataCallback_WindowsStaging()
|
||||
{
|
||||
MethodBase methodBase = new StackFrame().GetMethod();
|
||||
_Logger.LogInformation($"Skipped - {methodBase.Name}");
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[TestCategory(nameof(IsEnvironment.Name.WindowsProduction))]
|
||||
public void EDADataCallback_WindowsProduction()
|
||||
{
|
||||
_Background.EDADataCallback();
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
void IBackground.EDADataCallback()
|
||||
{
|
||||
EDADataCallback_WindowsDevelopment();
|
||||
EDADataCallback_WindowsStaging();
|
||||
EDADataCallback_WindowsProduction();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// dotnet build --runtime win-x64
|
||||
// dotnet test --runtime win-x64 --no-build --filter EDADataCallback_WindowsProduction --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\")
|
||||
// dotnet test --runtime win-x64 --no-build --filter "ClassName=APCViewer.Tests.BackgroundTests & TestCategory=WindowsDevelopment" --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\")
|
||||
// dotnet test --runtime win-x64 --no-build --filter "ClassName=APCViewer.Tests.BackgroundTests & TestCategory=WindowsStaging" --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\")
|
||||
// dotnet test --runtime win-x64 --no-build --filter "ClassName=APCViewer.Tests.BackgroundTests & TestCategory=WindowsProduction" --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\")
|
||||
282
APC Viewer.Tests/HomeControllerTests.cs
Normal file
282
APC Viewer.Tests/HomeControllerTests.cs
Normal file
@ -0,0 +1,282 @@
|
||||
using APCViewer.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Shared;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
|
||||
namespace APCViewer.Tests
|
||||
{
|
||||
|
||||
[TestClass]
|
||||
public class HomeControllerTests : LoggingUnitTesting, IHomeController
|
||||
{
|
||||
|
||||
private static long _Sequence;
|
||||
private static WebClient _WebClient;
|
||||
private static string _WorkingDirectory;
|
||||
private static Singleton.IBackground _Background;
|
||||
private static Controllers.HomeController _HomeController;
|
||||
private static HomeControllerTests _LoggingUnitTesting;
|
||||
internal static HomeControllerTests LoggingUnitTesting => _LoggingUnitTesting;
|
||||
|
||||
public HomeControllerTests() : base(testContext: null, declaringType: null)
|
||||
{
|
||||
if (_LoggingUnitTesting is null)
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
public HomeControllerTests(TestContext testContext) : base(testContext, new StackFrame().GetMethod().DeclaringType)
|
||||
{
|
||||
}
|
||||
|
||||
[ClassInitialize]
|
||||
public static void ClassInitialize(TestContext testContext)
|
||||
{
|
||||
if (_LoggingUnitTesting is null)
|
||||
_LoggingUnitTesting = new HomeControllerTests(testContext);
|
||||
_LoggingUnitTesting.Logger.LogInformation(string.Concat(testContext.TestName, " - ClassInitialize"));
|
||||
_WebClient = new WebClient();
|
||||
_Sequence = 637642624355251927;
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
_WorkingDirectory = Log.GetWorkingDirectory(assembly.GetName().Name, "IFXApps");
|
||||
Type type = new StackFrame().GetMethod().DeclaringType;
|
||||
_Background = new Singleton.Background(_LoggingUnitTesting.IsEnvironment, _LoggingUnitTesting.ConfigurationRoot, _WorkingDirectory);
|
||||
_HomeController = new Controllers.HomeController(new NullLogger<Controllers.HomeController>(), _Background, httpContextAccessor: null);
|
||||
_Background.Update(_LoggingUnitTesting.Logger, _WebClient);
|
||||
Assert.IsNotNull(_Background);
|
||||
Assert.IsFalse(string.IsNullOrEmpty(_Background.AppSettings.URLs));
|
||||
Assert.IsFalse(string.IsNullOrEmpty(_Background.AppSettings.Server));
|
||||
Assert.IsFalse(string.IsNullOrEmpty(_Background.AppSettings.MonARessource));
|
||||
}
|
||||
|
||||
[ClassCleanup()]
|
||||
public static void ClassCleanup()
|
||||
{
|
||||
if (!(_LoggingUnitTesting.Logger is null))
|
||||
_LoggingUnitTesting.Logger.LogInformation("Cleanup");
|
||||
if (!(_LoggingUnitTesting is null))
|
||||
_LoggingUnitTesting.Dispose();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Background()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.Background();
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.Background(bool? message_clear, bool? exceptions_clear, bool? set_is_primary_instance, bool? logistics_clear)
|
||||
{
|
||||
Background();
|
||||
return null;
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void DownloadCustomIPDSF()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.DownloadCustomIPDSF(ipdsf_file: "");
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.DownloadCustomIPDSF(string ipdsf_file)
|
||||
{
|
||||
DownloadCustomIPDSF();
|
||||
return null;
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void DownloadCustomPDSF()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.DownloadCustomPDSF(pdsf_file: "");
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.DownloadCustomPDSF(string pdsf_file)
|
||||
{
|
||||
DownloadCustomPDSF();
|
||||
return null;
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void DownloadIPDSF()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.DownloadIPDSF(_Sequence.ToString());
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.DownloadIPDSF(string id)
|
||||
{
|
||||
DownloadIPDSF();
|
||||
return null;
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void DownloadPDSF()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.DownloadPDSF(_Sequence.ToString());
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.DownloadPDSF(string id)
|
||||
{
|
||||
DownloadPDSF();
|
||||
return null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Encode()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.Encode();
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.Encode(string value)
|
||||
{
|
||||
Encode();
|
||||
return null;
|
||||
}
|
||||
|
||||
IActionResult IHomeController.Error()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Index()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.Index();
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.Index()
|
||||
{
|
||||
Index();
|
||||
return null;
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void IPDSF()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.IPDSF();
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.IPDSF(string directory, string filter, bool is_gaN, bool is_Si)
|
||||
{
|
||||
IPDSF();
|
||||
return null;
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void PDSF()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.PDSF();
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.PDSF(string directory, string filter, bool is_gaN, bool is_Si)
|
||||
{
|
||||
PDSF();
|
||||
return null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Privacy()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.Privacy();
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.Privacy()
|
||||
{
|
||||
Privacy();
|
||||
return null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TimePivot()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.TimePivot();
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
IActionResult IHomeController.TimePivot(bool is_gaN, bool is_Si)
|
||||
{
|
||||
TimePivot();
|
||||
return null;
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void ViewCustomIPDSF()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.ViewCustomIPDSF(ipdsf_file: "");
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
ContentResult IHomeController.ViewCustomIPDSF(string ipdsf_file)
|
||||
{
|
||||
ViewCustomIPDSF();
|
||||
return null;
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[TestMethod]
|
||||
public void ViewCustomPDSF()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.ViewCustomPDSF(pdsf_file: "");
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
ContentResult IHomeController.ViewCustomPDSF(string pdsf_file)
|
||||
{
|
||||
ViewCustomPDSF();
|
||||
return null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ViewIPDSF()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.ViewIPDSF(_Sequence.ToString());
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
ContentResult IHomeController.ViewIPDSF(string id)
|
||||
{
|
||||
ViewIPDSF();
|
||||
return null;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ViewPDSF()
|
||||
{
|
||||
IActionResult IActionResult = _HomeController.ViewPDSF(_Sequence.ToString());
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
|
||||
ContentResult IHomeController.ViewPDSF(string id)
|
||||
{
|
||||
ViewPDSF();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// dotnet build --runtime win-x64
|
||||
// dotnet test --no-build --filter ViewPDSF
|
||||
// dotnet test --runtime win-x64 --no-build --filter "ClassName=APCViewer.Tests.HomeTests & TestCategory=WindowsDevelopment" --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\")
|
||||
// dotnet test --runtime win-x64 --no-build --filter "ClassName=APCViewer.Tests.HomeTests & TestCategory=WindowsStaging" --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\")
|
||||
// dotnet test --runtime win-x64 --no-build --filter "ClassName=APCViewer.Tests.HomeTests & TestCategory=WindowsProduction" --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\")
|
||||
71
APC Viewer.Tests/Shared/LoggingUnitTesting.cs
Normal file
71
APC Viewer.Tests/Shared/LoggingUnitTesting.cs
Normal file
@ -0,0 +1,71 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Shared
|
||||
{
|
||||
|
||||
public class LoggingUnitTesting : UnitTesting, IDisposable
|
||||
{
|
||||
|
||||
protected ILogger<object> _Logger;
|
||||
protected ILoggerFactory _LoggerFactory;
|
||||
protected readonly LogLevel? _DefaultLogLevel;
|
||||
protected readonly LogLevel? _Log4netProviderLogLevel;
|
||||
protected readonly IConfigurationRoot _ConfigurationRoot;
|
||||
public ILogger<object> Logger => _Logger;
|
||||
public LogLevel? DefaultLogLevel => _DefaultLogLevel;
|
||||
public ILoggerFactory LoggerFactory => _LoggerFactory;
|
||||
public IConfigurationRoot ConfigurationRoot => _ConfigurationRoot;
|
||||
public LogLevel? Log4netProviderLogLevel => _Log4netProviderLogLevel;
|
||||
|
||||
public LoggingUnitTesting(TestContext testContext, Type declaringType) : base(testContext, declaringType)
|
||||
{
|
||||
_LoggerFactory = new LoggerFactory();
|
||||
if (testContext is null || declaringType is null)
|
||||
{
|
||||
_ConfigurationRoot = null;
|
||||
_DefaultLogLevel = null;
|
||||
_Log4netProviderLogLevel = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
LogLevel logLevel;
|
||||
IConfigurationSection configurationSection;
|
||||
List<LogLevel> logLevels = new List<LogLevel>();
|
||||
string defaultLogLevelSection = "Logging:LogLevel:Default";
|
||||
string log4netProviderLogLevelSection = "Logging:LogLevel:Log4netProvider";
|
||||
string[] sections = new string[] { defaultLogLevelSection, log4netProviderLogLevelSection };
|
||||
IConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
|
||||
.AddEnvironmentVariables()
|
||||
.AddJsonFile(_IsEnvironment.AppSettingsFileName, optional: false, reloadOnChange: true);
|
||||
_ConfigurationRoot = configurationBuilder.Build();
|
||||
foreach (string section in sections)
|
||||
{
|
||||
configurationSection = _ConfigurationRoot.GetSection(section);
|
||||
if (configurationSection is null)
|
||||
logLevel = LogLevel.Debug;
|
||||
else if (!Enum.TryParse<LogLevel>(configurationSection.Value, out logLevel))
|
||||
logLevel = LogLevel.Debug;
|
||||
logLevels.Add(logLevel);
|
||||
}
|
||||
_DefaultLogLevel = logLevels[0];
|
||||
_Log4netProviderLogLevel = logLevels[1];
|
||||
}
|
||||
if (DefaultLogLevel.HasValue)
|
||||
_LoggerFactory.AddProvider(new DebugProvider(DefaultLogLevel.Value));
|
||||
if (DefaultLogLevel.HasValue)
|
||||
_LoggerFactory.AddProvider(new ConsoleProvider(DefaultLogLevel.Value));
|
||||
_Logger = _LoggerFactory.CreateLogger<object>();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_LoggerFactory.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
93
APC Viewer.Tests/Shared/UnitTesting.cs
Normal file
93
APC Viewer.Tests/Shared/UnitTesting.cs
Normal file
@ -0,0 +1,93 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
|
||||
namespace Shared
|
||||
{
|
||||
|
||||
public class UnitTesting
|
||||
{
|
||||
|
||||
protected readonly IsEnvironment _IsEnvironment;
|
||||
|
||||
public IsEnvironment IsEnvironment => _IsEnvironment;
|
||||
|
||||
public UnitTesting(TestContext testContext, Type declaringType)
|
||||
{
|
||||
if (testContext is null || declaringType is null)
|
||||
_IsEnvironment = null;
|
||||
else
|
||||
{
|
||||
string projectDirectory = GetProjectDirectory(testContext);
|
||||
string json = JsonSerializer.Serialize(testContext.Properties);
|
||||
string vsCodeDirectory = Path.Combine(projectDirectory, ".vscode");
|
||||
if (!Directory.Exists(vsCodeDirectory))
|
||||
Directory.CreateDirectory(vsCodeDirectory);
|
||||
string launchText = GetLaunchText();
|
||||
File.WriteAllText(Path.Combine(vsCodeDirectory, "launch.json"), launchText);
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
if (!json.Contains("Debugger.IsAttached") || Debugger.IsAttached)
|
||||
break;
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
MethodBase methodBase = declaringType.GetMethod(testContext.TestName);
|
||||
if (!(methodBase is null))
|
||||
{
|
||||
TestCategoryAttribute testCategoryAttribute = methodBase.GetCustomAttribute<TestCategoryAttribute>();
|
||||
if (!(testCategoryAttribute is null))
|
||||
{
|
||||
foreach (string testCategory in testCategoryAttribute.TestCategories)
|
||||
_IsEnvironment = new IsEnvironment(testCategory);
|
||||
}
|
||||
}
|
||||
if (_IsEnvironment is null)
|
||||
_IsEnvironment = new IsEnvironment(processesCount: null, nullASPNetCoreEnvironmentIsDevelopment: Debugger.IsAttached, nullASPNetCoreEnvironmentIsProduction: !Debugger.IsAttached);
|
||||
}
|
||||
}
|
||||
|
||||
internal static string GetProjectDirectory(TestContext testContext)
|
||||
{
|
||||
string result;
|
||||
string[] checkFiles = null;
|
||||
result = Path.GetDirectoryName(testContext.DeploymentDirectory);
|
||||
for (int i = 0; i < int.MaxValue; i++)
|
||||
{
|
||||
if (string.IsNullOrEmpty(result))
|
||||
break;
|
||||
checkFiles = Directory.GetFiles(result, "*.Tests.*proj", SearchOption.TopDirectoryOnly);
|
||||
if (checkFiles.Any())
|
||||
break;
|
||||
result = Path.GetDirectoryName(result);
|
||||
}
|
||||
if (string.IsNullOrEmpty(result) || checkFiles is null || !checkFiles.Any())
|
||||
throw new Exception(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static string GetLaunchText()
|
||||
{
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.
|
||||
AppendLine("{").
|
||||
AppendLine(" \"configurations\": [").
|
||||
AppendLine(" {").
|
||||
AppendLine(" \"name\": \".NET Core Attach\",").
|
||||
AppendLine(" \"type\": \"coreclr\",").
|
||||
AppendLine(" \"request\": \"attach\",").
|
||||
AppendLine($" \"processId\": {System.Diagnostics.Process.GetCurrentProcess().Id}").
|
||||
AppendLine(" }").
|
||||
AppendLine(" ]").
|
||||
AppendLine("}");
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user