public async Task AddToCourseShouldAddStudentToCourse() { // Arrange var db = TestInit.InitializeInmemoryDatabase(); var teacherCoursesService = new TeacherCoursesService(db); var teacherStudentsService = new TeacherStudentsService(db); var userManager = testHelpers.GetUserManagerMock(); var roleManager = testHelpers.GetRoleManagerMock(); var usersController = new StudentsController(teacherStudentsService, teacherCoursesService, userManager, roleManager); usersController.TempData = new TempDataDictionary(Mock.Of <HttpContext>(), Mock.Of <ITempDataProvider>()); string studentId = "1"; int courseId = 1; db.Courses.Add(new Course { Id = courseId, Name = "Course" }); db.Students.Add(new Student { UserId = studentId }); await db.SaveChangesAsync(); // Act var result = await usersController.AddToCourse(studentId, courseId.ToString()); // Assert Assert.Contains(db.StudentCourses, sc => sc.StudentId == studentId && sc.CourseId == courseId); }