public async void AddCourses_AddsCoursesWithSameIdFromTheListOfSudentCourses() { //Arrange var connectionBuilder = new SqliteConnectionStringBuilder { DataSource = ":memory:" }; var connection = new SqliteConnection(connectionBuilder.ToString()); var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseSqlite(connection) .Options; using var context = new ApplicationDbContext(options); context.Database.OpenConnection(); context.Database.EnsureCreated(); var studentRepository = new StudentRepository(context); var courseRepository = new CourseRepository(context); var student = StudentHelpers.GetStudent(); var courses = CourseHelpers.GetCourses(); //Act foreach (var course in courses) { await courseRepository.Insert(course); } await studentRepository.Insert(student); await studentRepository.AddManyCourses(new List <int> { 1, 2, 3 }, "5"); var numberOfCoursesAfterInsertion = (await studentRepository.GetCourses("5")).Count(); //Assert Assert.Equal(3, numberOfCoursesAfterInsertion); await Assert.ThrowsAsync <AppUserException>( () => studentRepository.AddManyCourses(new List <int> { 1, 2, 3 }, "5")); await Assert.ThrowsAsync <AppUserException>( () => studentRepository.AddManyCourses(new List <int> { 10, 29, 13 }, "5")); }