fix: лекции когда возвращались не говорили записан ли студент уже или нет
This commit is contained in:
@@ -177,7 +177,7 @@ public class ApiWebApplicationFactory : WebApplicationFactory<Program>
|
||||
var pagedLectures = PagedResult<LectureDto>.Create([lectureDto], 1, 1, 20);
|
||||
var pagedEnrollments = PagedResult<EnrollmentDto>.Create([], 0, 1, 20);
|
||||
|
||||
stub.GetAllAsync(Arg.Any<LectureFilterRequest>()).Returns(pagedLectures);
|
||||
stub.GetAllAsync(Arg.Any<LectureFilterRequest>(), Arg.Any<int?>()).Returns(pagedLectures);
|
||||
stub.GetByIdAsync(Arg.Any<int>(), Arg.Any<int?>()).Returns(detailDto);
|
||||
stub.CreateAsync(Arg.Any<CreateLectureRequest>()).Returns(lectureDto);
|
||||
stub.UpdateAsync(Arg.Any<int>(), Arg.Any<UpdateLectureRequest>()).Returns(lectureDto);
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NSubstitute;
|
||||
using UniVerse.Application.DTOs.Lectures;
|
||||
using UniVerse.Application.Interfaces;
|
||||
using UniVerse.Domain.Entities;
|
||||
using UniVerse.Infrastructure.Data;
|
||||
using UniVerse.Infrastructure.Services;
|
||||
using Xunit;
|
||||
|
||||
namespace UniVerse.Api.Tests.Lectures;
|
||||
|
||||
public class LectureServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task GetAllAsync_MarksLecturesEnrolledByCurrentUser()
|
||||
{
|
||||
await using var db = CreateDbContext();
|
||||
var service = new LectureService(db, Substitute.For<IGamificationService>());
|
||||
var startsAt = DateTime.UtcNow.AddDays(1);
|
||||
|
||||
db.Users.Add(new User { Id = 1, Email = "student@test.local" });
|
||||
db.Courses.Add(new Course { Id = 1, Name = "Course" });
|
||||
db.Lectures.AddRange(
|
||||
Lecture(1, startsAt),
|
||||
Lecture(2, startsAt.AddDays(1)));
|
||||
db.LectureEnrollments.Add(new LectureEnrollment { LectureId = 1, UserId = 1 });
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var result = await service.GetAllAsync(new LectureFilterRequest(null, null, null, null, null, null, null, null), 1);
|
||||
|
||||
Assert.True(result.Items.Single(item => item.Id == 1).IsEnrolled);
|
||||
Assert.False(result.Items.Single(item => item.Id == 2).IsEnrolled);
|
||||
}
|
||||
|
||||
private static AppDbContext CreateDbContext()
|
||||
{
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseInMemoryDatabase($"LectureServiceTests_{Guid.NewGuid()}")
|
||||
.Options;
|
||||
return new AppDbContext(options);
|
||||
}
|
||||
|
||||
private static Lecture Lecture(int id, DateTime startsAt) => new()
|
||||
{
|
||||
Id = id,
|
||||
CourseId = 1,
|
||||
Title = $"Lecture {id}",
|
||||
StartsAt = startsAt,
|
||||
EndsAt = startsAt.AddHours(2),
|
||||
IsOpen = true,
|
||||
MaxEnrollments = 30
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user