apc-viewer/APC Viewer.Tests/BackgroundTests.cs

173 lines
6.6 KiB
C#

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\")