Fixing coverage - 6
This commit is contained in:
@@ -8,6 +8,8 @@ using BasicDotnetTemplate.MainProject.Controllers;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
|
using BasicDotnetTemplate.MainProject.Models.Api.Response;
|
||||||
|
using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||||
|
|
||||||
|
|
||||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||||
@@ -25,7 +27,26 @@ public class BaseController_Tests
|
|||||||
IConfiguration configuration = TestUtils.CreateConfiguration();
|
IConfiguration configuration = TestUtils.CreateConfiguration();
|
||||||
VersionController versionController = new VersionController(configuration);
|
VersionController versionController = new VersionController(configuration);
|
||||||
var result = versionController.GetVersion();
|
var result = versionController.GetVersion();
|
||||||
Assert.IsTrue(((IStatusCodeActionResult)result).StatusCode == 200);
|
var objectResult = ((ObjectResult)result).Value;
|
||||||
|
if (objectResult != null)
|
||||||
|
{
|
||||||
|
var data = (BaseResponse)objectResult;
|
||||||
|
if (data.Data != null)
|
||||||
|
{
|
||||||
|
AppSettings appSettings = new AppSettings();
|
||||||
|
configuration.GetSection("AppSettings").Bind(appSettings);
|
||||||
|
string version = data.Data != null ? (string)data.Data : "";
|
||||||
|
Assert.IsTrue((((IStatusCodeActionResult)result).StatusCode == 200) && (version == appSettings.Settings?.Version));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Assert.Fail($"Unable to convert response value to BaseResponse because Data is null");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Assert.Fail($"Data is null");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
"Url": ""
|
"Url": ""
|
||||||
},
|
},
|
||||||
"OpenApiLicense": {
|
"OpenApiLicense": {
|
||||||
"Name": "",
|
"Name": "MIT License",
|
||||||
"Url": ""
|
"Url": "https://github.com/csimonapastore/BasicDotnetTemplate/blob/main/LICENSE.md"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"AppSettings" :
|
||||||
|
{
|
||||||
|
"Settings": {
|
||||||
|
"Name": "MainProject",
|
||||||
|
"Version": "v1.0",
|
||||||
|
"Description": "This template contains basic configuration for a .Net 8 backend"
|
||||||
|
},
|
||||||
|
"OpenApiSettings": {
|
||||||
|
"TermsOfServiceUrl": "",
|
||||||
|
"OpenApiContact": {
|
||||||
|
"Name": "",
|
||||||
|
"Url": ""
|
||||||
|
},
|
||||||
|
"OpenApiLicense": {
|
||||||
|
"Name": "",
|
||||||
|
"Url": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,27 +19,15 @@ namespace BasicDotnetTemplate.MainProject.Tests;
|
|||||||
|
|
||||||
public static class TestUtils
|
public static class TestUtils
|
||||||
{
|
{
|
||||||
public static IConfiguration? CreateConfiguration()
|
public static IConfiguration CreateConfiguration()
|
||||||
{
|
{
|
||||||
try
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(Array.Empty<string>());
|
||||||
{
|
AppSettings appSettings = ProgramUtils.AddConfiguration(ref builder, "D:\\Users\\Simona\\Documents\\Projects\\BasicDotnetTemplate\\MainProject.Tests\\JsonData");
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(Array.Empty<string>());
|
ProgramUtils.AddOpenApi(ref builder, appSettings);
|
||||||
AppSettings appSettings = ProgramUtils.AddConfiguration(ref builder, "D:\\Users\\Simona\\Documents\\Projects\\BasicDotnetTemplate\\MainProject.Tests\\JsonData");
|
AppSettings _appSettings = new AppSettings();
|
||||||
ProgramUtils.AddOpenApi(ref builder, appSettings);
|
builder.Configuration.GetSection("AppSettings").Bind(_appSettings);
|
||||||
AppSettings _appSettings = new AppSettings();
|
return builder.Configuration;
|
||||||
builder.Configuration.GetSection("AppSettings").Bind(_appSettings);
|
|
||||||
return builder.Configuration;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine(ex.InnerException);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public class ProgramUtils_Tests
|
|||||||
};
|
};
|
||||||
|
|
||||||
WebApplicationBuilder builder = WebApplication.CreateBuilder(Array.Empty<string>());
|
WebApplicationBuilder builder = WebApplication.CreateBuilder(Array.Empty<string>());
|
||||||
AppSettings realAppSettings = ProgramUtils.AddConfiguration(ref builder, "D:\\Users\\Simona\\Documents\\Projects\\BasicDotnetTemplate\\MainProject.Tests\\JsonData");
|
AppSettings realAppSettings = ProgramUtils.AddConfiguration(ref builder, "D:\\Users\\Simona\\Documents\\Projects\\BasicDotnetTemplate\\MainProject.Tests\\JsonData", "noApiConfigurationAppSettings.json");
|
||||||
OpenApiInfo realOpenApiInfo = ProgramUtils.CreateOpenApiInfo(realAppSettings);
|
OpenApiInfo realOpenApiInfo = ProgramUtils.CreateOpenApiInfo(realAppSettings);
|
||||||
|
|
||||||
var areEquals = expectedOpenApiInfo.Title == realOpenApiInfo.Title &&
|
var areEquals = expectedOpenApiInfo.Title == realOpenApiInfo.Title &&
|
||||||
@@ -115,8 +115,6 @@ public class ProgramUtils_Tests
|
|||||||
Assert.Fail($"An exception was thrown: {ex.Message}");
|
Assert.Fail($"An exception was thrown: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,8 +13,8 @@
|
|||||||
"Url": ""
|
"Url": ""
|
||||||
},
|
},
|
||||||
"OpenApiLicense": {
|
"OpenApiLicense": {
|
||||||
"Name": "",
|
"Name": "MIT License",
|
||||||
"Url": ""
|
"Url": "https://github.com/csimonapastore/BasicDotnetTemplate/blob/main/LICENSE.md"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user