Files
jdescopingtool/NEW/tests/JdeScoping.ExcelIO.Tests/Fixtures/WorkbookFixtureBase.cs
T
Joseph Doherty 604bfe919c refactor: address code review findings across all projects
Apply comprehensive fixes from code reviews including:
- Extract shared utilities (SqlFormatHelper, CellValueConverter, DbDestinationBase)
- Add interface abstractions (IAuthenticationService, IDatabaseMigrator, IMisQueryBuilder)
- Implement SecureStore for encrypted secrets storage
- Fix error handling with proper HTTP status codes and logging
- Optimize double enumeration in DevEtlRegistry
- Add DataSync.Dev README for developer onboarding
- Extract filter panel base classes to reduce duplication
- Update code review docs to mark all issues as fixed
2026-01-19 11:05:36 -05:00

69 lines
2.4 KiB
C#

using ClosedXML.Excel;
using JdeScoping.Core.Models.SearchResults;
using JdeScoping.ExcelIO.Generators;
using JdeScoping.ExcelIO.Mapping;
using JdeScoping.ExcelIO.Mapping.Maps;
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);
}
}