public async Task PutAsyncWhenTrainingTutorsReturnsTrainingTutor() { // Arrange var mockTrainingTutorRepository = GetDefaultITrainingTutorRepositoryInstance(); var mockIUnitOfWork = GetDefaultIUnitOfWorkInstance(); TrainingTutor trainingTutor = new TrainingTutor(); int trainingId = 2; int tutorId = 102; trainingTutor.TrainingId = trainingId; trainingTutor.TutorId = tutorId; trainingTutor.Assistance = false; TrainingTutor trainingTutorExpected = new TrainingTutor(); trainingTutorExpected.Assistance = true; mockTrainingTutorRepository.Setup(r => r.FindByTrainingIdAndTutorId(trainingId, tutorId)) .Returns(Task.FromResult <TrainingTutor>(trainingTutor)); var service = new TrainingTutorService(mockTrainingTutorRepository.Object, mockIUnitOfWork.Object, null); // Act TrainingTutorResponse result = await service.UpdateAsync(trainingId, tutorId, trainingTutorExpected); // Assert Assert.AreEqual(trainingTutorExpected.Assistance, result.Resource.Assistance); }
public async Task <TrainingTutorResponse> SaveAsync(TrainingTutor trainingTutor) { try { await _trainingTutorRepository.AddAsync(trainingTutor); //Added by rodrigo rule 29 NotificationUser nu = new NotificationUser(); nu.NotificationId = 903; nu.UserId = trainingTutor.TutorId; await _notificationUserRepository.AddAsync(nu); await _unitOfWork.CompleteAsync(); return(new TrainingTutorResponse(trainingTutor)); } catch (Exception ex) { return(new TrainingTutorResponse($"An error ocurred while saving the training tutor: {ex.Message}")); } }
public void Update(TrainingTutor trainingTutor) { _context.TrainingTutors.Update(trainingTutor); }
public void Remove(TrainingTutor trainingTutor) { _context.TrainingTutors.Remove(trainingTutor); }
public async Task AddAsync(TrainingTutor trainingTutor) { await _context.TrainingTutors.AddAsync(trainingTutor); }
public async Task <TrainingTutorResponse> UpdateAsync(int trainingId, int tutorId, TrainingTutor trainingTutor) { var existingTrainingTutor = await _trainingTutorRepository.FindByTrainingIdAndTutorId(trainingId, tutorId); if (existingTrainingTutor == null) { return(new TrainingTutorResponse("Training tutor not found")); } existingTrainingTutor.TrainingId = trainingTutor.TrainingId; existingTrainingTutor.TutorId = trainingTutor.TutorId; existingTrainingTutor.Assistance = trainingTutor.Assistance; try { _trainingTutorRepository.Update(existingTrainingTutor); await _unitOfWork.CompleteAsync(); return(new TrainingTutorResponse(existingTrainingTutor)); } catch (Exception ex) { return(new TrainingTutorResponse($"An error ocurred while updating the training tutor: {ex.Message}")); } }