6952f686fa
- Add WorkbookFixtureBase and 4 concrete fixtures for shared workbooks - Add ExcelTestHelpers with shared utility methods - Create Integration/ folder with 7 fixture-based test classes: - MinimalSearchTests (5 tests) - SearchResultsSheetTests (5 tests) - MisInfoSheetTests (11 tests) - InvestigationSheetTests (7 tests) - ProtectionAndStyleTests (7 tests) - LegacyFormatTests (5 tests) - LargeDataSetTests (1 test) - Delete redundant ExcelExportIntegrationTests.cs (26 tests) - Delete redundant LegacyComparisonTests.cs (16 tests) - Reduce workbook generations from ~42 to 4 fixtures - Test runtime reduced from ~18 min to ~4 min (76% improvement) - All 122 ExcelIO tests pass
69 lines
2.4 KiB
C#
69 lines
2.4 KiB
C#
using ClosedXML.Excel;
|
|
using JdeScoping.ExcelIO.Generators;
|
|
using JdeScoping.ExcelIO.Mapping;
|
|
using JdeScoping.ExcelIO.Mapping.Maps;
|
|
using JdeScoping.ExcelIO.Models.Reporting;
|
|
using JdeScoping.ExcelIO.Options;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
using NSubstitute;
|
|
|
|
namespace JdeScoping.ExcelIO.Tests.Fixtures;
|
|
|
|
public abstract class WorkbookFixtureBase : IDisposable
|
|
{
|
|
public XLWorkbook Workbook { get; }
|
|
public SearchModel SearchModel { get; }
|
|
|
|
protected abstract SearchModel CreateSearchModel();
|
|
|
|
protected WorkbookFixtureBase()
|
|
{
|
|
SearchModel = CreateSearchModel();
|
|
var service = CreateExportService();
|
|
var bytes = service.GenerateAsync(SearchModel).GetAwaiter().GetResult();
|
|
Workbook = new XLWorkbook(new MemoryStream(bytes));
|
|
}
|
|
|
|
private static ExcelExportService CreateExportService()
|
|
{
|
|
var logger = Substitute.For<ILogger<ExcelExportService>>();
|
|
var options = Microsoft.Extensions.Options.Options.Create(new ExcelExportOptions
|
|
{
|
|
CriteriaSheetPassword = "TestCriteriaPass",
|
|
DataSheetPassword = "TestDataPass"
|
|
});
|
|
|
|
var registry = CreateTestRegistry();
|
|
var tableWriter = new FluentTableWriter(registry);
|
|
var criteriaGenerator = new CriteriaSheetGenerator(options, tableWriter);
|
|
|
|
return new ExcelExportService(logger, options, criteriaGenerator, tableWriter, registry);
|
|
}
|
|
|
|
private static ExcelMapRegistry CreateTestRegistry()
|
|
{
|
|
var registry = new ExcelMapRegistry();
|
|
|
|
registry.Register(new SearchResultMap());
|
|
registry.Register(new MisSearchResultMap());
|
|
registry.Register(new MisNonMatchSearchResultMap());
|
|
registry.Register(new TimespanFilterMap());
|
|
registry.Register(new WorkOrderFilterEntryMap());
|
|
registry.Register(new ItemNumberFilterEntryMap());
|
|
registry.Register(new ProfitCenterFilterEntryMap());
|
|
registry.Register(new WorkCenterFilterEntryMap());
|
|
registry.Register(new OperatorFilterEntryMap());
|
|
registry.Register(new ComponentLotFilterEntryMap());
|
|
registry.Register(new ItemOperationMisFilterEntryMap());
|
|
|
|
return registry;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Workbook.Dispose();
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|