新增消息一键已读
This commit is contained in:
@@ -234,6 +234,53 @@ public sealed class NotificationsControllerTests
|
||||
Assert.Equal(fixture.ClassStudentUser.Id, notification.UserId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Mark_all_read_only_updates_the_current_users_unread_notifications()
|
||||
{
|
||||
await using var fixture = await NotificationFixture.CreateAsync();
|
||||
fixture.Db.Notifications.AddRange(
|
||||
new Notification
|
||||
{
|
||||
UserId = fixture.Sender.Id,
|
||||
Title = "当前用户未读",
|
||||
Content = "应被标为已读。"
|
||||
},
|
||||
new Notification
|
||||
{
|
||||
UserId = fixture.Sender.Id,
|
||||
Title = "当前用户已读",
|
||||
Content = "应保持已读。",
|
||||
IsRead = true
|
||||
},
|
||||
new Notification
|
||||
{
|
||||
UserId = fixture.CollegeRecipient.Id,
|
||||
Title = "其他用户未读",
|
||||
Content = "不应被修改。"
|
||||
});
|
||||
await fixture.Db.SaveChangesAsync();
|
||||
|
||||
var controller = new NotificationsController(
|
||||
fixture.Db,
|
||||
new TestDataScope(
|
||||
fixture.Sender.Id,
|
||||
fixture.FirstCollege.Id,
|
||||
SystemRoles.AcademicAdmin));
|
||||
|
||||
var result = await controller.MarkAllRead(CancellationToken.None);
|
||||
|
||||
Assert.IsType<NoContentResult>(result);
|
||||
var notifications = await fixture.Db.Notifications.AsNoTracking()
|
||||
.OrderBy(x => x.Title)
|
||||
.ToListAsync();
|
||||
Assert.All(
|
||||
notifications.Where(x => x.UserId == fixture.Sender.Id),
|
||||
notification => Assert.True(notification.IsRead));
|
||||
Assert.False(Assert.Single(
|
||||
notifications,
|
||||
x => x.UserId == fixture.CollegeRecipient.Id).IsRead);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Publishing_course_grades_automatically_notifies_roster_students()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user