Adding tests

This commit is contained in:
2025-03-26 23:43:44 +01:00
parent 9f595779ee
commit c9390479bb
5 changed files with 132 additions and 39 deletions

View File

@@ -19,12 +19,24 @@ using BasicDotnetTemplate.MainProject.Core.Database;
using BasicDotnetTemplate.MainProject.Services;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Mvc.Controllers;
namespace BasicDotnetTemplate.MainProject.Tests;
public static class TestUtils
{
public static AuthorizationFilterContext CreateAuthorizationContext()
{
var httpContext = new DefaultHttpContext();
var actionContext = new ActionContext(httpContext, new RouteData(), new ControllerActionDescriptor());
return new AuthorizationFilterContext(actionContext, new List<IFilterMetadata>());
}
public static IConfiguration CreateConfiguration()
{
WebApplicationBuilder builder = WebApplication.CreateBuilder(Array.Empty<string>());
@@ -64,6 +76,16 @@ public static class TestUtils
return context;
}
public static BaseService CreateBaseService()
{
IConfiguration configuration = CreateConfiguration();
var optionsBuilder = new DbContextOptionsBuilder<SqlServerContext>();
optionsBuilder.UseSqlServer(GetSqlConnectionString(configuration));
SqlServerContext sqlServerContext = CreateInMemorySqlContext();
var httpContextAccessor = new Mock<IHttpContextAccessor>();
return new BaseService(httpContextAccessor.Object, configuration, sqlServerContext);
}
public static AuthService CreateAuthService()
{
IConfiguration configuration = CreateConfiguration();