排课
Build and publish Jiaowu packages and container image / Test, package and publish (push) Successful in 32m28s
Build and publish Jiaowu packages and container image / Test, package and publish (push) Successful in 32m28s
This commit is contained in:
@@ -0,0 +1,205 @@
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Infrastructure.Exams;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class ExamArrangementServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Normal_arrangement_only_updates_selected_sessions_and_requested_resource()
|
||||
{
|
||||
await using var connection = new SqliteConnection("Data Source=:memory:");
|
||||
await connection.OpenAsync();
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
await using var db = new AppDbContext(options);
|
||||
await db.Database.EnsureCreatedAsync();
|
||||
var seed = await SeedBaseDataAsync(db, "NORMAL");
|
||||
|
||||
var plan = new ExamPlan
|
||||
{
|
||||
AcademicTermId = seed.Term.Id,
|
||||
Name = "期末考试"
|
||||
};
|
||||
var selected = NewExamSession(plan.Id, seed.FirstTask.Id);
|
||||
var untouched = NewExamSession(plan.Id, seed.SecondTask.Id);
|
||||
plan.Sessions.Add(selected);
|
||||
plan.Sessions.Add(untouched);
|
||||
db.ExamPlans.Add(plan);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var result = await new ExamArrangementService(db).ArrangeAsync(
|
||||
plan.Id,
|
||||
[selected.Id],
|
||||
assignClassrooms: true,
|
||||
assignInvigilators: false,
|
||||
CancellationToken.None);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.NotNull(selected.ClassroomId);
|
||||
Assert.Null(untouched.ClassroomId);
|
||||
Assert.Empty(selected.Invigilators);
|
||||
Assert.Contains("1个场次处理完成", result.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Makeup_arrangement_only_updates_selected_sessions_and_requested_resource()
|
||||
{
|
||||
await using var connection = new SqliteConnection("Data Source=:memory:");
|
||||
await connection.OpenAsync();
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
await using var db = new AppDbContext(options);
|
||||
await db.Database.EnsureCreatedAsync();
|
||||
var seed = await SeedBaseDataAsync(db, "MAKEUP");
|
||||
|
||||
var plan = new MakeupExamPlan
|
||||
{
|
||||
AcademicTermId = seed.Term.Id,
|
||||
Name = "补考计划"
|
||||
};
|
||||
var selected = NewMakeupExamSession(plan.Id, seed.FirstTask.Id);
|
||||
var untouched = NewMakeupExamSession(plan.Id, seed.SecondTask.Id);
|
||||
plan.Sessions.Add(selected);
|
||||
plan.Sessions.Add(untouched);
|
||||
db.MakeupExamPlans.Add(plan);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var result = await new MakeupExamArrangementService(db).ArrangeAsync(
|
||||
plan.Id,
|
||||
[selected.Id],
|
||||
assignClassrooms: true,
|
||||
assignInvigilators: false,
|
||||
CancellationToken.None);
|
||||
|
||||
Assert.True(result.Success);
|
||||
Assert.NotNull(selected.ClassroomId);
|
||||
Assert.Null(untouched.ClassroomId);
|
||||
Assert.Empty(selected.Invigilators);
|
||||
Assert.Contains("1个场次处理完成", result.Message);
|
||||
}
|
||||
|
||||
private static ExamSession NewExamSession(Guid planId, Guid taskId) => new()
|
||||
{
|
||||
ExamPlanId = planId,
|
||||
TeachingTaskId = taskId,
|
||||
ExamDate = new DateOnly(2026, 12, 28),
|
||||
StartPeriod = 1,
|
||||
PeriodCount = 2,
|
||||
StartsAt = new DateTime(2026, 12, 28, 8, 0, 0, DateTimeKind.Utc),
|
||||
EndsAt = new DateTime(2026, 12, 28, 9, 50, 0, DateTimeKind.Utc),
|
||||
RequiredInvigilatorCount = 1
|
||||
};
|
||||
|
||||
private static MakeupExamSession NewMakeupExamSession(Guid planId, Guid taskId) => new()
|
||||
{
|
||||
MakeupExamPlanId = planId,
|
||||
TeachingTaskId = taskId,
|
||||
ExamDate = new DateOnly(2026, 12, 28),
|
||||
StartPeriod = 1,
|
||||
PeriodCount = 2,
|
||||
StartsAt = new DateTime(2026, 12, 28, 8, 0, 0, DateTimeKind.Utc),
|
||||
EndsAt = new DateTime(2026, 12, 28, 9, 50, 0, DateTimeKind.Utc),
|
||||
RequiredInvigilatorCount = 1
|
||||
};
|
||||
|
||||
private static async Task<SeedData> SeedBaseDataAsync(AppDbContext db, string suffix)
|
||||
{
|
||||
var term = new AcademicTerm
|
||||
{
|
||||
Code = $"2026-{suffix}",
|
||||
Name = $"2026 {suffix}",
|
||||
AcademicYear = "2026-2027",
|
||||
Season = TermSeason.Autumn,
|
||||
StartDate = new DateOnly(2026, 9, 1),
|
||||
EndDate = new DateOnly(2027, 1, 15)
|
||||
};
|
||||
var campus = new Campus { Code = $"C-{suffix}", Name = "主校区" };
|
||||
var college = new College
|
||||
{
|
||||
Code = $"COL-{suffix}",
|
||||
Name = "计算机学院",
|
||||
CampusId = campus.Id
|
||||
};
|
||||
var building = new Building
|
||||
{
|
||||
Code = $"B-{suffix}",
|
||||
Name = "第一教学楼",
|
||||
CampusId = campus.Id
|
||||
};
|
||||
var classroom = new Classroom
|
||||
{
|
||||
Code = $"R-{suffix}",
|
||||
Name = "101",
|
||||
BuildingId = building.Id,
|
||||
Capacity = 80
|
||||
};
|
||||
var firstCourse = new Course
|
||||
{
|
||||
Code = $"COURSE-1-{suffix}",
|
||||
Name = "程序设计",
|
||||
CollegeId = college.Id
|
||||
};
|
||||
var secondCourse = new Course
|
||||
{
|
||||
Code = $"COURSE-2-{suffix}",
|
||||
Name = "大学英语",
|
||||
CollegeId = college.Id
|
||||
};
|
||||
var firstTask = new TeachingTask
|
||||
{
|
||||
TaskNumber = $"TASK-1-{suffix}",
|
||||
Name = "程序设计教学班",
|
||||
AcademicTermId = term.Id,
|
||||
CourseId = firstCourse.Id,
|
||||
Status = TeachingTaskStatus.Published
|
||||
};
|
||||
var secondTask = new TeachingTask
|
||||
{
|
||||
TaskNumber = $"TASK-2-{suffix}",
|
||||
Name = "大学英语教学班",
|
||||
AcademicTermId = term.Id,
|
||||
CourseId = secondCourse.Id,
|
||||
Status = TeachingTaskStatus.Published
|
||||
};
|
||||
|
||||
db.AddRange(
|
||||
term,
|
||||
campus,
|
||||
college,
|
||||
building,
|
||||
classroom,
|
||||
firstCourse,
|
||||
secondCourse,
|
||||
firstTask,
|
||||
secondTask,
|
||||
new ScheduleTimeSlot
|
||||
{
|
||||
AcademicTermId = term.Id,
|
||||
PeriodNumber = 1,
|
||||
Name = "第1节",
|
||||
StartsAt = new TimeOnly(8, 0),
|
||||
EndsAt = new TimeOnly(8, 45)
|
||||
},
|
||||
new ScheduleTimeSlot
|
||||
{
|
||||
AcademicTermId = term.Id,
|
||||
PeriodNumber = 2,
|
||||
Name = "第2节",
|
||||
StartsAt = new TimeOnly(9, 0),
|
||||
EndsAt = new TimeOnly(9, 50)
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
return new SeedData(term, firstTask, secondTask);
|
||||
}
|
||||
|
||||
private sealed record SeedData(
|
||||
AcademicTerm Term,
|
||||
TeachingTask FirstTask,
|
||||
TeachingTask SecondTask);
|
||||
}
|
||||
Reference in New Issue
Block a user