refactor(arena-two-pick): route entry/finish through InventoryService
Replace RewardGrantService + ICurrencySpendService + IViewerEntitlements with IInventoryService. tx.IsFreeplay replaces FakeEntitlements.IsFreeplay; debit helpers take IInventoryTransaction. ComputePostStateRewardList deleted (replaced by result.RewardList from CommitAsync). Update 5 test files to new 8-arg ctor. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ using SVSim.Database.Models;
|
||||
using SVSim.Database.Repositories.Globals;
|
||||
using SVSim.Database.Repositories.Viewer;
|
||||
using SVSim.Database.Services;
|
||||
using SVSim.Database.Services.Inventory;
|
||||
using SVSim.EmulatedEntrypoint.Services;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
@@ -25,19 +26,6 @@ public class ArenaTwoPickServiceDraftTests
|
||||
};
|
||||
}
|
||||
|
||||
private sealed class FakeEntitlements : IViewerEntitlements
|
||||
{
|
||||
public bool IsFreeplay { get; init; }
|
||||
|
||||
public long EffectiveBalance(SVSim.Database.Models.Viewer viewer, SpendCurrency currency) => 0;
|
||||
public bool OwnsCard(SVSim.Database.Models.Viewer viewer, long cardId) => IsFreeplay;
|
||||
public bool OwnsCosmetic(SVSim.Database.Models.Viewer viewer, CosmeticType type, int id) => IsFreeplay;
|
||||
public Task<IReadOnlyList<OwnedCardEntry>> EffectiveOwnedCardsAsync(SVSim.Database.Models.Viewer viewer, CancellationToken ct = default)
|
||||
=> Task.FromResult<IReadOnlyList<OwnedCardEntry>>(new List<OwnedCardEntry>());
|
||||
public Task<EffectiveCosmetics> EffectiveCosmeticsAsync(SVSim.Database.Models.Viewer viewer, CancellationToken ct = default)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
private static async Task<(IArenaTwoPickService, IArenaTwoPickRunRepository, long viewerId)> SetupWithActiveRunAsync(int classChosen = 0)
|
||||
{
|
||||
var factory = new SVSimTestFactory();
|
||||
@@ -73,11 +61,9 @@ public class ArenaTwoPickServiceDraftTests
|
||||
new FakePool(),
|
||||
scope.ServiceProvider.GetRequiredService<IGameConfigService>(),
|
||||
scope.ServiceProvider.GetRequiredService<IViewerRepository>(),
|
||||
scope.ServiceProvider.GetRequiredService<RewardGrantService>(),
|
||||
new FakeEntitlements(),
|
||||
scope.ServiceProvider.GetRequiredService<IInventoryService>(),
|
||||
new SystemRandom(seed: 1),
|
||||
db,
|
||||
scope.ServiceProvider.GetRequiredService<ICurrencySpendService>());
|
||||
db);
|
||||
|
||||
return (svc, runs, 7);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using SVSim.Database.Models;
|
||||
using SVSim.Database.Repositories.Globals;
|
||||
using SVSim.Database.Repositories.Viewer;
|
||||
using SVSim.Database.Services;
|
||||
using SVSim.Database.Services.Inventory;
|
||||
using SVSim.EmulatedEntrypoint.Services;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
@@ -23,24 +24,10 @@ public class ArenaTwoPickServiceEntryTests
|
||||
=> throw new NotSupportedException("pool not used in EntryAsync");
|
||||
}
|
||||
|
||||
/// <summary>Minimal fake that exposes only <see cref="IsFreeplay"/>.</summary>
|
||||
private sealed class FakeEntitlements : IViewerEntitlements
|
||||
{
|
||||
public bool IsFreeplay { get; init; }
|
||||
|
||||
public long EffectiveBalance(SVSim.Database.Models.Viewer viewer, SpendCurrency currency) => 0;
|
||||
public bool OwnsCard(SVSim.Database.Models.Viewer viewer, long cardId) => IsFreeplay;
|
||||
public bool OwnsCosmetic(SVSim.Database.Models.Viewer viewer, CosmeticType type, int id) => IsFreeplay;
|
||||
public Task<IReadOnlyList<OwnedCardEntry>> EffectiveOwnedCardsAsync(SVSim.Database.Models.Viewer viewer, CancellationToken ct = default)
|
||||
=> Task.FromResult<IReadOnlyList<OwnedCardEntry>>(new List<OwnedCardEntry>());
|
||||
public Task<EffectiveCosmetics> EffectiveCosmeticsAsync(SVSim.Database.Models.Viewer viewer, CancellationToken ct = default)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
private static async Task<(SVSimDbContext db, IArenaTwoPickService svc, long viewerId)> SetupAsync(
|
||||
int ticketCount, bool freeplay = false, ulong crystals = 0, ulong rupees = 0)
|
||||
{
|
||||
var factory = new SVSimTestFactory();
|
||||
var factory = new SVSimTestFactory(freeplayEnabled: freeplay);
|
||||
var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
await db.Database.EnsureCreatedAsync();
|
||||
@@ -56,8 +43,8 @@ public class ArenaTwoPickServiceEntryTests
|
||||
db.Viewers.Add(viewer);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var grants = scope.ServiceProvider.GetRequiredService<RewardGrantService>();
|
||||
var config = scope.ServiceProvider.GetRequiredService<IGameConfigService>();
|
||||
var inv = scope.ServiceProvider.GetRequiredService<IInventoryService>();
|
||||
|
||||
// Seed reward catalog so GetMaxWinCountAsync returns 7.
|
||||
await new ArenaTwoPickRewardImporter()
|
||||
@@ -69,11 +56,9 @@ public class ArenaTwoPickServiceEntryTests
|
||||
new NullCardPoolService(),
|
||||
config,
|
||||
scope.ServiceProvider.GetRequiredService<IViewerRepository>(),
|
||||
grants,
|
||||
new FakeEntitlements { IsFreeplay = freeplay },
|
||||
inv,
|
||||
new SystemRandom(seed: 1234),
|
||||
db,
|
||||
scope.ServiceProvider.GetRequiredService<ICurrencySpendService>());
|
||||
db);
|
||||
|
||||
return (db, svc, viewer.Id);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using SVSim.Database.Models;
|
||||
using SVSim.Database.Repositories.Globals;
|
||||
using SVSim.Database.Repositories.Viewer;
|
||||
using SVSim.Database.Services;
|
||||
using SVSim.Database.Services.Inventory;
|
||||
using SVSim.EmulatedEntrypoint.Services;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
@@ -17,19 +18,6 @@ public class ArenaTwoPickServiceFinishTests
|
||||
{
|
||||
private const long TicketItemId = 80001;
|
||||
|
||||
private sealed class FakeEntitlements : IViewerEntitlements
|
||||
{
|
||||
public bool IsFreeplay { get; init; }
|
||||
|
||||
public long EffectiveBalance(SVSim.Database.Models.Viewer viewer, SpendCurrency currency) => 0;
|
||||
public bool OwnsCard(SVSim.Database.Models.Viewer viewer, long cardId) => IsFreeplay;
|
||||
public bool OwnsCosmetic(SVSim.Database.Models.Viewer viewer, CosmeticType type, int id) => IsFreeplay;
|
||||
public Task<IReadOnlyList<OwnedCardEntry>> EffectiveOwnedCardsAsync(SVSim.Database.Models.Viewer viewer, CancellationToken ct = default)
|
||||
=> Task.FromResult<IReadOnlyList<OwnedCardEntry>>(new List<OwnedCardEntry>());
|
||||
public Task<EffectiveCosmetics> EffectiveCosmeticsAsync(SVSim.Database.Models.Viewer viewer, CancellationToken ct = default)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
private sealed class FakePool : IArenaTwoPickCardPoolService
|
||||
{
|
||||
public List<CandidatePair> GeneratePickSetsForTurn(int classId, int turn, long startingPairId, IRandom rng) => new();
|
||||
@@ -90,11 +78,9 @@ public class ArenaTwoPickServiceFinishTests
|
||||
new FakePool(),
|
||||
scope.ServiceProvider.GetRequiredService<IGameConfigService>(),
|
||||
scope.ServiceProvider.GetRequiredService<IViewerRepository>(),
|
||||
scope.ServiceProvider.GetRequiredService<RewardGrantService>(),
|
||||
new FakeEntitlements(),
|
||||
scope.ServiceProvider.GetRequiredService<IInventoryService>(),
|
||||
new SystemRandom(seed: 1),
|
||||
db,
|
||||
scope.ServiceProvider.GetRequiredService<ICurrencySpendService>());
|
||||
db);
|
||||
|
||||
return (db, svc, 7L);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ArenaTwoPickServiceTopTests
|
||||
private static IArenaTwoPickService BuildService(SVSimDbContext db, IArenaTwoPickRunRepository runRepo)
|
||||
{
|
||||
// GetTopAsync only uses _runs — every other dep can be null! because the test path
|
||||
// never touches them. The 9th positional arg (db) is required from Task 13 onward.
|
||||
return new ArenaTwoPickService(runRepo, null!, null!, null!, null!, null!, null!, null!, db, null!);
|
||||
// never touches them.
|
||||
return new ArenaTwoPickService(runRepo, null!, null!, null!, null!, null!, null!, db);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using SVSim.Database.Models;
|
||||
using SVSim.Database.Repositories.Globals;
|
||||
using SVSim.Database.Repositories.Viewer;
|
||||
using SVSim.Database.Services;
|
||||
using SVSim.Database.Services.Inventory;
|
||||
using SVSim.EmulatedEntrypoint.Services;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
@@ -17,19 +18,6 @@ public class ArenaTwoPickServiceWeightedRewardsTests
|
||||
{
|
||||
private const long TicketItemId = 80001;
|
||||
|
||||
private sealed class FakeEntitlements : IViewerEntitlements
|
||||
{
|
||||
public bool IsFreeplay { get; init; }
|
||||
|
||||
public long EffectiveBalance(SVSim.Database.Models.Viewer viewer, SpendCurrency currency) => 0;
|
||||
public bool OwnsCard(SVSim.Database.Models.Viewer viewer, long cardId) => IsFreeplay;
|
||||
public bool OwnsCosmetic(SVSim.Database.Models.Viewer viewer, CosmeticType type, int id) => IsFreeplay;
|
||||
public Task<IReadOnlyList<OwnedCardEntry>> EffectiveOwnedCardsAsync(SVSim.Database.Models.Viewer viewer, CancellationToken ct = default)
|
||||
=> Task.FromResult<IReadOnlyList<OwnedCardEntry>>(new List<OwnedCardEntry>());
|
||||
public Task<EffectiveCosmetics> EffectiveCosmeticsAsync(SVSim.Database.Models.Viewer viewer, CancellationToken ct = default)
|
||||
=> throw new NotSupportedException();
|
||||
}
|
||||
|
||||
private sealed class FakePool : IArenaTwoPickCardPoolService
|
||||
{
|
||||
public List<CandidatePair> GeneratePickSetsForTurn(int classId, int turn, long startingPairId, IRandom rng) => new();
|
||||
@@ -100,11 +88,9 @@ public class ArenaTwoPickServiceWeightedRewardsTests
|
||||
new FakePool(),
|
||||
scope.ServiceProvider.GetRequiredService<IGameConfigService>(),
|
||||
scope.ServiceProvider.GetRequiredService<IViewerRepository>(),
|
||||
scope.ServiceProvider.GetRequiredService<RewardGrantService>(),
|
||||
new FakeEntitlements(),
|
||||
scope.ServiceProvider.GetRequiredService<IInventoryService>(),
|
||||
rng,
|
||||
db,
|
||||
scope.ServiceProvider.GetRequiredService<ICurrencySpendService>());
|
||||
db);
|
||||
|
||||
return (db, svc, 7L);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user