2026-02-08 11:57:57 +01:00
|
|
|
using FluentResults;
|
|
|
|
|
using IdentityShroud.Core.Services;
|
|
|
|
|
using IdentityShroud.Core.Tests.Fixtures;
|
|
|
|
|
using IdentityShroud.Core.Tests.Substitutes;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace IdentityShroud.Core.Tests.Services;
|
|
|
|
|
|
|
|
|
|
public class RealmServiceTests : IClassFixture<DbFixture>
|
|
|
|
|
{
|
|
|
|
|
private readonly Db _db;
|
|
|
|
|
|
|
|
|
|
public RealmServiceTests(DbFixture dbFixture)
|
|
|
|
|
{
|
|
|
|
|
_db = dbFixture.CreateDbContext("realmservice");
|
|
|
|
|
|
|
|
|
|
if (!_db.Database.EnsureCreated())
|
|
|
|
|
TruncateTables();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TruncateTables()
|
|
|
|
|
{
|
|
|
|
|
_db.Database.ExecuteSqlRaw("TRUNCATE realm CASCADE;");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(null)]
|
|
|
|
|
[InlineData("a7c2a39c-3ed9-4790-826e-43bb2e5e480c")]
|
|
|
|
|
public async Task Create(string? idString)
|
|
|
|
|
{
|
|
|
|
|
Guid? realmId = null;
|
|
|
|
|
if (idString is not null)
|
|
|
|
|
realmId = new(idString);
|
|
|
|
|
|
|
|
|
|
var encryptionService = EncryptionServiceSubstitute.CreatePassthrough();
|
|
|
|
|
RealmService sut = new(_db, encryptionService);
|
|
|
|
|
|
|
|
|
|
var response = await sut.Create(
|
|
|
|
|
new(realmId, "slug", "New realm"),
|
|
|
|
|
TestContext.Current.CancellationToken);
|
|
|
|
|
|
|
|
|
|
RealmCreateResponse val = ResultAssert.Success(response);
|
|
|
|
|
if (realmId.HasValue)
|
2026-02-08 18:00:24 +01:00
|
|
|
Assert.Equal(realmId, val.Id);
|
2026-02-08 11:57:57 +01:00
|
|
|
else
|
2026-02-08 18:00:24 +01:00
|
|
|
Assert.NotEqual(Guid.Empty, val.Id);
|
2026-02-08 11:57:57 +01:00
|
|
|
|
2026-02-08 18:00:24 +01:00
|
|
|
Assert.Equal("slug", val.Slug);
|
|
|
|
|
Assert.Equal("New realm", val.Name);
|
|
|
|
|
|
|
|
|
|
// TODO verify data has been stored!
|
2026-02-08 11:57:57 +01:00
|
|
|
}
|
|
|
|
|
}
|