Card liquefication
This commit is contained in:
@@ -216,6 +216,89 @@ internal sealed class SVSimTestFactory : WebApplicationFactory<Program>
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeds an OwnedCardEntry for the viewer. Uses an existing card from the minimal test set
|
||||
/// when <paramref name="cardId"/> matches one (10001001/10001002/10001003); otherwise the
|
||||
/// caller must have inserted the card row themselves. <paramref name="dustReward"/> is written
|
||||
/// onto the card's CollectionInfo so destruct tests can compute expected vials.
|
||||
///
|
||||
/// NOTE: This helper ALWAYS resets the viewer's RedEther to 0 (so destruct tests can assert
|
||||
/// literal post-state totals). Callers that need a non-zero balance should re-assign after seeding.
|
||||
/// </summary>
|
||||
public async Task SeedOwnedCardAsync(
|
||||
long viewerId,
|
||||
long cardId,
|
||||
int count,
|
||||
int dustReward = 50,
|
||||
int craftCost = 200,
|
||||
bool isProtected = false)
|
||||
{
|
||||
using var scope = Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
var card = await db.Cards.FirstOrDefaultAsync(c => c.Id == cardId);
|
||||
if (card is null)
|
||||
{
|
||||
card = new ShadowverseCardEntry
|
||||
{
|
||||
Id = cardId,
|
||||
Name = $"SeededCard{cardId}",
|
||||
Rarity = Rarity.Bronze,
|
||||
CollectionInfo = new CardCollectionInfo { CraftCost = craftCost, DustReward = dustReward },
|
||||
};
|
||||
db.Cards.Add(card);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
else if (card.CollectionInfo is null || card.CollectionInfo.DustReward != dustReward || card.CollectionInfo.CraftCost != craftCost)
|
||||
{
|
||||
card.CollectionInfo = new CardCollectionInfo { CraftCost = craftCost, DustReward = dustReward };
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
var viewer = await db.Viewers.Include(v => v.Cards).ThenInclude(c => c.Card).FirstAsync(v => v.Id == viewerId);
|
||||
var owned = viewer.Cards.FirstOrDefault(c => c.Card.Id == cardId);
|
||||
if (owned is null)
|
||||
{
|
||||
viewer.Cards.Add(new OwnedCardEntry { Card = card, Count = count, IsProtected = isProtected });
|
||||
}
|
||||
else
|
||||
{
|
||||
owned.Count = count;
|
||||
owned.IsProtected = isProtected;
|
||||
}
|
||||
viewer.Currency.RedEther = 0; // Reset RedEther so destruct tests can assert literal post-state totals
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Puts <paramref name="count"/> copies of <paramref name="cardId"/> into the viewer's deck
|
||||
/// in the given format + slot. Tests use this to set up deck-strip scenarios for /card/destruct.
|
||||
/// The card must already exist (typically via SeedOwnedCardAsync, which inserts the card row).
|
||||
/// </summary>
|
||||
public async Task AddCardToDeckAsync(long viewerId, Format format, int deckNumber, long cardId, int count)
|
||||
{
|
||||
using var scope = Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
var viewer = await db.Viewers
|
||||
.Include(v => v.Decks).ThenInclude(d => d.Cards).ThenInclude(c => c.Card)
|
||||
.FirstAsync(v => v.Id == viewerId);
|
||||
|
||||
var deck = viewer.Decks.First(d => d.Format == format && d.Number == deckNumber);
|
||||
var card = await db.Cards.FirstAsync(c => c.Id == cardId);
|
||||
|
||||
var existing = deck.Cards.FirstOrDefault(c => c.Card.Id == cardId);
|
||||
if (existing is null)
|
||||
{
|
||||
deck.Cards.Add(new DeckCard { Card = card, Count = count });
|
||||
}
|
||||
else
|
||||
{
|
||||
existing.Count = count;
|
||||
}
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
Reference in New Issue
Block a user