Files
Academic-Affairs-System/tests/Jiaowu.Api.Tests/TimetableExcelExporterTests.cs
T
2026-07-25 20:21:42 +08:00

101 lines
3.0 KiB
C#

using ClosedXML.Excel;
using Jiaowu.Api.Domain.Academic;
using Jiaowu.Api.Infrastructure.Timetables;
namespace Jiaowu.Api.Tests;
public sealed class TimetableExcelExporterTests
{
[Fact]
public void Create_builds_week_grid_and_flexible_course_section()
{
var timetable = new TimetableData(
new TimetableTermDto(
Guid.NewGuid(),
"2026-2027 学年第一学期",
"2026-2027",
TermSeason.Autumn,
new DateOnly(2026, 9, 1),
new DateOnly(2027, 1, 15),
true),
new TimetableSubjectDto(
Guid.NewGuid(),
"CS2601",
"计算机科学 2601 班",
TimetableResourceType.Class,
2026,
Guid.NewGuid(),
"计算机科学与技术",
Guid.NewGuid(),
"计算机学院",
null,
null,
null),
null,
null,
new TimetablePlanDto(
Guid.NewGuid(),
"正式课表",
"V1",
SchedulePlanStatus.Published,
DateTime.UtcNow,
DateTime.UtcNow),
[
new TimetableSlotDto(
1,
"第一节",
new TimeOnly(8, 0),
new TimeOnly(8, 45))
],
[
new TimetableEntryDto(
Guid.NewGuid(),
Guid.NewGuid(),
"TASK-01",
"高等数学 01",
"MATH101",
"高等数学",
["张老师"],
["计算机科学 2601 班"],
"101",
"第一教学楼",
"主校区",
1,
1,
2,
1,
16,
WeekPattern.All,
null)
],
[
new FlexibleCourseDto(
Guid.NewGuid(),
"TASK-02",
"劳动教育",
"LAB101",
"劳动教育",
1,
16,
1,
16,
1,
["李老师"],
["计算机科学 2601 班"],
null)
],
[]);
var bytes = TimetableExcelExporter.Create(timetable);
using var stream = new MemoryStream(bytes);
using var workbook = new XLWorkbook(stream);
var sheet = workbook.Worksheet("课表");
Assert.Contains("计算机科学 2601 班", sheet.Cell("A1").GetString());
Assert.Contains("高等数学", sheet.Cell(5, 2).GetString());
Assert.Contains(
sheet.CellsUsed(),
cell => cell.GetString().Contains("非排时课程"));
}
}