Fixing coverage
This commit is contained in:
80
MainProject.Tests/Models/Api/Response/ApiResponse_Tests.cs
Normal file
80
MainProject.Tests/Models/Api/Response/ApiResponse_Tests.cs
Normal file
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using BasicDotnetTemplate.MainProject;
|
||||
using BasicDotnetTemplate.MainProject.Models.Api.Response;
|
||||
using Microsoft.Extensions.DependencyModel.Resolution;
|
||||
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class ApiResponse_Tests
|
||||
{
|
||||
[TestMethod]
|
||||
public void IstantiateBaseResponse_OnlyStatus_Valid()
|
||||
{
|
||||
try
|
||||
{
|
||||
var baseResponse = new BaseResponse(200, null, null);
|
||||
Assert.IsTrue(baseResponse.Status == 200 && String.IsNullOrEmpty(baseResponse.Message) && baseResponse.Data == null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IstantiateBaseResponse_OnlyStatus_IsInvalid()
|
||||
{
|
||||
try
|
||||
{
|
||||
var baseResponse = new BaseResponse(201, null, null);
|
||||
Assert.IsFalse(baseResponse.Status == 200);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IstantiateBaseResponse_StatusAndMessage_Valid()
|
||||
{
|
||||
try
|
||||
{
|
||||
var baseResponse = new BaseResponse(200, "This is a test message", null);
|
||||
Assert.IsTrue(baseResponse.Status == 200 && baseResponse.Message == "This is a test message" && baseResponse.Data == null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void IstantiateBaseResponse_AllFields_Valid()
|
||||
{
|
||||
try
|
||||
{
|
||||
string[] data = { "Volvo", "BMW", "Ford", "Mazda" };
|
||||
var baseResponse = new BaseResponse(200, "This is a test message", data);
|
||||
Assert.IsTrue(baseResponse.Status == 200 && baseResponse.Message == "This is a test message" && baseResponse.Data == data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.InnerException);
|
||||
Assert.Fail($"An exception was thrown: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -22,12 +22,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers
|
||||
#nullable enable
|
||||
private static BaseResponse CreateResponse(HttpStatusCode status, string message, object? data = null)
|
||||
{
|
||||
return new BaseResponse()
|
||||
{
|
||||
Status = (int)status,
|
||||
Message = message,
|
||||
Data = data
|
||||
};
|
||||
return new BaseResponse((int)status, message, data);
|
||||
}
|
||||
|
||||
protected new IActionResult Created(string message, object? data = null)
|
||||
|
||||
@@ -2,10 +2,18 @@ namespace BasicDotnetTemplate.MainProject.Models.Api.Response;
|
||||
|
||||
public class BaseResponse
|
||||
{
|
||||
#nullable enable
|
||||
public BaseResponse(int status, string? message, dynamic? data)
|
||||
{
|
||||
this.Status = status;
|
||||
this.Message = message;
|
||||
this.Data = data;
|
||||
}
|
||||
#nullable disable
|
||||
public int Status { get; set; }
|
||||
#nullable enable
|
||||
public string? Message { get; set; }
|
||||
|
||||
public object? Data { get; set; }
|
||||
public virtual dynamic? Data { get; set; }
|
||||
#nullable disable
|
||||
}
|
||||
@@ -3,7 +3,6 @@ using System.Runtime.CompilerServices;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using NLog;
|
||||
using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
using BasicDotnetTemplate.MainProject.Utils;
|
||||
using System.Reflection;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject;
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
using BasicDotnetTemplate.MainProject.Models.Settings;
|
||||
|
||||
namespace BasicDotnetTemplate.MainProject.Utils;
|
||||
|
||||
public static class AppSettingsUtils
|
||||
{
|
||||
static AppSettingsUtils() { }
|
||||
public static bool CheckAppSettings(AppSettings appSetting)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user