public async Task UnassignStudentMaterialAsyncWhenStudentIdAndStudyMaterialIdIsValidReturnsStudentMaterial() { // Arrange var mockStudentMaterial = new Mock <IStudentMaterialRepository>(); var mockUnitOfWork = new Mock <IUnitOfWork>(); var mockStudyMaterial = new Mock <IStudyMaterialRepository>(); int studentId = 1; int materialId = 1; int categoryId = 1; int instituteId = 1; var studentMaterial = new StudentMaterial() { StudentId = studentId, StudyMaterialId = materialId, CategoryId = categoryId, InstituteId = instituteId }; mockStudentMaterial.Setup(r => r.UnassignstudyMaterial(studentId, materialId)); mockStudentMaterial.Setup(r => r.FindByStudentIdAndStudyMaterialId(studentId, materialId)) .Returns(Task.FromResult(studentMaterial)); mockStudentMaterial.Setup(r => r.Remove(studentMaterial)); var service = new StudentMaterialService(mockStudentMaterial.Object, mockUnitOfWork.Object, mockStudyMaterial.Object); // Act StudentMaterialResponse result = await service.UnassignStudentMaterialAsync(studentId, materialId); // Assert result.Should().Equals(studentMaterial); }
public async Task UnassignstudyMaterial(int studentId, int materialId) { StudentMaterial studentMaterial = await FindByStudentIdAndStudyMaterialId(studentId, materialId); if (studentMaterial != null) { Remove(studentMaterial); } }
public async Task AssignStudentMaterial(int studentId, int materialId) { StudentMaterial result = await FindByStudentIdAndStudyMaterialId(studentId, materialId); if (result == null) { result = new StudentMaterial { StudentId = studentId, StudyMaterialId = materialId }; await AddAsync(result); } }
public async Task <StudentMaterialResponse> AssignStudentMaterialAsync(int studentId, StudentMaterial studentMaterial) { try { await _studentMaterialRepository.AssignStudentMaterial(studentId, studentMaterial.StudyMaterialId); await _unitOfWork.CompleteAsync(); StudentMaterial result = await _studentMaterialRepository.FindByStudentIdAndStudyMaterialId(studentId, studentMaterial.StudyMaterialId); return(new StudentMaterialResponse(result)); } catch (Exception ex) { return(new StudentMaterialResponse ($"An error ocurred while assigning StudyMaterial to Student: {ex.Message}")); } }
public async Task <StudentMaterialResponse> UnassignStudentMaterialAsync(int studentId, int materialId) { try { StudentMaterial studentMaterial = await _studentMaterialRepository.FindByStudentIdAndStudyMaterialId(studentId, materialId); _studentMaterialRepository.Remove(studentMaterial); await _unitOfWork.CompleteAsync(); var material = await _studyMaterialRepository.FindById(materialId); _studyMaterialRepository.Remove(material); await _unitOfWork.CompleteAsync(); return(new StudentMaterialResponse(studentMaterial)); } catch (Exception ex) { return(new StudentMaterialResponse ($"An error ocurred while unassigning StudyMaterial from Student: {ex.Message}")); } }
public void Remove(StudentMaterial studentMaterial) { _context.StudentMaterials.Remove(studentMaterial); }
public async Task AddAsync(StudentMaterial studentMaterial) { await _context.StudentMaterials.AddAsync(studentMaterial); }