Change
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System.Security.Claims;
|
||||
using Api.Models;
|
||||
using Api.Services;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Tests;
|
||||
|
||||
internal static class TestSupport
|
||||
{
|
||||
public static AppDbContext CreateDbContext(string? databaseName = null)
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseInMemoryDatabase(databaseName ?? Guid.NewGuid().ToString())
|
||||
.Options;
|
||||
|
||||
return new AppDbContext(options);
|
||||
}
|
||||
|
||||
public static ClaimsPrincipal CreatePrincipal(params Claim[] claims)
|
||||
{
|
||||
return new ClaimsPrincipal(new ClaimsIdentity(claims, "TestAuth"));
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class OAuthValidationServiceStub : IOAuthValidationService
|
||||
{
|
||||
public (bool IsValid, ClaimsPrincipal? Principal, string? ErrorMessage) ValidationResult { get; set; }
|
||||
|
||||
public (string Email, string? FirstName, string? LastName, string? ProfilePictureUrl, string ProviderId) UserInfo { get; set; }
|
||||
|
||||
public (string Email, string? FirstName, string? LastName, string? ProfilePictureUrl, string ProviderId) AsyncUserInfo { get; set; }
|
||||
|
||||
public Task<(bool IsValid, ClaimsPrincipal? Principal, string? ErrorMessage)> ValidateIdTokenAsync(string idToken, string provider)
|
||||
{
|
||||
return Task.FromResult(ValidationResult);
|
||||
}
|
||||
|
||||
public (string Email, string? FirstName, string? LastName, string? ProfilePictureUrl, string ProviderId) ExtractUserInfo(ClaimsPrincipal principal, string provider)
|
||||
{
|
||||
return UserInfo;
|
||||
}
|
||||
|
||||
public Task<(string Email, string? FirstName, string? LastName, string? ProfilePictureUrl, string ProviderId)> ExtractUserInfoAsync(ClaimsPrincipal principal, string provider, string? idToken = null, string? accessToken = null)
|
||||
{
|
||||
return Task.FromResult(AsyncUserInfo);
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class JwtServiceStub : IJwtService
|
||||
{
|
||||
public string GeneratedToken { get; set; } = "test-access-token";
|
||||
|
||||
public DateTime Expiration { get; set; } = DateTime.UtcNow.AddHours(1);
|
||||
|
||||
public string GenerateToken(User user)
|
||||
{
|
||||
return GeneratedToken;
|
||||
}
|
||||
|
||||
public ClaimsPrincipal? ValidateToken(string token)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public DateTime GetTokenExpiration(string token)
|
||||
{
|
||||
return Expiration;
|
||||
}
|
||||
}
|
||||
@@ -11,11 +11,16 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Aspire.Hosting.Testing" Version="9.3.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.18" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.2" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../Api/Api.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="System.Net" />
|
||||
<Using Include="Microsoft.Extensions.DependencyInjection" />
|
||||
|
||||
Reference in New Issue
Block a user