Migrate ExcelIO from ClosedXML to NPOI

This commit is contained in:
Joseph Doherty
2026-02-06 17:27:09 -05:00
parent 070d915b12
commit dd18a05408
26 changed files with 3034 additions and 2805 deletions
@@ -1,130 +1,131 @@
using ClosedXML.Excel;
using JdeScoping.ExcelIO.Tests.Fixtures;
using Shouldly;
using Xunit;
namespace JdeScoping.ExcelIO.Tests.Integration;
public class MisInfoSheetTests : IClassFixture<WithMisDataFixture>
{
private readonly XLWorkbook _workbook;
private readonly IXLWorksheet _sheet;
private readonly List<string> _headers;
public MisInfoSheetTests(WithMisDataFixture fixture)
{
_workbook = fixture.Workbook;
_sheet = _workbook.Worksheet("MIS Info");
_headers = ExcelTestHelpers.GetHeadersFromSheet(_sheet);
}
[Fact]
public void SheetCount_IsFour()
{
_workbook.Worksheets.Count.ShouldBe(4);
}
[Fact]
public void MisInfoSheet_Exists()
{
_workbook.Worksheets.TryGetWorksheet("MIS Info", out _).ShouldBeTrue();
}
[Fact]
public void ColumnCount_Is19()
{
_headers.Count.ShouldBe(19);
}
[Fact]
public void ColumnHeaders_MatchExpected()
{
_headers.ShouldContain("Item Number");
_headers.ShouldContain("MIS Job Step Sequence Number");
_headers.ShouldContain("MIS Number");
_headers.ShouldContain("MIS Revision");
_headers.ShouldContain("Item Description");
_headers.ShouldContain("MIS Release Status");
_headers.ShouldContain("MIS Release Date");
_headers.ShouldContain("Branch Code");
_headers.ShouldContain("Job Step Sequence Number");
_headers.ShouldContain("Matched Sequence Number");
_headers.ShouldContain("Matched to F3112Z1?");
_headers.ShouldContain("Matched to F3003?");
_headers.ShouldContain("Function Operation Description");
_headers.ShouldContain("Char Number");
_headers.ShouldContain("Test Description");
_headers.ShouldContain("Sampling Type");
_headers.ShouldContain("Sampling Value");
_headers.ShouldContain("Tools & Gauges");
_headers.ShouldContain("Work Instructions");
}
[Fact]
public void ColumnOrder_MatchesSpec()
{
_headers[0].ShouldBe("Item Number");
_headers[1].ShouldBe("MIS Job Step Sequence Number");
_headers[2].ShouldBe("MIS Number");
_headers[3].ShouldBe("MIS Revision");
_headers[4].ShouldBe("Item Description");
_headers[5].ShouldBe("MIS Release Status");
_headers[6].ShouldBe("MIS Release Date");
_headers[7].ShouldBe("Branch Code");
_headers[8].ShouldBe("Job Step Sequence Number");
_headers[9].ShouldBe("Matched Sequence Number");
_headers[10].ShouldBe("Matched to F3112Z1?");
_headers[11].ShouldBe("Matched to F3003?");
_headers[12].ShouldBe("Function Operation Description");
_headers[13].ShouldBe("Char Number");
_headers[14].ShouldBe("Test Description");
_headers[15].ShouldBe("Sampling Type");
_headers[16].ShouldBe("Sampling Value");
_headers[17].ShouldBe("Tools & Gauges");
_headers[18].ShouldBe("Work Instructions");
}
[Fact]
public void TableStyle_IsLight18()
{
var table = _sheet.Tables.First();
table.Theme.ShouldBe(XLTableTheme.TableStyleLight18);
}
[Fact]
public void Protection_IsEnabled()
{
_sheet.Protection.IsProtected.ShouldBeTrue();
}
[Fact]
public void DataRow_ContainsExpectedValues()
{
_sheet.Cell(2, 1).Value.GetText().ShouldBe("ITEM-001");
_sheet.Cell(2, 3).Value.GetText().ShouldBe("MIS-001");
}
[Fact]
public void TestDescriptionColumn_IsWrapped()
{
var colIndex = _headers.IndexOf("Test Description") + 1;
_sheet.Column(colIndex).Width.ShouldBe(65);
_sheet.Column(colIndex).Style.Alignment.WrapText.ShouldBeTrue();
}
[Fact]
public void ToolsGaugesColumn_IsWrapped()
{
var colIndex = _headers.IndexOf("Tools & Gauges") + 1;
_sheet.Column(colIndex).Width.ShouldBe(65);
_sheet.Column(colIndex).Style.Alignment.WrapText.ShouldBeTrue();
}
[Fact]
public void WorkInstructionsColumn_IsWrapped()
{
var colIndex = _headers.IndexOf("Work Instructions") + 1;
_sheet.Column(colIndex).Width.ShouldBe(65);
_sheet.Column(colIndex).Style.Alignment.WrapText.ShouldBeTrue();
}
}
using JdeScoping.ExcelIO.Tests.Fixtures;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using Shouldly;
using Xunit;
namespace JdeScoping.ExcelIO.Tests.Integration;
public class MisInfoSheetTests : IClassFixture<WithMisDataFixture>
{
private readonly XSSFWorkbook _workbook;
private readonly ISheet _sheet;
private readonly List<string> _headers;
public MisInfoSheetTests(WithMisDataFixture fixture)
{
_workbook = fixture.Workbook;
_sheet = _workbook.GetSheet("MIS Info")!;
_headers = ExcelTestHelpers.GetHeadersFromSheet(_sheet);
}
[Fact]
public void SheetCount_IsFour()
{
_workbook.NumberOfSheets.ShouldBe(4);
}
[Fact]
public void MisInfoSheet_Exists()
{
_workbook.GetSheet("MIS Info").ShouldNotBeNull();
}
[Fact]
public void ColumnCount_Is19()
{
_headers.Count.ShouldBe(19);
}
[Fact]
public void ColumnHeaders_MatchExpected()
{
_headers.ShouldContain("Item Number");
_headers.ShouldContain("MIS Job Step Sequence Number");
_headers.ShouldContain("MIS Number");
_headers.ShouldContain("MIS Revision");
_headers.ShouldContain("Item Description");
_headers.ShouldContain("MIS Release Status");
_headers.ShouldContain("MIS Release Date");
_headers.ShouldContain("Branch Code");
_headers.ShouldContain("Job Step Sequence Number");
_headers.ShouldContain("Matched Sequence Number");
_headers.ShouldContain("Matched to F3112Z1?");
_headers.ShouldContain("Matched to F3003?");
_headers.ShouldContain("Function Operation Description");
_headers.ShouldContain("Char Number");
_headers.ShouldContain("Test Description");
_headers.ShouldContain("Sampling Type");
_headers.ShouldContain("Sampling Value");
_headers.ShouldContain("Tools & Gauges");
_headers.ShouldContain("Work Instructions");
}
[Fact]
public void ColumnOrder_MatchesSpec()
{
_headers[0].ShouldBe("Item Number");
_headers[1].ShouldBe("MIS Job Step Sequence Number");
_headers[2].ShouldBe("MIS Number");
_headers[3].ShouldBe("MIS Revision");
_headers[4].ShouldBe("Item Description");
_headers[5].ShouldBe("MIS Release Status");
_headers[6].ShouldBe("MIS Release Date");
_headers[7].ShouldBe("Branch Code");
_headers[8].ShouldBe("Job Step Sequence Number");
_headers[9].ShouldBe("Matched Sequence Number");
_headers[10].ShouldBe("Matched to F3112Z1?");
_headers[11].ShouldBe("Matched to F3003?");
_headers[12].ShouldBe("Function Operation Description");
_headers[13].ShouldBe("Char Number");
_headers[14].ShouldBe("Test Description");
_headers[15].ShouldBe("Sampling Type");
_headers[16].ShouldBe("Sampling Value");
_headers[17].ShouldBe("Tools & Gauges");
_headers[18].ShouldBe("Work Instructions");
}
[Fact]
public void TableStyle_IsLight18()
{
var table = ExcelTestHelpers.GetFirstTable(_sheet);
table.StyleName.ShouldBe("TableStyleLight18");
}
[Fact]
public void Protection_IsEnabled()
{
((XSSFSheet)_sheet).IsSheetLocked.ShouldBeTrue();
}
[Fact]
public void DataRow_ContainsExpectedValues()
{
ExcelTestHelpers.GetCellText(_sheet, 2, 1).ShouldBe("ITEM-001");
ExcelTestHelpers.GetCellText(_sheet, 2, 3).ShouldBe("MIS-001");
}
[Fact]
public void TestDescriptionColumn_IsWrapped()
{
var colIndex = _headers.IndexOf("Test Description") + 1;
ExcelTestHelpers.GetColumnWidthChars(_sheet, colIndex).ShouldBe(65);
ExcelTestHelpers.GetCell(_sheet, 2, colIndex)!.CellStyle.WrapText.ShouldBeTrue();
}
[Fact]
public void ToolsGaugesColumn_IsWrapped()
{
var colIndex = _headers.IndexOf("Tools & Gauges") + 1;
ExcelTestHelpers.GetColumnWidthChars(_sheet, colIndex).ShouldBe(65);
ExcelTestHelpers.GetCell(_sheet, 2, colIndex)!.CellStyle.WrapText.ShouldBeTrue();
}
[Fact]
public void WorkInstructionsColumn_IsWrapped()
{
var colIndex = _headers.IndexOf("Work Instructions") + 1;
ExcelTestHelpers.GetColumnWidthChars(_sheet, colIndex).ShouldBe(65);
ExcelTestHelpers.GetCell(_sheet, 2, colIndex)!.CellStyle.WrapText.ShouldBeTrue();
}
}