Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
9 commits
Select commit Hold shift + click to select a range
be5da4f
移行の領域のドメインの単体試験を `Carina.Domain.Tests/Unit/Migration` へ移し、クラスを試す型ごとにま…
fyui001 Nov 13, 2026
8a2e689
移行の記録を読む口の機能試験と口の一覧の試験を `Feature/Migration` の `GetMigrationRecordActi…
fyui001 Nov 13, 2026
82f1534
移行の記録の表の試験と移行の道具の引数と報告の試験を `Carina.Db.Tests` の決めた置き場所へ移し、移行の排他の試験を表の試…
fyui001 Nov 13, 2026
456b88b
移行の記録のリポジトリの DB を使う試験を `DbIntegration/Domain/Migration` へ移し、試すものは DI …
fyui001 Nov 13, 2026
285f8d1
移行で変換したルールを番組検索の条件として読み戻す試験を `ProgrammeSearchQueryTests` へ移す。
fyui001 Nov 13, 2026
7752b8c
移行の領域のインフラの単体試験を `Unit/Infra/Migration` へ移し、移行全体を通す試験とほかの領域の型を試す試験は古い…
fyui001 Nov 13, 2026
938b6c7
まだ移していない領域の一覧から移行の領域を外し、移行の道具の型と記録の表の試験を移行の領域の一覧に載せる。
fyui001 Nov 13, 2026
8a04acb
アプリの口の一覧から移行の口を確かめる試験を、ほかの領域の口の一覧の試験と同じ `RoutedSurfaceTests` へ移す。
fyui001 Nov 13, 2026
8406f90
移行の流れの試験の後片付けで一つの消去が失敗しても残りの一時ディレクトリを消し、補助の関数を試験の後ろへまとめる。
fyui001 Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

using Carina.Domain.Migration;

namespace Carina.Api.Tests.FeatureTest;
namespace Carina.Api.Tests.Feature.Migration;

public sealed class MigrationRecordEndpointTests
[Trait("Category", "Feature")]
public sealed class GetMigrationRecordActionTests
{
private const string Record = "/api/migration/record";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Net.Http.Headers;
using System.Text.Json;

using Carina.Api.Tests.FeatureTest;
using Carina.Domain.Base;
using Carina.Domain.Encodings;
using Carina.Domain.Migration;
Expand All @@ -12,7 +13,7 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;

namespace Carina.Api.Tests.FeatureTest;
namespace Carina.Api.Tests.Feature.Migration;

internal sealed class HeldMigrationRecord : IMigrationRecordRepository
{
Expand Down
65 changes: 0 additions & 65 deletions tests/Carina.Api.Tests/FeatureTest/MigrationSurfaceTests.cs

This file was deleted.

53 changes: 53 additions & 0 deletions tests/Carina.Api.Tests/FeatureTest/RoutedSurfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public sealed class RoutedSurfaceTests(TestingWebApplicationFactory factory)
{
private const int TheSurfacesThisRepositoryHadWhenTheSweepWasWritten = 50;

private const string MigrationRoot = "/api/migration";

[Fact]
public void EveryRoutedSurfaceSaysWhetherItDestroys()
{
Expand Down Expand Up @@ -421,6 +423,51 @@ public void AskingForTheLedgerToBeCheckedDiscardsNothing()
.Effect);
}

[Fact]
public void TheMigrationSurfaceIsTheOneTheRecordIsReadThrough()
=> Assert.Equal(
["GET /api/migration/record"],
MigrationSurfaces().Select(surface => surface.ToString()).Order(StringComparer.Ordinal).ToArray());

[Fact]
public void NothingAnywhereElseOffersAMigrationOfItsOwn()
=> Assert.Equal(
["/api/migration/record"],
Inventory()
.Select(surface => surface.Pattern)
.Where(pattern => pattern.Contains("migration", StringComparison.OrdinalIgnoreCase))
.Distinct(StringComparer.Ordinal)
.Order(StringComparer.Ordinal)
.ToArray());

[Fact]
public void NothingUnderTheMigrationSurfaceIsAskedForOnAMethodThatWrites()
=> Assert.All(MigrationSurfaces(), surface => Assert.True(
HttpMethods.IsGet(surface.Method),
$"{surface} reaches the record on a method that is not a read"));

[Fact]
public void NothingUnderTheMigrationSurfaceChangesAnythingOrSaysItDestroys()
=> Assert.All(MigrationSurfaces(), surface => Assert.Equal(EndpointEffect.Reading, surface.Effect));

[Fact]
public void NothingUnderTheMigrationSurfaceDeletes()
=> Assert.Empty(EndpointRules.SurfacesThatDeleteUnder(Inventory(), MigrationRoot));

[Fact]
public void TheRootIsReadAsAWholeSegmentAndNotAsLeadingLetters()
{
RoutedSurface[] inventory =
[
new("POST", "/api/migrations-of-a-kind/run", EndpointEffect.Changing),
new("POST", "/api/migration/run", EndpointEffect.Changing),
];

Assert.Equal(
["POST /api/migration/run"],
inventory.Where(UnderTheMigrationRoot).Select(surface => surface.ToString()).ToArray());
}

[Fact]
public void TheInventoryHoldsTheSurfacesTheDocumentCannotDescribe()
{
Expand Down Expand Up @@ -511,5 +558,11 @@ public async Task APathThatMerelyLooksLikeAnEnumeratedSurfaceIsRefused(string pa
Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);
}

private static bool UnderTheMigrationRoot(RoutedSurface surface)
=> string.Equals(surface.Pattern, MigrationRoot, StringComparison.Ordinal)
|| surface.Pattern.StartsWith(MigrationRoot + "/", StringComparison.Ordinal);

private IEnumerable<RoutedSurface> MigrationSurfaces() => Inventory().Where(UnderTheMigrationRoot);

private IReadOnlyList<RoutedSurface> Inventory() => RouteInventory.Of(factory);
}
4 changes: 3 additions & 1 deletion tests/Carina.Conventions.Tests/TestLayoutRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public static class TestLayoutRules
"Integrity",
"Live",
"Machines",
"Migration",
"Net",
"Persistence",
"Playback",
Expand Down Expand Up @@ -66,6 +65,8 @@ public static class TestLayoutRules
new("Epg", "src/Carina.Api/Events/ProgrammeFeedReaders.cs"),
new("Epg", "src/Carina.Api/Events/ProgrammeFeedStream.cs"),
new("Logos", "src/Carina.Api/Logos/LogoDelivery.cs"),
new("Migration", "src/Carina.Db/CarryArguments.cs"),
new("Migration", "src/Carina.Db/CarrySaid.cs"),
new("Notifications", "src/Carina.Api/Requests/NotificationRequests.cs"),
new("Notifications", "src/Carina.Api/Services/NotificationDestinationService.cs"),
new("Notifications", "src/Carina.Api/Services/NotificationPushService.cs"),
Expand Down Expand Up @@ -111,6 +112,7 @@ public static class TestLayoutRules
new("Channels", "LogoVisitSchema"),
new("Channels", "ServiceReachSchema"),
new("Channels", "StationLogoSchema"),
new("Migration", "MigrationRecordSchema"),
new("Programmes", "ProgrammeSearchFoldingSchema"),
new("Quality", "QualityTablesDroppedWholeSchema"),
new("Recordings", "RecordingBroadcastGroupSchema"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using Carina.Domain.Migration;
using Carina.Infrastructure.Migration;
using Carina.Infrastructure.Persistence;

using Npgsql;

namespace Carina.Db.Tests;
namespace Carina.Db.Tests.DbIntegration.Infra.Migration;

[Collection(ConnectionEnvironmentCollection.Name)]
[Trait("Category", "DbIntegration")]
Expand All @@ -13,6 +15,8 @@ public sealed class MigrationRecordSchemaTests(MigratedScratchDatabase database)

private const string Ended = "timestamptz '2026-09-08 03:04:00+00'";

private static readonly CancellationToken Cancel = CancellationToken.None;

public static TheoryData<string> Refusals => Named(MigrationRefusals.All.Select(refusal => refusal.ToString()));

public static TheoryData<string> Counted =>
Expand Down Expand Up @@ -337,6 +341,37 @@ await CountAsync(
$"SELECT count(*) FROM migration_rule_proposal WHERE run_id = '{run}' AND rule_id IS NULL"));
}

[Fact]
public async Task ASecondRunIsRefusedWhileTheFirstStillHoldsTheLease()
{
await using CarinaDbContext first = CarinaDbContextFactory.Create(database.ConnectionString);
await using CarinaDbContext second = CarinaDbContextFactory.Create(database.ConnectionString);

IAsyncDisposable? held = await new MigrationLease(first).TakeAsync(Cancel);

Assert.NotNull(held);
Assert.Null(await new MigrationLease(second).TakeAsync(Cancel));

await held.DisposeAsync();
}

[Fact]
public async Task TheNextRunGetsTheLeaseOnceTheFirstHasGivenItBack()
{
await using CarinaDbContext first = CarinaDbContextFactory.Create(database.ConnectionString);
await using CarinaDbContext second = CarinaDbContextFactory.Create(database.ConnectionString);

IAsyncDisposable? held = await new MigrationLease(first).TakeAsync(Cancel);
Assert.NotNull(held);
await held.DisposeAsync();

IAsyncDisposable? next = await new MigrationLease(second).TakeAsync(Cancel);

Assert.NotNull(next);

await next.DisposeAsync();
}

private static TheoryData<string> Named(IEnumerable<string> names)
{
TheoryData<string> data = [];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Carina.Domain.Migration;

namespace Carina.Db.Tests;
namespace Carina.Db.Tests.Unit.Infra.Migration;

[Trait("Category", "Unit")]
public sealed class CarryArgumentsTests
{
[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
using Carina.Domain.Encodings;
using Carina.Domain.Migration;

namespace Carina.Db.Tests;
namespace Carina.Db.Tests.Unit.Infra.Migration;

[Trait("Category", "Unit")]
public sealed class CarrySaidTests
{
private static readonly DateTime Began = new(2026, 9, 8, 3, 0, 0, DateTimeKind.Utc);
Expand Down
Loading
Loading