DD.WellWorkover.Cloud/AsbCloudWebApi.Tests/ControllersTests/ControllerExtentions.cs

32 lines
903 B
C#
Raw Normal View History

2022-01-09 11:46:27 +05:00
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
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 }
};
}
}
}