修复场地课表遗漏借用的问题
This commit is contained in:
1 parent
5872c06042
commit
54e1986ad0
3 files changed
+102
-4
No files matched your search
@@ -0,0 +1,66 @@
|
||||
using System.Text.Json;
|
||||
using Jiaowu.Api.Controllers;
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Jiaowu.Api.Infrastructure.Timetables;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class VenueDisplaysControllerTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Classroom_IncludesApprovedReservationForToday()
|
||||
{
|
||||
await using var connection = new SqliteConnection("Data Source=:memory:");
|
||||
await connection.OpenAsync();
|
||||
var db = new AppDbContext(new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options);
|
||||
await db.Database.EnsureCreatedAsync();
|
||||
|
||||
var today = DateOnly.FromDateTime(DateTime.Now);
|
||||
var campus = new Campus { Code = "MAIN", Name = "主校区" };
|
||||
var building = new Building { Code = "A", Name = "明德楼", CampusId = campus.Id };
|
||||
var classroom = new Classroom { Code = "A101", Name = "A101", BuildingId = building.Id, Capacity = 60 };
|
||||
var college = new College { Code = "CS", Name = "计算机学院" };
|
||||
var applicant = new ApplicationUser
|
||||
{
|
||||
Id = Guid.NewGuid(), UserName = "applicant", NormalizedUserName = "APPLICANT",
|
||||
DisplayName = "张老师", CollegeId = college.Id
|
||||
};
|
||||
var term = new AcademicTerm
|
||||
{
|
||||
Code = "CURRENT", Name = "当前学期", AcademicYear = "2026-2027", Season = TermSeason.Autumn,
|
||||
StartDate = today.AddDays(-7), EndDate = today.AddDays(120), IsCurrent = true
|
||||
};
|
||||
db.AddRange(campus, building, classroom, college, applicant, term);
|
||||
db.ClassroomReservations.Add(new ClassroomReservation
|
||||
{
|
||||
ApplicantUserId = applicant.Id, ApplicantName = applicant.DisplayName,
|
||||
ApplicantCollegeId = college.Id, AcademicTermId = term.Id, ClassroomId = classroom.Id,
|
||||
ReservationDate = today, StartPeriod = 3, PeriodCount = 2, AttendeeCount = 30,
|
||||
Purpose = "学院学术讲座", ContactPhone = "13800000000",
|
||||
Status = ClassroomReservationStatus.Approved
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var controller = new VenueDisplaysController(
|
||||
db,
|
||||
new TimetableDataService(db),
|
||||
new ClassroomReservationAvailabilityService(db));
|
||||
|
||||
var result = await controller.Classroom(classroom.Id, CancellationToken.None);
|
||||
|
||||
var response = Assert.IsType<OkObjectResult>(result).Value;
|
||||
using var document = JsonDocument.Parse(JsonSerializer.Serialize(response));
|
||||
var entry = Assert.Single(document.RootElement.GetProperty("Entries").EnumerateArray());
|
||||
Assert.Equal("教室借用", entry.GetProperty("CourseName").GetString());
|
||||
Assert.Equal("学院学术讲座", entry.GetProperty("ClassNames")[0].GetString());
|
||||
Assert.Equal("张老师", entry.GetProperty("TeacherNames")[0].GetString());
|
||||
Assert.True(entry.GetProperty("IsReservation").GetBoolean());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user