45 lines
1.5 KiB
C#
45 lines
1.5 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.ProfileControllerUnitTests;
|
|
|
|
public abstract class ProfileControllerTestBase : TestBase
|
|
{
|
|
protected ProfileController _profileController = null!;
|
|
protected Mock<IUserManager> _userManagerMock = null!;
|
|
|
|
protected const string AccessDeniedText = "Access denied";
|
|
protected const string BadRequestText = "Bad request";
|
|
protected const string NotFoundText = "Not found";
|
|
protected const string LoginAcceptedText = "Login accepted";
|
|
|
|
public override async Task Setup()
|
|
{
|
|
await base.Setup();
|
|
|
|
_userManagerMock = new Mock<IUserManager>();
|
|
|
|
_profileController = new ProfileController(_userManagerMock.Object);
|
|
}
|
|
|
|
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"));
|
|
|
|
_profileController.ControllerContext = new ControllerContext
|
|
{
|
|
HttpContext = new DefaultHttpContext { User = user }
|
|
};
|
|
}
|
|
} |