Fixing coverage - 11
This commit is contained in:
45
MainProject.Tests/Controllers/RootController_Tests.cs
Normal file
45
MainProject.Tests/Controllers/RootController_Tests.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Net;
|
||||||
|
using System.Net.Http;
|
||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using BasicDotnetTemplate.MainProject;
|
||||||
|
using BasicDotnetTemplate.MainProject.Controllers;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
|
using BasicDotnetTemplate.MainProject.Models.Api.Response;
|
||||||
|
using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||||
|
|
||||||
|
|
||||||
|
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class RootController_Test
|
||||||
|
{
|
||||||
|
[TestMethod]
|
||||||
|
public void GetRoot_Valid()
|
||||||
|
{
|
||||||
|
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
RootController rootController = new RootController();
|
||||||
|
var result = rootController.GetRoot();
|
||||||
|
if (result != null)
|
||||||
|
{
|
||||||
|
var data = (OkResult)result;
|
||||||
|
Assert.IsTrue(data.StatusCode == 200);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Assert.Fail($"Data is null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex.InnerException);
|
||||||
|
Assert.Fail($"An exception was thrown: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,25 @@ namespace BasicDotnetTemplate.MainProject.Tests;
|
|||||||
public class BaseController_Tests
|
public class BaseController_Tests
|
||||||
{
|
{
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void BaseControllerInit_Valid()
|
public void BaseController_NullConfiguration()
|
||||||
|
{
|
||||||
|
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||||
|
var exception = true;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_ = new VersionController(null);
|
||||||
|
exception = false;
|
||||||
|
Assert.Fail($"This test should not pass as configuration is null");
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
Assert.IsTrue(exception);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void VersionController_GetVersion_Valid()
|
||||||
{
|
{
|
||||||
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user