Files
raceplanner/backend/backend.Tests/Utilities/MockHttpContext.cs
T
Denis Urs Rudolph 571fe5bc7c Add comprehensive test suite infrastructure
- Create backend xUnit test project with Moq and FluentAssertions
- Add test utilities: TestDataFactory, MockHttpContext, TestUserClaims
- Create AuthControllerTests with comprehensive auth scenarios
- Install Jest and React Testing Library for frontend
- Configure jest.config.ts and jest.setup.ts with Next.js support
- Add test scripts to package.json
2026-04-05 22:16:44 +02:00

39 lines
1018 B
C#

using System.Security.Claims;
using Microsoft.AspNetCore.Http;
namespace backend.Tests.Utilities;
public static class MockHttpContext
{
public static HttpContext Create(
string userId = "test-user-id",
string email = "test@example.com",
string role = "Participant",
bool isAuthenticated = true)
{
var claims = new List<Claim>();
if (isAuthenticated)
{
claims.Add(new Claim(ClaimTypes.NameIdentifier, userId));
claims.Add(new Claim(ClaimTypes.Email, email));
claims.Add(new Claim(ClaimTypes.Role, role));
}
var identity = new ClaimsIdentity(claims, isAuthenticated ? "TestAuthType" : null);
var principal = new ClaimsPrincipal(identity);
var httpContext = new DefaultHttpContext
{
User = principal
};
return httpContext;
}
public static HttpContext CreateAnonymous()
{
return Create(isAuthenticated: false);
}
}