选课批次:时间窗口、退课截止、学分上限、开放/关闭。
教学班投放:容量、班级范围、全校开放。 学生选退课:容量、重复课程、学分上限、课表冲突校验。 教学班实时名单。 校级、学院级、学生角色分级操作。 SQLite 本地增量升级及演示数据。 MySQL 正式 EF Core 迁移。 Vue 已编译进 wwwroot,单服务运行无需 npm run dev。 学生端和管理端均完成桌面、手机响应式检查。
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Infrastructure.CourseSelection;
|
||||
|
||||
namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class CourseSelectionRulesTests
|
||||
{
|
||||
[Fact]
|
||||
public void Selection_requires_open_status_and_active_window()
|
||||
{
|
||||
var now = new DateTime(2026, 7, 24, 8, 0, 0, DateTimeKind.Utc);
|
||||
var round = CreateRound(now.AddHours(-1), now.AddHours(1));
|
||||
|
||||
Assert.True(CourseSelectionRules.IsSelectionOpen(round, now));
|
||||
|
||||
round.Status = CourseSelectionRoundStatus.Closed;
|
||||
Assert.False(CourseSelectionRules.IsSelectionOpen(round, now));
|
||||
|
||||
round.Status = CourseSelectionRoundStatus.Open;
|
||||
Assert.False(CourseSelectionRules.IsSelectionOpen(round, now.AddHours(2)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Withdrawal_respects_deadline()
|
||||
{
|
||||
var now = new DateTime(2026, 7, 24, 8, 0, 0, DateTimeKind.Utc);
|
||||
var round = CreateRound(now.AddDays(-1), now.AddDays(1));
|
||||
round.WithdrawalEndsAt = now.AddMinutes(30);
|
||||
|
||||
Assert.True(CourseSelectionRules.CanWithdraw(round, now));
|
||||
Assert.False(CourseSelectionRules.CanWithdraw(round, now.AddHours(1)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Schedule_conflict_detects_overlapping_weeks_and_periods()
|
||||
{
|
||||
var selected = CreateEntry(1, 1, 2, 1, 16, WeekPattern.All);
|
||||
var overlapping = CreateEntry(1, 2, 2, 1, 16, WeekPattern.All);
|
||||
|
||||
Assert.True(CourseSelectionRules.HasScheduleConflict(
|
||||
[overlapping],
|
||||
[selected]));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Odd_and_even_week_entries_do_not_conflict()
|
||||
{
|
||||
var selected = CreateEntry(3, 5, 2, 1, 16, WeekPattern.Odd);
|
||||
var candidate = CreateEntry(3, 5, 2, 1, 16, WeekPattern.Even);
|
||||
|
||||
Assert.False(CourseSelectionRules.HasScheduleConflict(
|
||||
[candidate],
|
||||
[selected]));
|
||||
}
|
||||
|
||||
private static CourseSelectionRound CreateRound(DateTime startsAt, DateTime endsAt) =>
|
||||
new()
|
||||
{
|
||||
Name = "第一轮选课",
|
||||
StartsAt = startsAt,
|
||||
EndsAt = endsAt,
|
||||
WithdrawalEndsAt = endsAt.AddDays(1),
|
||||
Status = CourseSelectionRoundStatus.Open
|
||||
};
|
||||
|
||||
private static ScheduleEntry CreateEntry(
|
||||
int dayOfWeek,
|
||||
int startPeriod,
|
||||
int periodCount,
|
||||
int startWeek,
|
||||
int endWeek,
|
||||
WeekPattern weekPattern) =>
|
||||
new()
|
||||
{
|
||||
DayOfWeek = dayOfWeek,
|
||||
StartPeriod = startPeriod,
|
||||
PeriodCount = periodCount,
|
||||
StartWeek = startWeek,
|
||||
EndWeek = endWeek,
|
||||
WeekPattern = weekPattern
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user