Consolidation

This commit is contained in:
gamer147
2026-05-25 16:34:24 -04:00
parent 9b051c444c
commit 8e913578ff
14 changed files with 566 additions and 280 deletions

View File

@@ -35,8 +35,8 @@ public class CardAcquisitionServiceTests
viewer.Cards.Add(new OwnedCardEntry { Card = card, Count = count, IsProtected = false });
}
// Pre-seed bare Cards rows (no ownership) for any cardIds the test plans to grant via
// the service. GrantCardsToViewer does a FirstAsync(c => c.Id == grpKey) lookup; without
// these the production code throws "Sequence contains no elements".
// the service. RewardGrantService.ApplyAsync does FirstOrDefaultAsync on _db.Cards;
// without the row the grant throws InvalidOperationException("Card {id} not in catalog").
if (grantableCardIds is not null)
{
foreach (var cardId in grantableCardIds)
@@ -71,7 +71,7 @@ public class CardAcquisitionServiceTests
}
[Test]
public async Task GrantAsync_NewBronzeCard_GrantsCardOnly()
public async Task GrantManyAsync_NewBronzeCard_GrantsCardOnly()
{
// 101111010 is a synthetic test card (inserted ad-hoc via grantableCardIds) with no
// CardCosmeticReward associations. Expectation: grant returns only the type=5 entry.
@@ -79,7 +79,7 @@ public class CardAcquisitionServiceTests
var viewerId = await SeedViewerWithCards(factory, new() { }, grantableCardIds: new[] { 101111010L });
var service = GetService(factory);
var result = await service.GrantAsync(viewerId, new[] { 101111010L });
var result = await service.GrantManyAsync(viewerId, new[] { 101111010L });
Assert.That(result.RewardList, Has.Count.EqualTo(1));
Assert.That(result.RewardList[0].RewardType, Is.EqualTo(5)); // Card
@@ -88,7 +88,7 @@ public class CardAcquisitionServiceTests
}
[Test]
public async Task GrantAsync_LeaderCard_GrantsCardAndSkin()
public async Task GrantManyAsync_LeaderCard_GrantsCardAndSkin()
{
// Card 704741010 (Aria leader-card variant) has 3 cosmetic associations in the seed:
// skin 407, sleeve 704741010, emblem 704741010.
@@ -116,7 +116,7 @@ public class CardAcquisitionServiceTests
}
var service = GetService(factory);
var result = await service.GrantAsync(viewerId, new[] { 704741010L });
var result = await service.GrantManyAsync(viewerId, new[] { 704741010L });
var skinEntry = result.RewardList.SingleOrDefault(r => r.RewardType == 10);
Assert.That(skinEntry, Is.Not.Null, "expected a Skin reward entry");
@@ -134,7 +134,7 @@ public class CardAcquisitionServiceTests
}
[Test]
public async Task GrantAsync_AlreadyOwnedSkin_OmitsFromRewardList()
public async Task GrantManyAsync_AlreadyOwnedSkin_OmitsFromRewardList()
{
using var factory = new SVSimTestFactory();
var viewerId = await SeedViewerWithCards(factory, new() { }, grantableCardIds: new[] { 704741010L });
@@ -153,7 +153,7 @@ public class CardAcquisitionServiceTests
}
var service = GetService(factory);
var result = await service.GrantAsync(viewerId, new[] { 704741010L });
var result = await service.GrantManyAsync(viewerId, new[] { 704741010L });
Assert.That(result.RewardList.Any(r => r.RewardType == 10), Is.False,
"skin entry should be omitted since viewer already owns it");
@@ -162,7 +162,7 @@ public class CardAcquisitionServiceTests
}
[Test]
public async Task GrantAsync_FoilLeaderCard_ResolvesToNonFoilCosmetics()
public async Task GrantManyAsync_FoilLeaderCard_ResolvesToNonFoilCosmetics()
{
using var factory = new SVSimTestFactory();
var viewerId = await SeedViewerWithCards(factory, new() { }, grantableCardIds: new[] { 704741011L });
@@ -181,7 +181,7 @@ public class CardAcquisitionServiceTests
}
var service = GetService(factory);
var result = await service.GrantAsync(viewerId, new[] { 704741011L });
var result = await service.GrantManyAsync(viewerId, new[] { 704741011L });
var skinEntry = result.RewardList.SingleOrDefault(r => r.RewardType == 10);
Assert.That(skinEntry, Is.Not.Null, "expected skin entry via foil resolution");
@@ -195,7 +195,7 @@ public class CardAcquisitionServiceTests
}
[Test]
public async Task GrantAsync_MultipleCopiesOfSameLeader_GrantsCosmeticOnce()
public async Task GrantManyAsync_MultipleCopiesOfSameLeader_GrantsCosmeticOnce()
{
using var factory = new SVSimTestFactory();
var viewerId = await SeedViewerWithCards(factory, new() { }, grantableCardIds: new[] { 704741010L });
@@ -210,7 +210,7 @@ public class CardAcquisitionServiceTests
}
var service = GetService(factory);
var result = await service.GrantAsync(viewerId, new[] { 704741010L, 704741010L, 704741010L });
var result = await service.GrantManyAsync(viewerId, new[] { 704741010L, 704741010L, 704741010L });
Assert.That(result.RewardList.Count(r => r.RewardType == 10), Is.EqualTo(1),
"skin should appear exactly once in reward_list");
@@ -219,7 +219,7 @@ public class CardAcquisitionServiceTests
}
[Test]
public async Task GrantAsync_RecentLeaderCard_GrantsAllFiveCosmeticTypes()
public async Task GrantManyAsync_RecentLeaderCard_GrantsAllFiveCosmeticTypes()
{
using var factory = new SVSimTestFactory();
var viewerId = await SeedViewerWithCards(factory, new() { }, grantableCardIds: new[] { 721141010L });
@@ -250,7 +250,7 @@ public class CardAcquisitionServiceTests
}
var service = GetService(factory);
var result = await service.GrantAsync(viewerId, new[] { 721141010L });
var result = await service.GrantManyAsync(viewerId, new[] { 721141010L });
Assert.Multiple(() =>
{
@@ -263,7 +263,7 @@ public class CardAcquisitionServiceTests
}
[Test]
public async Task GrantAsync_BackfillMode_DoesNotIncrementCardCount()
public async Task BackfillCosmeticsAsync_DoesNotIncrementCardCount()
{
using var factory = new SVSimTestFactory();
// Pre-seed viewer with card 704741010 count=5, no skin
@@ -279,7 +279,7 @@ public class CardAcquisitionServiceTests
}
var service = GetService(factory);
var result = await service.GrantAsync(viewerId, newCardIds: null);
var result = await service.BackfillCosmeticsAsync(viewerId);
using var scope2 = factory.Services.CreateScope();
var db2 = scope2.ServiceProvider.GetRequiredService<SVSimDbContext>();
@@ -295,7 +295,7 @@ public class CardAcquisitionServiceTests
}
[Test]
public async Task GrantAsync_BackfillCalledTwice_SecondCallIsNoOp()
public async Task BackfillCosmeticsAsync_CalledTwice_SecondCallIsNoOp()
{
using var factory = new SVSimTestFactory();
var viewerId = await SeedViewerWithCards(factory, new() { [704741010L] = 1 });
@@ -310,15 +310,15 @@ public class CardAcquisitionServiceTests
}
var service = GetService(factory);
var first = await service.GrantAsync(viewerId, newCardIds: null);
var second = await service.GrantAsync(viewerId, newCardIds: null);
var first = await service.BackfillCosmeticsAsync(viewerId);
var second = await service.BackfillCosmeticsAsync(viewerId);
Assert.That(first.RewardList, Is.Not.Empty, "first call should grant cosmetics");
Assert.That(second.RewardList, Is.Empty, "second call should be a no-op");
}
[Test]
public async Task GrantAsync_LeaderCardWithMissingMapping_GrantsCardSilently()
public async Task GrantManyAsync_LeaderCardWithMissingMapping_GrantsCardSilently()
{
using var factory = new SVSimTestFactory();
var viewerId = await SeedViewerWithCards(factory, new() { }, grantableCardIds: new[] { 701141010L });
@@ -326,7 +326,7 @@ public class CardAcquisitionServiceTests
// NO CardCosmeticReward rows inserted for this card — simulates the 83 missing-mapping cases.
var service = GetService(factory);
var result = await service.GrantAsync(viewerId, new[] { 701141010L });
var result = await service.GrantManyAsync(viewerId, new[] { 701141010L });
Assert.That(result.RewardList.Any(r => r.RewardType == 5 && r.RewardId == 701141010L), Is.True);
Assert.That(result.RewardList.Any(r => r.RewardType == 10), Is.False);
@@ -334,7 +334,7 @@ public class CardAcquisitionServiceTests
}
[Test]
public async Task GrantAsync_OrphanCosmeticReward_LogsWarningAndSkips()
public async Task GrantManyAsync_OrphanCosmeticReward_LogsWarningAndSkips()
{
using var factory = new SVSimTestFactory();
var viewerId = await SeedViewerWithCards(factory, new() { }, grantableCardIds: new[] { 704741010L });
@@ -354,7 +354,7 @@ public class CardAcquisitionServiceTests
}
var service = GetService(factory);
var result = await service.GrantAsync(viewerId, new[] { 704741010L });
var result = await service.GrantManyAsync(viewerId, new[] { 704741010L });
Assert.That(result.RewardList.Any(r => r.RewardType == 5 && r.RewardId == 704741010L), Is.True);
Assert.That(result.RewardList.Any(r => r.RewardType == 10 && r.RewardId == 407L), Is.True,