Files
Academic-Affairs-System/tests/Jiaowu.Api.Tests/StudentCourseProgressRulesTests.cs
T
2026-10-15 12:44:08 +08:00

74 lines
2.5 KiB
C#

using Jiaowu.Api.Domain.Academic;
using Jiaowu.Api.Infrastructure.Graduation;
namespace Jiaowu.Api.Tests;
public sealed class StudentCourseProgressRulesTests
{
[Fact]
public void Persisted_evaluation_result_overrides_numeric_reference_score()
{
var evaluation = StudentCourseProgressRules.Evaluate(
[
new StudentCourseAttemptSnapshot(80, GradeExamStatus.Normal, false),
new StudentCourseAttemptSnapshot(40, GradeExamStatus.Normal, true)
],
false);
Assert.True(evaluation.HasPassedAttempt);
Assert.True(evaluation.HasFailedAttempt);
Assert.Equal(StudentCourseProgressStatus.Completed, evaluation.Status);
}
[Fact]
public void Passed_attempt_takes_precedence_over_other_states()
{
var result = StudentCourseProgressRules.Evaluate(
[
new StudentCourseAttemptSnapshot(52, GradeExamStatus.Normal),
new StudentCourseAttemptSnapshot(76, GradeExamStatus.Normal)
],
true);
Assert.Equal(StudentCourseProgressStatus.Completed, result.Status);
Assert.True(result.HasPassedAttempt);
Assert.True(result.HasFailedAttempt);
}
[Fact]
public void Failed_course_becomes_retaking_when_currently_in_progress()
{
var result = StudentCourseProgressRules.Evaluate(
[new StudentCourseAttemptSnapshot(48, GradeExamStatus.Normal)],
true);
Assert.Equal(StudentCourseProgressStatus.Retaking, result.Status);
Assert.False(result.HasPassedAttempt);
Assert.True(result.HasFailedAttempt);
}
[Theory]
[InlineData(GradeExamStatus.Absent, StudentCourseProgressStatus.Failed)]
[InlineData(GradeExamStatus.Deferred, StudentCourseProgressStatus.Pending)]
public void Special_exam_states_are_presented_accurately(
GradeExamStatus examStatus,
StudentCourseProgressStatus expected)
{
var result = StudentCourseProgressRules.Evaluate(
[new StudentCourseAttemptSnapshot(null, examStatus)],
false);
Assert.Equal(expected, result.Status);
}
[Fact]
public void Current_course_without_result_is_in_progress()
{
var result = StudentCourseProgressRules.Evaluate([], true);
Assert.Equal(StudentCourseProgressStatus.InProgress, result.Status);
Assert.False(result.HasPassedAttempt);
Assert.False(result.HasFailedAttempt);
}
}