Implement phase 5 critical branch extraction
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using RolemasterDb.App.Data;
|
||||
using RolemasterDb.ImportTool.Parsing;
|
||||
|
||||
namespace RolemasterDb.ImportTool.Tests;
|
||||
@@ -249,6 +252,83 @@ public sealed class StandardCriticalTableParserIntegrationTests
|
||||
Assert.Contains("Blast goes in through foe's eye", superSlaying.DescriptionText, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Slash_branch_cells_split_base_text_from_conditional_affix_branches()
|
||||
{
|
||||
var entry = LoadManifest().Tables.Single(item => string.Equals(item.Slug, "slash", StringComparison.Ordinal));
|
||||
var parseResult = await LoadParseResultAsync(entry);
|
||||
var result = parseResult.Table.Results.Single(item =>
|
||||
item.GroupKey is null &&
|
||||
string.Equals(item.RollBandLabel, "36-45", StringComparison.Ordinal) &&
|
||||
string.Equals(item.ColumnKey, "B", StringComparison.Ordinal));
|
||||
|
||||
Assert.Equal("Strike foe in shin. If he doesn't have greaves, you slash open foe's shin.", result.DescriptionText);
|
||||
Assert.Null(result.RawAffixText);
|
||||
Assert.DoesNotContain("with leg greaves:", result.RawCellText, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Equal(2, result.Branches.Count);
|
||||
|
||||
var withGreaves = result.Branches.Single(item => string.Equals(item.ConditionText, "with leg greaves", StringComparison.OrdinalIgnoreCase));
|
||||
var withoutGreaves = result.Branches.Single(item => string.Equals(item.ConditionText, "w/o leg greaves", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
Assert.Equal("with_leg_greaves", withGreaves.ConditionKey);
|
||||
Assert.Equal("+2H – π", withGreaves.RawAffixText);
|
||||
Assert.Equal(string.Empty, withGreaves.DescriptionText);
|
||||
Assert.Equal("without_leg_greaves", withoutGreaves.ConditionKey);
|
||||
Assert.Equal("+2H – ∫", withoutGreaves.RawAffixText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Impact_branch_cells_keep_prose_branch_text_separate_from_affix_branch_text()
|
||||
{
|
||||
var entry = LoadManifest().Tables.Single(item => string.Equals(item.Slug, "impact", StringComparison.Ordinal));
|
||||
var parseResult = await LoadParseResultAsync(entry);
|
||||
var result = parseResult.Table.Results.Single(item =>
|
||||
item.GroupKey is null &&
|
||||
string.Equals(item.RollBandLabel, "86-90", StringComparison.Ordinal) &&
|
||||
string.Equals(item.ColumnKey, "D", StringComparison.Ordinal));
|
||||
|
||||
Assert.Equal(
|
||||
"Onslaught to foe's midsection. Organs are damaged and foe throws up blood. Foe's abdomen is seriously damaged. He falls and should not be moved.",
|
||||
result.DescriptionText);
|
||||
Assert.Null(result.RawAffixText);
|
||||
Assert.Equal(2, result.Branches.Count);
|
||||
|
||||
var withArmor = result.Branches.Single(item => string.Equals(item.ConditionText, "with abdominal armor", StringComparison.OrdinalIgnoreCase));
|
||||
var withoutArmor = result.Branches.Single(item => string.Equals(item.ConditionText, "w/o abdominal armor", StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
Assert.Equal("12∑", withArmor.RawAffixText);
|
||||
Assert.Equal(string.Empty, withArmor.DescriptionText);
|
||||
Assert.Null(withoutArmor.RawAffixText);
|
||||
Assert.Equal("dies in 6 rounds", withoutArmor.DescriptionText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Loader_upgrades_existing_sqlite_and_persists_branch_rows()
|
||||
{
|
||||
var entry = LoadManifest().Tables.Single(item => string.Equals(item.Slug, "slash", StringComparison.Ordinal));
|
||||
var parseResult = await LoadParseResultAsync(entry);
|
||||
var databasePath = CreateTemporaryDatabaseCopy();
|
||||
var loader = new CriticalImportLoader(databasePath);
|
||||
|
||||
await loader.LoadAsync(parseResult.Table);
|
||||
|
||||
await using var dbContext = CreateDbContext(databasePath);
|
||||
var result = await dbContext.CriticalResults
|
||||
.Include(item => item.CriticalTable)
|
||||
.Include(item => item.CriticalColumn)
|
||||
.Include(item => item.CriticalRollBand)
|
||||
.Include(item => item.Branches)
|
||||
.SingleAsync(item =>
|
||||
item.CriticalTable.Slug == "slash" &&
|
||||
item.CriticalColumn.ColumnKey == "B" &&
|
||||
item.CriticalRollBand.Label == "36-45");
|
||||
|
||||
Assert.DoesNotContain("with leg greaves:", result.RawCellText, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Equal(2, result.Branches.Count);
|
||||
Assert.Contains(result.Branches, item => item.ConditionKey == "with_leg_greaves" && item.RawAffixText == "+2H – π");
|
||||
Assert.Contains(result.Branches, item => item.ConditionKey == "without_leg_greaves" && item.RawAffixText == "+2H – ∫");
|
||||
}
|
||||
|
||||
private static async Task<CriticalTableParseResult> LoadParseResultAsync(CriticalImportManifestEntry entry)
|
||||
{
|
||||
var xmlPath = Path.Combine(GetArtifactCacheRoot(), $"{entry.Slug}.xml");
|
||||
@@ -278,6 +358,22 @@ public sealed class StandardCriticalTableParserIntegrationTests
|
||||
return cacheRoot;
|
||||
}
|
||||
|
||||
private static RolemasterDbContext CreateDbContext(string databasePath)
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<RolemasterDbContext>()
|
||||
.UseSqlite($"Data Source={databasePath}")
|
||||
.Options;
|
||||
|
||||
return new RolemasterDbContext(options);
|
||||
}
|
||||
|
||||
private static string CreateTemporaryDatabaseCopy()
|
||||
{
|
||||
var databasePath = Path.Combine(GetArtifactCacheRoot(), $"rolemaster-{Guid.NewGuid():N}.db");
|
||||
File.Copy(Path.Combine(GetRepositoryRoot(), "src", "RolemasterDb.App", "rolemaster.db"), databasePath, true);
|
||||
return databasePath;
|
||||
}
|
||||
|
||||
private static string GetRepositoryRoot()
|
||||
{
|
||||
var probe = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
|
||||
Reference in New Issue
Block a user