成绩分析
This commit is contained in:
1 parent
0a0500dd70
commit
9ba83c3dc1
4 files changed
+754
-33
No files matched your search
@@ -1,11 +1,22 @@
|
||||
using DocumentFormat.OpenXml.Packaging;
|
||||
using Jiaowu.Api.Controllers;
|
||||
using Jiaowu.Api.Infrastructure.Grades;
|
||||
using Jiaowu.Api.Infrastructure.Pdf;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class GradeAnalysisWordReportGeneratorTests
|
||||
{
|
||||
[Fact]
|
||||
public void ChineseTypefaceResolver_ProvidesChineseGlyphsForReportCharts()
|
||||
{
|
||||
using var typeface = PdfTypefaceResolver.ResolveChineseTypeface(null);
|
||||
using var font = new SKFont(typeface, 20);
|
||||
|
||||
Assert.True(font.ContainsGlyphs("人数平均分合格率"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generate_CreatesReadableDocxWithAnalysisSectionsAndCharts()
|
||||
{
|
||||
@@ -37,8 +48,38 @@ public sealed class GradeAnalysisWordReportGeneratorTests
|
||||
Assert.Contains("同课程教学班对比", text);
|
||||
Assert.Contains("各范围基准", text);
|
||||
Assert.Contains("历年成绩趋势", text);
|
||||
Assert.Contains("行政班组成", text);
|
||||
Assert.Contains("计科一班", text);
|
||||
Assert.Equal(3, document.MainDocumentPart.ImageParts.Count());
|
||||
Assert.Equal(2, document.MainDocumentPart.HeaderParts.Count());
|
||||
Assert.Equal(2, document.MainDocumentPart.FooterParts.Count());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Generate_CourseOverallReport_CreatesReadableDocx()
|
||||
{
|
||||
var now = new DateTime(2026, 8, 21, 10, 30, 0, DateTimeKind.Local);
|
||||
var summary = new GradeAnalyticsController.CourseOverview(
|
||||
Guid.NewGuid(), "CS101", "程序设计", Guid.NewGuid(), "计算机学院", 2, 3,
|
||||
30, 26, 8, 99m, 78.5m, 52m, 86.67m, 26.67m, now);
|
||||
var report = new GradeAnalyticsController.CourseOverallAnalysisReport(
|
||||
summary,
|
||||
[new("0–59", 0, 60, 4), new("60–69", 60, 70, 6),
|
||||
new("70–79", 70, 80, 8), new("80–89", 80, 90, 7), new("90–100", 90, null, 5)],
|
||||
[new(Guid.NewGuid(), "2025-2026 学年第二学期", 1, 12, 76m, 83.33m, 25m),
|
||||
new(Guid.NewGuid(), "2026-2027 学年第一学期", 2, 18, 80.2m, 88.89m, 27.78m)],
|
||||
[new("计算机学院", 18, 80m, 88.89m, 27.78m), new("电子信息学院", 12, 76.3m, 83.33m, 25m)],
|
||||
[new(Guid.NewGuid(), Guid.NewGuid(), "2026-2027 学年第一学期", "TASK-01", "程序设计一班", "张老师", 18, 99m, 80.2m, 82m, 52m, 11.2m, 88.89m, 27.78m)]);
|
||||
|
||||
var bytes = GradeAnalysisWordReportGenerator.Generate(report, now);
|
||||
|
||||
Assert.True(bytes.Length > 8_000);
|
||||
using var stream = new MemoryStream(bytes);
|
||||
using var document = WordprocessingDocument.Open(stream, false);
|
||||
var text = document.MainDocumentPart!.Document.InnerText;
|
||||
Assert.Contains("科目总体成绩分析报告", text);
|
||||
Assert.Contains("学生来源学院对比", text);
|
||||
Assert.Contains("教学班横向比较", text);
|
||||
Assert.Single(document.MainDocumentPart.ImageParts);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user