This commit introduces the `Strata.Excel.Core` project, a .NET library built on ClosedXML for robust Excel document generation and data import. Key features include: - **Export:** Flexible data export to Excel, supporting custom formatting, titles, subtitles, humanized headings, and batched processing for large datasets. Includes `ExcelContentResult` and `ZipFileContentResult` for ASP.NET Core integration. - **Import:** Utilities to easily import data from Excel worksheets into C# objects. - **Test Utilities:** Comprehensive helpers for comparing Excel workbooks in tests, handling resource extraction, and performing load tests. - **Build Infrastructure:** Sets up a Dockerfile for building the library, including SonarQube and Dependency-Check scanning. - **Project Structure:** Establishes `.gitignore`, `.dockerignore`, `nuget.config`, and a `README.md` with usage instructions and versioning guidelines. This foundational commit provides a reusable and well-tested framework for Excel operations within Strata applications.
77 lines
3.1 KiB
C#
77 lines
3.1 KiB
C#
using ClosedXML.Excel;
|
|
using FluentAssertions;
|
|
using Newtonsoft.Json;
|
|
using NUnit.Framework;
|
|
using Strata.Excel.TestUtilities;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using static Strata.Excel.Core.ExportUtils;
|
|
using static Strata.Excel.Core.Test.Unit.ExcelExportTests.TestExcelExport;
|
|
|
|
namespace Strata.Excel.Core.Test.Unit.ExcelLoadTests
|
|
{
|
|
[TestFixture]
|
|
public class TestExcelLoad
|
|
{
|
|
[OneTimeSetUp]
|
|
public void RunBeforeAnyTests()
|
|
{
|
|
Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
|
|
// or identically under the hoods
|
|
Directory.SetCurrentDirectory(TestContext.CurrentContext.TestDirectory);
|
|
}
|
|
|
|
private static readonly ResourceFileExtractor _dataExtractor = new ResourceFileExtractor(".ExcelExportTests.");
|
|
|
|
[TestCaseSource(nameof(LoadTestCases))]
|
|
[Ignore("need to look for alternative that can handle large data")]
|
|
public void ExcelLoadTest(int load, int batchSize)
|
|
{
|
|
var jsonData = _dataExtractor.ReadFileFromResource("data.json");
|
|
var loadData = JsonConvert.DeserializeObject<List<TestData>>(jsonData);
|
|
var data = new List<TestData>();
|
|
while (data.Count < load)
|
|
{
|
|
data.AddRange(loadData);
|
|
}
|
|
Action action = () =>
|
|
{
|
|
var expectedLoad = data.Count + 1; // Add 1 to include the header row
|
|
var options = new ExportOptions
|
|
{
|
|
EmptyMessage = "No Mappings",
|
|
BatchSize = batchSize
|
|
};
|
|
options.AddColumnOptions("Confidence Score", NumberFormatId.ZeroPercent, XLAlignmentHorizontalValues.Right);
|
|
options.AddColumnOptions("Date Mapped", NumberFormatId.ShortDateSlash, XLAlignmentHorizontalValues.Right);
|
|
|
|
var wb = CreateExcelWorkbook(data, options);
|
|
#pragma warning disable S125 // Sections of code should not be commented out
|
|
//var expected = $@"Excel Load Test {TestContext.CurrentContext.Test.Name}.xlsx";
|
|
//wb.SaveAs(Path.Combine(@"C:\Git\excel.core\tests\Strata.Excel.Core.Test.Unit\ExcelLoadTests\", expected));
|
|
#pragma warning restore S125 // Sections of code should not be commented
|
|
|
|
// assert
|
|
wb.Worksheets.Should().HaveCount(1);
|
|
var ws = wb.Worksheet(1);
|
|
ws.Should().NotBeNull();
|
|
var table = ws.Tables.First();
|
|
table.RowCount().Should().Be(expectedLoad);
|
|
};
|
|
action.Should().NotThrow()
|
|
.And.Subject.ExecutionTime().Should().BeLessThan(TimeSpan.FromMinutes(load / 3000));
|
|
}
|
|
|
|
public static IEnumerable<TestCaseData> LoadTestCases()
|
|
{
|
|
var batchSize = 100000;
|
|
for (var i = 48; i < 50; i += 2)
|
|
{
|
|
yield return new TestCaseData(i * 10000, batchSize).SetName($"{i}0000 rows with batches of {batchSize}");
|
|
}
|
|
}
|
|
}
|
|
}
|