修复“其他考试”成绩链路

This commit is contained in:
biss committed 2026-10-06 21:07:46 +08:00
1 parent ce2f91c36f
commit a5ef6d7b8e
3 files changed
+132 -21

No files matched your search

@@ -66,13 +66,23 @@ public sealed class OtherExamsControllerTests
EnrollmentDate = new DateOnly(2026, 9, 1),
Status = StudentStatus.Active
};
var anotherStudent = new Student
{
StudentNumber = "202600002",
Name = "另一测试学生",
AdministrativeClassId = administrativeClass.Id,
EnrollmentYear = 2026,
EnrollmentDate = new DateOnly(2026, 9, 1),
Status = StudentStatus.Active
};
var batch = new OtherExamBatch
{
ExamCode = "CET4",
Name = "大学英语四级",
ExamDate = new DateOnly(2026, 6, 1),
MetricKind = OtherExamMetricKind.Score,
MaxScore = 710
MaxScore = 710,
Status = OtherExamBatchStatus.Published
};
var oldResult = new OtherExamResult
{
@@ -81,7 +91,14 @@ public sealed class OtherExamsControllerTests
Score = 500,
AttemptNumber = 1
};
db.AddRange(college, major, administrativeClass, student, batch, oldResult);
var anotherOldResult = new OtherExamResult
{
OtherExamBatchId = batch.Id,
StudentId = anotherStudent.Id,
Score = 520,
AttemptNumber = 1
};
db.AddRange(college, major, administrativeClass, student, anotherStudent, batch, oldResult, anotherOldResult);
await db.SaveChangesAsync();
var controller = new OtherExamsController(db, new TestDataScope(college.Id));
@@ -91,10 +108,13 @@ public sealed class OtherExamsControllerTests
Assert.IsType<OkObjectResult>(result);
db.ChangeTracker.Clear();
var saved = await db.OtherExamResults.SingleAsync(x => x.OtherExamBatchId == batch.Id);
var saved = await db.OtherExamResults.SingleAsync(x => x.StudentId == student.Id);
Assert.Equal(610.5m, saved.Score);
Assert.Equal("已复核", saved.Notes);
Assert.Equal(1, saved.AttemptNumber);
Assert.Equal(2, await db.OtherExamResults.CountAsync(x => x.OtherExamBatchId == batch.Id));
Assert.Equal(520m, (await db.OtherExamResults.SingleAsync(x => x.StudentId == anotherStudent.Id)).Score);
Assert.Equal(OtherExamBatchStatus.Published, (await db.OtherExamBatches.SingleAsync()).Status);
}
[Fact]