Files
2026-04-20 14:47:24 -05:00

85 lines
2.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LCU.API.Collections.RepoApi.Models.Reporting;
using LCU.Shared.Collections.RepoApiLib.Formatting;
using LCU.Shared.Collections.RepoApiLib.Models.Reporting.Responses;
using Xunit;
namespace LCU.API.Collections.RepoApiTests
{
internal class DummyClass
{
public int RepoId { get; set; }
public string SomeString { get; set; }
}
public class DataTableFormattingTest
{
[Fact]
public void CreateDataTable_Ok()
{
// Arrange
var dummyData = new List<DummyClass>()
{
new DummyClass()
{
RepoId = 49,
SomeString = "String"
},
new DummyClass()
{
RepoId = 51
}
};
// Act
var dataTable = DataTableFormatting.CreateDataTable(
dummyData,
(entry) => entry.RepoId,
(entry) => new ReportHeaderCellMap()
{
Header = "First Header",
Cell = new ReportCell()
{
Display = entry?.SomeString,
Value = 123
}
},
(entry) => new ReportHeaderCellMap()
{
Header = "2nd Header",
Cell = new ReportCell()
{
Display = "Whatever I want",
Value = true
}
});
// Assert
Assert.NotNull(dataTable);
Assert.Equal(2, dataTable.Headers.Length);
Assert.Equal("First Header", dataTable.Headers[0]);
Assert.Equal("2nd Header", dataTable.Headers[1]);
Assert.Equal(2, dataTable.Rows.Count());
var firstRow = dataTable.Rows.ElementAt(0);
Assert.Equal(49, firstRow.RepoId);
Assert.Equal("String", firstRow.Cells[0].Display);
Assert.Equal(123, firstRow.Cells[0].Value);
Assert.Equal("Whatever I want", firstRow.Cells[1].Display);
Assert.Equal(true, firstRow.Cells[1].Value);
var secondRow = dataTable.Rows.ElementAt(1);
Assert.Equal(51, secondRow.RepoId);
Assert.Null(secondRow.Cells[0].Display);
Assert.Equal(123, secondRow.Cells[0].Value);
Assert.Equal("Whatever I want", secondRow.Cells[1].Display);
Assert.Equal(true, secondRow.Cells[1].Value);
}
}
}