public void Setup() { _contextFactory = new SampleDbContextFactory(); using ApplicationContext context = _contextFactory.CreateDbContext(); context.Lecturers.Add(new Lecturer { FullName = "Test Lecturer" }); context.SaveChanges(); }
public async Task GetByIdAsyncTest(IEnumerable <Course> data, int id, Course?expected) { // Arrange await using (ApplicationContext context = _contextFactory.CreateDbContext()) { await context.Courses.AddRangeAsync(data); await context.SaveChangesAsync(); } var loggerMock = new Mock <ILogger <CourseRepository> >(); var repository = new CourseRepository(_contextFactory, loggerMock.Object); // Act Course?course = await repository.GetByIdAsync(id); // Assert Assert.That(course, Is.EqualTo(expected)); }
public async Task GetByIdAsyncTest(IEnumerable <Lecturer> data, int id, Lecturer?expected) { // Arrange await using (ApplicationContext context = _contextFactory.CreateDbContext()) { await context.Lecturers.AddRangeAsync(data); await context.SaveChangesAsync(); } var loggerMock = new Mock <ILogger <LecturerRepository> >(); var repository = new LecturerRepository(_contextFactory, loggerMock.Object); // Act Lecturer?lecturer = await repository.GetByIdAsync(id); // Assert Assert.That(lecturer, Is.EqualTo(expected)); }
public async Task GetByIdAsyncTest(IEnumerable <Student> data, int id, Student?expected) { // Arrange await using (ApplicationContext context = _contextFactory.CreateDbContext()) { await context.Students.AddRangeAsync(data); await context.SaveChangesAsync(); } var loggerMock = new Mock <ILogger <StudentRepository> >(); var repository = new StudentRepository(_contextFactory, loggerMock.Object); // Act Student?student = await repository.GetByIdAsync(id); // Assert Assert.That(student, Is.EqualTo(expected)); }
public async Task GetByIdAsyncTest(IEnumerable <JournalRecord> data, int id, JournalRecord?expected) { // Arrange await using (ApplicationContext context = _contextFactory.CreateDbContext()) { await context.JournalRecords.AddRangeAsync(data); await context.SaveChangesAsync(); } var loggerMock = new Mock <ILogger <JournalRecordRepository> >(); var repository = new JournalRecordRepository(_contextFactory, loggerMock.Object); // Act JournalRecord?journalRecord = await repository.GetByIdAsync(id); // Assert Assert.That(journalRecord, Is.EqualTo(expected)); }
public void Setup() { _contextFactory = new SampleDbContextFactory(); using var context = _contextFactory.CreateDbContext(); context.Lecturers.Add(new Lecturer { FullName = "Test Lecturer" }); context.SaveChanges(); context.Courses.Add(new Course { Name = "Test Course", LecturerId = 1 }); context.SaveChanges(); context.Lectures.Add(new Lecture { Name = "Test Lecture 1", CourseId = 1 }); context.Lectures.Add(new Lecture { Name = "Test Lecture 2", CourseId = 1 }); context.Lectures.Add(new Lecture { Name = "Test Lecture 3", CourseId = 1 }); context.Lectures.Add(new Lecture { Name = "Test Lecture 4", CourseId = 1 }); context.Lectures.Add(new Lecture { Name = "Test Lecture 5", CourseId = 1 }); context.SaveChanges(); context.Students.Add(new Student { FullName = "Test Student" }); context.SaveChanges(); }