diff --git a/OpenNest.IO/Bom/BomImportRows.cs b/OpenNest.IO/Bom/BomImportRows.cs index 7c409d1..d96c24a 100644 --- a/OpenNest.IO/Bom/BomImportRows.cs +++ b/OpenNest.IO/Bom/BomImportRows.cs @@ -22,7 +22,7 @@ public static class BomImportRows foreach (var group in analysis.Groups) foreach (var part in group.Parts) if (part.DxfPath != null) - matchedPaths[part.Item.FileName ?? ""] = part.DxfPath; + matchedPaths[LookupName(part.Item.FileName)] = part.DxfPath; var rows = new List(); @@ -45,14 +45,7 @@ public static class BomImportRows } else { - var lookupName = item.FileName; - if ( - lookupName.EndsWith(".dxf", StringComparison.OrdinalIgnoreCase) - || lookupName.EndsWith(".dwg", StringComparison.OrdinalIgnoreCase) - ) - lookupName = Path.GetFileNameWithoutExtension(lookupName); - - if (matchedPaths.TryGetValue(lookupName, out var dxfPath)) + if (matchedPaths.TryGetValue(LookupName(item.FileName), out var dxfPath)) { row.DxfPath = dxfPath; row.Status = "Matched"; @@ -70,4 +63,19 @@ public static class BomImportRows return rows; } + + /// + /// The drawing name a BOM file name refers to: the name without a + /// .dxf or .dwg extension, as matches it. + /// + private static string LookupName(string fileName) + { + fileName ??= ""; + if ( + fileName.EndsWith(".dxf", StringComparison.OrdinalIgnoreCase) + || fileName.EndsWith(".dwg", StringComparison.OrdinalIgnoreCase) + ) + return Path.GetFileNameWithoutExtension(fileName); + return fileName; + } } diff --git a/OpenNest.Tests/Bom/BomImportRowsTests.cs b/OpenNest.Tests/Bom/BomImportRowsTests.cs index c4fbbdd..0e51efc 100644 --- a/OpenNest.Tests/Bom/BomImportRowsTests.cs +++ b/OpenNest.Tests/Bom/BomImportRowsTests.cs @@ -61,6 +61,22 @@ public sealed class BomImportRowsTests : IDisposable Assert.Equal(Path.Combine(folder, "PT01.dxf"), rows[0].DxfPath); } + [Fact] + public void Build_MatchesFileNamesThatIncludeTheExtension() + { + Touch("PT01.dxf"); + Touch("PT02.dwg"); + + var rows = BomImportRows.Build( + new List { Item("PT01.dxf"), Item("PT02.DWG") }, + folder + ); + + Assert.All(rows, r => Assert.True(r.IsEditable, r.FileName)); + Assert.Equal(Path.Combine(folder, "PT01.dxf"), rows[0].DxfPath); + Assert.Equal(Path.Combine(folder, "PT02.dwg"), rows[1].DxfPath); + } + [Fact] public void Build_WithMissingFolder_FindsNoDrawings() {