Files
Joseph Doherty 621dd41a97 refactor(ExcelIO): delete old attribute-based infrastructure
- Remove OutputColumnAttribute, OutputTableAttribute, OutputColumnCache
- Remove AttributeTableWriter and ColumnFormatter
- Remove duplicate ExcelFormats from Mapping (use Formatting version)
- Remove OutputColumn model
- Add FilterEntryMaps for criteria sheet filter models
- Update CriteriaSheetGenerator to use FluentTableWriter
- Remove attributes from filter entry models (now use fluent maps)
- Update DI to register filter entry maps and remove old services
- Update tests to use new fluent infrastructure
- Delete obsolete test files for removed infrastructure

Task 16 of fluent-excel-mapping-implementation plan.
2026-01-06 23:56:02 -05:00

136 lines
3.6 KiB
C#

using JdeScoping.ExcelIO.Formatting;
using JdeScoping.ExcelIO.Mapping;
using Shouldly;
using Xunit;
namespace JdeScoping.ExcelIO.Tests.Mapping;
public class ExcelClassMapTests
{
// Test model
private sealed class TestModel
{
public int Id { get; init; }
public string Name { get; init; } = string.Empty;
public DateTime CreatedAt { get; init; }
}
// Test map
private sealed class TestModelMap : ExcelClassMap<TestModel>
{
public TestModelMap()
{
Table("Test_Table", "Test Tab");
Map(x => x.Id).Order(10).Header("ID Number");
Map(x => x.Name).Order(20).Header("Full Name");
Map(x => x.CreatedAt).Order(30).Header("Created").Format(ExcelFormats.TimestampFormat);
}
}
[Fact]
public void MappedType_ReturnsCorrectType()
{
var map = new TestModelMap();
map.MappedType.ShouldBe(typeof(TestModel));
}
[Fact]
public void Table_SetsTableAndTabName()
{
var map = new TestModelMap();
map.TableName.ShouldBe("Test_Table");
map.TabName.ShouldBe("Test Tab");
}
[Fact]
public void Columns_ReturnsOrderedColumns()
{
var map = new TestModelMap();
var columns = map.Columns;
columns.Count.ShouldBe(3);
columns[0].PropertyName.ShouldBe("Id");
columns[1].PropertyName.ShouldBe("Name");
columns[2].PropertyName.ShouldBe("CreatedAt");
}
[Fact]
public void Map_SetsHeaderText()
{
var map = new TestModelMap();
var columns = map.Columns;
columns[0].HeaderText.ShouldBe("ID Number");
columns[1].HeaderText.ShouldBe("Full Name");
columns[2].HeaderText.ShouldBe("Created");
}
[Fact]
public void Map_SetsFormat()
{
var map = new TestModelMap();
var columns = map.Columns;
columns[2].Format.ShouldBe(ExcelFormats.TimestampFormat);
}
[Fact]
public void ValueGetter_ExtractsPropertyValue()
{
var map = new TestModelMap();
var columns = map.Columns;
var testObj = new TestModel { Id = 42, Name = "Test", CreatedAt = new DateTime(2024, 1, 15) };
columns[0].ValueGetter(testObj).ShouldBe(42);
columns[1].ValueGetter(testObj).ShouldBe("Test");
columns[2].ValueGetter(testObj).ShouldBe(new DateTime(2024, 1, 15));
}
}
public class ExcelMapRegistryTests
{
private sealed class DummyModel { public int Id { get; init; } }
private sealed class DummyMap : ExcelClassMap<DummyModel>
{
public DummyMap() { Map(x => x.Id).Order(1).Header("ID"); }
}
[Fact]
public void Register_AndGetMap_ReturnsMap()
{
var registry = new ExcelMapRegistry();
var map = new DummyMap();
registry.Register(map);
var retrieved = registry.GetMap<DummyModel>();
retrieved.ShouldBe(map);
}
[Fact]
public void GetMap_UnregisteredType_ThrowsInvalidOperationException()
{
var registry = new ExcelMapRegistry();
Should.Throw<InvalidOperationException>(() => registry.GetMap<DummyModel>());
}
[Fact]
public void HasMap_RegisteredType_ReturnsTrue()
{
var registry = new ExcelMapRegistry();
registry.Register(new DummyMap());
registry.HasMap<DummyModel>().ShouldBeTrue();
}
[Fact]
public void HasMap_UnregisteredType_ReturnsFalse()
{
var registry = new ExcelMapRegistry();
registry.HasMap<DummyModel>().ShouldBeFalse();
}
}