26ff8d9b4f
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
117 lines
3.4 KiB
C#
117 lines
3.4 KiB
C#
using ClosedXML.Excel;
|
|
using JdeScoping.ExcelIO.Attributes;
|
|
using JdeScoping.ExcelIO.Formatting;
|
|
using Shouldly;
|
|
using Xunit;
|
|
|
|
namespace JdeScoping.ExcelIO.Tests;
|
|
|
|
public class ColumnFormatterTests
|
|
{
|
|
[Fact]
|
|
public void ApplyColumnFormat_AutoWidth_AdjustsToContents()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
worksheet.Cell(1, 1).Value = "Some Text Value";
|
|
|
|
var attr = new OutputColumnAttribute
|
|
{
|
|
AutoWidth = true,
|
|
Format = OutputColumnAttribute.StdFormat
|
|
};
|
|
|
|
ColumnFormatter.ApplyColumnFormat(worksheet.Column(1), attr);
|
|
|
|
// Width should be greater than default after adjustment
|
|
worksheet.Column(1).Width.ShouldBeGreaterThan(0);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyColumnFormat_FixedWidth_SetsExactWidth()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
|
|
var attr = new OutputColumnAttribute
|
|
{
|
|
AutoWidth = false,
|
|
Width = 50.0,
|
|
Format = OutputColumnAttribute.StdFormat
|
|
};
|
|
|
|
ColumnFormatter.ApplyColumnFormat(worksheet.Column(1), attr);
|
|
|
|
worksheet.Column(1).Width.ShouldBe(50.0);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyColumnFormat_WrapText_EnablesWrapping()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
|
|
var attr = new OutputColumnAttribute
|
|
{
|
|
WrapText = true,
|
|
AutoWidth = false,
|
|
Width = 65.0,
|
|
Format = OutputColumnAttribute.StdFormat
|
|
};
|
|
|
|
ColumnFormatter.ApplyColumnFormat(worksheet.Column(1), attr);
|
|
|
|
worksheet.Column(1).Style.Alignment.WrapText.ShouldBeTrue();
|
|
worksheet.Column(1).Width.ShouldBe(65.0);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyColumnFormat_DateFormat_AppliesCorrectFormat()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
|
|
var attr = new OutputColumnAttribute
|
|
{
|
|
AutoWidth = false,
|
|
Width = 20.0,
|
|
Format = OutputColumnAttribute.DateFormat
|
|
};
|
|
|
|
ColumnFormatter.ApplyColumnFormat(worksheet.Column(1), attr);
|
|
|
|
worksheet.Column(1).Style.NumberFormat.Format.ShouldBe(OutputColumnAttribute.DateFormat);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyColumnFormat_TimestampFormat_AppliesCorrectFormat()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
|
|
var attr = new OutputColumnAttribute
|
|
{
|
|
AutoWidth = false,
|
|
Width = 25.0,
|
|
Format = OutputColumnAttribute.TimestampFormat
|
|
};
|
|
|
|
ColumnFormatter.ApplyColumnFormat(worksheet.Column(1), attr);
|
|
|
|
worksheet.Column(1).Style.NumberFormat.Format.ShouldBe(OutputColumnAttribute.TimestampFormat);
|
|
}
|
|
|
|
[Fact]
|
|
public void AutoFitWithPadding_AppliesPaddingFactor()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
worksheet.Cell(1, 1).Value = "Some Text";
|
|
|
|
ColumnFormatter.AutoFitWithPadding(worksheet.Column(1), 1.30);
|
|
|
|
// Width should be greater than 0 and include padding
|
|
worksheet.Column(1).Width.ShouldBeGreaterThan(0);
|
|
}
|
|
}
|