DD.WellWorkover.Cloud/AsbCloudWebApi.Tests/ControllersTests/ControllerExtentions.cs
2022-06-15 14:57:37 +05:00

27 lines
787 B
C#

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
namespace AsbCloudWebApi.Tests.ControllersTests
{
static class ControllerExtentions
{
public static void AddUser(this ControllerBase controller)
{
var claims = new Claim[] { new Claim("idCompany", "1") };
controller.AddUser(claims);
}
public static void AddUser(this ControllerBase controller, Claim[] claims)
{
var identity = new ClaimsIdentity(claims, "mock");
var user = new ClaimsPrincipal(identity);
controller.ControllerContext = new ControllerContext()
{
HttpContext = new DefaultHttpContext() { User = user }
};
}
}
}