Various changes (Controller and test)
- Added RootController - Added new methods in BaseController - Added BaseResponse - Changed Program structure - Added first basic test for Program
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
using BasicDotnetTemplate.MainProject.Utils;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests
|
||||
{
|
||||
[TestClass]
|
||||
public class AppSettingsUtils_Tests
|
||||
{
|
||||
private readonly AppSettings _appSettings;
|
||||
|
||||
public AppSettingsUtils_Tests()
|
||||
{
|
||||
_appSettings = new AppSettings();
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void AppSettingsUtils_Tests_IsValid()
|
||||
{
|
||||
bool result = AppSettingsUtils.CheckAppSettings(_appSettings);
|
||||
|
||||
Assert.IsTrue(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
MainProject.Tests/Program_Tests.cs
Normal file
67
MainProject.Tests/Program_Tests.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using BasicDotnetTemplate.MainProject;
|
||||
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class Program_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public async Task Program_Configuration_IsValid()
|
||||
{
|
||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||
|
||||
try
|
||||
{
|
||||
var reflectionType = typeof(ReflectionProgram);
|
||||
|
||||
if (reflectionType != null)
|
||||
{
|
||||
MethodInfo[] methods = reflectionType.GetMethods(); //Using BindingFlags.NonPublic does not show any results
|
||||
|
||||
MethodInfo? execute = null;
|
||||
|
||||
foreach (MethodInfo m in methods)
|
||||
{
|
||||
if (m.Name == "LaunchConfiguration")
|
||||
{
|
||||
execute = m;
|
||||
}
|
||||
}
|
||||
|
||||
if (execute != null)
|
||||
{
|
||||
object initializeObj = execute.Invoke(null, new object[] { });
|
||||
MethodInfo initialize = (MethodInfo)initializeObj;
|
||||
if (initialize != null)
|
||||
{
|
||||
initialize.Invoke(null, new object[] { new string[] { } });
|
||||
Assert.IsTrue(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail("Initialize is null.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail("Initialize method not found in Program class.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail("Program class not found in the assembly.");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user