26ff8d9b4f
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
81 lines
2.5 KiB
C#
81 lines
2.5 KiB
C#
using ClosedXML.Excel;
|
|
using JdeScoping.ExcelIO.Formatting;
|
|
using Shouldly;
|
|
using Xunit;
|
|
|
|
namespace JdeScoping.ExcelIO.Tests;
|
|
|
|
public class HeaderFormatterTests
|
|
{
|
|
[Fact]
|
|
public void ApplyHeaderFormat_Cell_AppliesCorrectStyling()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
var cell = worksheet.Cell(1, 1);
|
|
|
|
HeaderFormatter.ApplyHeaderFormat(cell, "Test Header");
|
|
|
|
cell.Value.GetText().ShouldBe("Test Header");
|
|
cell.Style.Font.Bold.ShouldBeTrue();
|
|
cell.Style.Alignment.Horizontal.ShouldBe(XLAlignmentHorizontalValues.Center);
|
|
cell.Style.Fill.BackgroundColor.ShouldBe(XLColor.Gainsboro);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyHeaderFormat_Cell_WithoutText_AppliesOnlyStyling()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
var cell = worksheet.Cell(1, 1);
|
|
cell.Value = "Original";
|
|
|
|
HeaderFormatter.ApplyHeaderFormat(cell);
|
|
|
|
cell.Value.GetText().ShouldBe("Original");
|
|
cell.Style.Font.Bold.ShouldBeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyHeaderFormat_Range_AppliesCorrectStyling()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
var range = worksheet.Range(1, 1, 1, 3);
|
|
|
|
HeaderFormatter.ApplyHeaderFormat(range, "Header", merge: false);
|
|
|
|
range.FirstCell().Value.GetText().ShouldBe("Header");
|
|
foreach (var cell in range.Cells())
|
|
{
|
|
cell.Style.Font.Bold.ShouldBeTrue();
|
|
cell.Style.Fill.BackgroundColor.ShouldBe(XLColor.Gainsboro);
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyHeaderFormat_Range_WithMerge_MergesCells()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
var range = worksheet.Range(1, 1, 1, 3);
|
|
|
|
HeaderFormatter.ApplyHeaderFormat(range, "Merged Header", merge: true);
|
|
|
|
range.IsMerged().ShouldBeTrue();
|
|
range.FirstCell().Value.GetText().ShouldBe("Merged Header");
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyHeaderFormat_Range_WithoutMerge_DoesNotMergeCells()
|
|
{
|
|
using var workbook = new XLWorkbook();
|
|
var worksheet = workbook.Worksheets.Add("Test");
|
|
var range = worksheet.Range(1, 1, 1, 3);
|
|
|
|
HeaderFormatter.ApplyHeaderFormat(range, "Not Merged", merge: false);
|
|
|
|
range.IsMerged().ShouldBeFalse();
|
|
}
|
|
}
|