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:
2024-05-04 17:51:11 +02:00
parent d3ba42e57a
commit 708966fcf8
8 changed files with 172 additions and 28 deletions

View 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}");
}
}
}