|
| 1 | +using CodeBeam.UltimateAuth.Core.Abstractions; |
| 2 | +using CodeBeam.UltimateAuth.Core.MultiTenancy; |
| 3 | +using CodeBeam.UltimateAuth.Tokens.EntityFrameworkCore; |
| 4 | +using Microsoft.Data.Sqlite; |
| 5 | +using Microsoft.EntityFrameworkCore; |
| 6 | + |
| 7 | +namespace CodeBeam.UltimateAuth.Tests.Unit.Tokens.Contracts; |
| 8 | + |
| 9 | +public sealed class EfCoreRefreshTokenStoreContractTests |
| 10 | + : RefreshTokenStoreContractTests |
| 11 | +{ |
| 12 | + protected override async Task<IRefreshTokenStoreTestDatabase> |
| 13 | + CreateDatabaseAsync() |
| 14 | + { |
| 15 | + var db = new Database(); |
| 16 | + await db.InitializeAsync(); |
| 17 | + return db; |
| 18 | + } |
| 19 | + |
| 20 | + private sealed class Database |
| 21 | + : IRefreshTokenStoreTestDatabase |
| 22 | + { |
| 23 | + private readonly SqliteConnection _connection; |
| 24 | + private readonly UAuthTokenDbContext _db; |
| 25 | + |
| 26 | + public Database() |
| 27 | + { |
| 28 | + _connection = |
| 29 | + new SqliteConnection("Data Source=:memory:"); |
| 30 | + |
| 31 | + var options = |
| 32 | + new DbContextOptionsBuilder<UAuthTokenDbContext>() |
| 33 | + .UseSqlite(_connection) |
| 34 | + .Options; |
| 35 | + |
| 36 | + _db = new UAuthTokenDbContext(options); |
| 37 | + } |
| 38 | + |
| 39 | + public async Task InitializeAsync() |
| 40 | + { |
| 41 | + await _connection.OpenAsync(); |
| 42 | + await _db.Database.EnsureCreatedAsync(); |
| 43 | + } |
| 44 | + |
| 45 | + public IRefreshTokenStore CreateStore(TenantKey tenant) |
| 46 | + => new EfCoreRefreshTokenStore<UAuthTokenDbContext>( |
| 47 | + _db, |
| 48 | + new TenantExecutionContext(tenant)); |
| 49 | + |
| 50 | + public async ValueTask DisposeAsync() |
| 51 | + { |
| 52 | + await _db.DisposeAsync(); |
| 53 | + await _connection.DisposeAsync(); |
| 54 | + } |
| 55 | + } |
| 56 | +} |
0 commit comments