完善实验成绩导入模板字段

This commit is contained in:
biss committed 2026-11-18 21:45:10 +08:00
1 parent 666eab0d47
commit 3e718dc347
4 files changed
+80 -8

No files matched your search

@@ -321,6 +321,13 @@ public sealed class ExperimentGradesControllerTests
var worksheet = workbook.Worksheet("实验成绩导入");
worksheet.Cell("D2").Value = "已完成";
worksheet.Cell("E2").Value = 85;
Assert.Equal("提交物或报告地址", worksheet.Cell("J1").GetString());
Assert.Equal("评分项评语:操作", worksheet.Cell("M1").GetString());
worksheet.Cell("I2").Value = "总体良好";
worksheet.Cell("J2").Value = "https://example.com/report";
worksheet.Cell("K2").Value = new DateTime(2026, 11, 18, 14, 35, 42);
worksheet.Cell("L2").Value = "是";
worksheet.Cell("M2").Value = "操作熟练";
workbook.SaveAs(stream);
}
stream.Position = 0;
@@ -331,6 +338,30 @@ public sealed class ExperimentGradesControllerTests
Assert.Equal(85m, await fixture.Db.ExperimentGradeRecords
.Select(record => record.TotalScore)
.SingleAsync());
var record = await fixture.Db.ExperimentGradeRecords.Include(x => x.ItemScores).SingleAsync();
Assert.Equal("总体良好", record.TeacherComment);
Assert.Equal("https://example.com/report", record.SubmissionReference);
Assert.Equal(new DateTime(2026, 11, 18, 14, 35, 42), record.SubmittedAt);
Assert.True(record.IsLate);
Assert.Equal("操作熟练", Assert.Single(record.ItemScores).Comment);
var exported = Assert.IsType<FileContentResult>(await teacher.DownloadTemplate(sheet.Id, CancellationToken.None));
using var exportedStream = new MemoryStream(exported.FileContents);
using var oldWorkbook = new XLWorkbook(exportedStream);
var exportedSheet = oldWorkbook.Worksheet("实验成绩导入");
Assert.Equal("2026-11-18 14:35:42", exportedSheet.Cell("K2").GetString());
exportedSheet.Columns(10, 13).Delete();
await using var oldStream = new MemoryStream();
oldWorkbook.SaveAs(oldStream);
oldStream.Position = 0;
var oldFile = new FormFile(oldStream, 0, oldStream.Length, "file", "旧模板.xlsx");
Assert.IsType<OkObjectResult>(await teacher.ImportRecords(sheet.Id, oldFile, CancellationToken.None));
fixture.Db.ChangeTracker.Clear();
record = await fixture.Db.ExperimentGradeRecords.Include(x => x.ItemScores).SingleAsync();
Assert.Equal("https://example.com/report", record.SubmissionReference);
Assert.Equal(new DateTime(2026, 11, 18, 14, 35, 42), record.SubmittedAt);
Assert.True(record.IsLate);
Assert.Equal("操作熟练", Assert.Single(record.ItemScores).Comment);
}
[Fact]