165 lines
6.1 KiB
C#
165 lines
6.1 KiB
C#
using EDAViewer.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using Shared;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Net;
|
|
using System.Reflection;
|
|
|
|
namespace EDAViewer.Tests
|
|
{
|
|
|
|
[TestClass]
|
|
public class HomeControllerTests : LoggingUnitTesting, IHomeController
|
|
{
|
|
|
|
private static string _WorkingDirectory;
|
|
private static AppSettings _AppSettings;
|
|
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"));
|
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
|
_AppSettings = _LoggingUnitTesting.ConfigurationRoot.Get<AppSettings>();
|
|
Assert.IsFalse(string.IsNullOrEmpty(_AppSettings.WorkingDirectoryName));
|
|
_WorkingDirectory = Log.GetWorkingDirectory(assembly.GetName().Name, _AppSettings.WorkingDirectoryName);
|
|
_Background = new Singleton.Background(_LoggingUnitTesting.IsEnvironment, _AppSettings, _WorkingDirectory);
|
|
_HomeController = new Controllers.HomeController(new NullLogger<Controllers.HomeController>(), _LoggingUnitTesting.IsEnvironment, _Background, _AppSettings);
|
|
_Background.Update(_LoggingUnitTesting.Logger);
|
|
Assert.IsNotNull(_Background);
|
|
Assert.IsFalse(string.IsNullOrEmpty(_AppSettings.URLs));
|
|
Assert.IsFalse(string.IsNullOrEmpty(_AppSettings.Server));
|
|
Assert.IsFalse(string.IsNullOrEmpty(_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(ActionResult))]
|
|
public void Background()
|
|
{
|
|
IActionResult IActionResult = _HomeController.Background();
|
|
Assert.IsTrue(true);
|
|
}
|
|
|
|
public IActionResult Background(bool? message_clear, bool? exceptions_clear, bool? set_is_primary_instance, int? invoke_eda_dcp)
|
|
{
|
|
Background();
|
|
return null;
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory(nameof(ActionResult))]
|
|
public void Encode()
|
|
{
|
|
IActionResult IActionResult = _HomeController.Encode();
|
|
Assert.IsTrue(true);
|
|
}
|
|
|
|
public IActionResult Encode(string value)
|
|
{
|
|
Encode();
|
|
return null;
|
|
}
|
|
|
|
public IActionResult Error()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory(nameof(ActionResult))]
|
|
public void Index()
|
|
{
|
|
IActionResult IActionResult = _HomeController.Index();
|
|
Assert.IsTrue(true);
|
|
}
|
|
|
|
IActionResult IHomeController.Index()
|
|
{
|
|
Index();
|
|
return null;
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory(nameof(ActionResult))]
|
|
public void Privacy()
|
|
{
|
|
IActionResult IActionResult = _HomeController.Privacy();
|
|
Assert.IsTrue(true);
|
|
}
|
|
|
|
IActionResult IHomeController.Privacy()
|
|
{
|
|
Privacy();
|
|
return null;
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory(nameof(ActionResult))]
|
|
public void ViewEdaHtmlDiff()
|
|
{
|
|
IActionResult IActionResult = _HomeController.ViewEdaHtmlDiff();
|
|
Assert.IsTrue(true);
|
|
}
|
|
|
|
public IActionResult ViewEdaHtmlDiff(WithEnvironment withEnvironment)
|
|
{
|
|
ViewEdaHtmlDiff();
|
|
return null;
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory(nameof(ActionResult))]
|
|
public void GetDirectoriesOrFiles()
|
|
{
|
|
//ActionResult<IEnumerable<SelectListItem>> GetDirectoriesOrFiles(string path = null, bool? upDirectory = null, string filter = null)
|
|
ActionResult<IEnumerable<SelectListItem>> actionResults = _HomeController.GetDirectoriesOrFiles();
|
|
Assert.IsTrue(true);
|
|
}
|
|
|
|
public ActionResult<IEnumerable<SelectListItem>> GetDirectoriesOrFiles(string path, bool? upDirectory, string filter)
|
|
{
|
|
GetDirectoriesOrFiles();
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// dotnet build --runtime win-x64
|
|
// dotnet test --runtime win-x64 --no-build --filter GetDirectoriesOrFiles --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\")
|
|
// dotnet test --runtime win-x64 --no-build --filter "ClassName=EDAViewer.Tests.BackgroundTests & TestCategory=WindowsDevelopment" --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\")
|
|
// dotnet test --runtime win-x64 --no-build --filter "ClassName=EDAViewer.Tests.BackgroundTests & TestCategory=WindowsStaging" --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\")
|
|
// dotnet test --runtime win-x64 --no-build --filter "ClassName=EDAViewer.Tests.BackgroundTests & TestCategory=WindowsProduction" --% -- TestRunParameters.Parameter(name=\"Debug\", value=\"Debugger.IsAttached\") |