Backend/e-suite.API/eSuite.API.UnitTests/Controllers/RoleControllerUnitTests/RoleControllerTestBase.cs
2026-01-20 21:50:10 +00:00

44 lines
1.4 KiB
C#

using System.Security.Claims;
using e_suite.API.Common;
using e_suite.UnitTestCore;
using eSuite.API.Controllers;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Moq;
namespace eSuite.API.UnitTests.Controllers.RoleControllerUnitTests;
public abstract class RoleControllerTestBase : TestBase
{
protected Mock<IRoleManager> _roleManagerMock = null!;
protected RoleController _roleController = null!;
public override async Task Setup()
{
await base.Setup();
_roleManagerMock = new Mock<IRoleManager>();
_roleController = new RoleController(_roleManagerMock.Object);
const long id = -1;
const string email = "email@mail.test";
const string displayName = "Testy McTester";
AddAuthorisedUserToController(id, email, displayName);
}
protected void AddAuthorisedUserToController(long id, string email, string displayName)
{
var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
{
new(ClaimTypes.PrimarySid, id.ToString()),
new(ClaimTypes.Email, email),
new(ClaimTypes.Name, displayName)
// other required and custom claims
}, "TestAuthentication"));
_roleController.ControllerContext = new ControllerContext
{
HttpContext = new DefaultHttpContext { User = user }
};
}
}