Integration Testing - Claims

Hi,
I am testing a service where one of the model is decorated with the following attributes, I’m having trouble mocking the permission to allow the test to pass.

[ValidateHasClaim(Permissions.Perm, Permissions.CanCreatePaymentPlan)]
[RequiresAnyRole( Roles.BackofficeStaff)]

I’m using a projected configured with Asp.net Identity and for the unit tests running sqlite in memory do I have to recreate all the asp.net identity tables or is there a better way?

You would need to populate the ClaimsPrincipal User property of the IRequest Context.

This is dependent on the Web Host used, e.g if you’re using Kestrel:

if (req is NetCoreRequest netReq)
{
    netReq.HttpContext.User = new(...);
}

Where the Request will be Authenticated for both ServiceStack and ASP .NET Requests or for just ServiceStack Requests you can use:

req.Items[Keywords.ClaimsPrincipal] = new ClaimsPrincipal(...);