I'm new to ASP.NET Core. I need to mock ClaimsPrincipal
in an unit test in C#, for the following method:
public class MyTestHelper
{
public static string getName(this ClaimsPrincipal principal)
{
string name = principal.Claims.Any(c => c.Type= "test") ?
Convert.ToString(principal.Claims.Where(i => i.Type = "test").FirstOrDefault().Value);
}
}
This is what I've tried so far. But I get an error message saying cannot convert from IPrincipal
to ClaimsPrincipal
:
[Test]
public void getNameTest()
{
var principal = new Mock<IPrincipal>;
string name = MyTestHelper.getName(principal.Object);
}
Thank you for your help!