public async Task GetByStudentIdAndSessionIdAsyncWhenValidIdsReturnsASessionReservation() { //Arrange var mockUnitOfWork = GetDefaultIUnitOfWorkInstance(); var mockSessionReservationRepository = GetDefaultISessionReservationRepositoryInstance(); var mockSessionRepository = GetDefaultISessionRepositoryInstance(); var mockStudentRepository = GetDefaultIStudentRepositoryInstance(); int sessionId = 1; int studentId = 1; var sessionReservDTO = new SessionReservation { Confirmed = false, Qualification = 2, StudentId = studentId, SessionId = sessionId }; mockSessionReservationRepository.Setup(sr => sr.FindByStudentIdAndSessionId(studentId, sessionId)) .Returns(Task.FromResult <SessionReservation>(sessionReservDTO)); var service = new SessionReservationService(mockSessionReservationRepository.Object, mockSessionRepository.Object, mockStudentRepository.Object, mockUnitOfWork.Object); // Act SessionReservationResponse result = await service.GetByStudentIdAndSessionId(studentId, sessionId); var sessionReserv = result.Resource; // Assert Assert.AreEqual(sessionReserv, sessionReservDTO); }
public async Task AsyncCreateSessionReservationWhenSessionReservationAlreadyExists() { //Arrange var mockSessionReservationRepository = GetDefaultISessionReservationRepositoryInstance(); var mockSessionRepository = GetDefaultISessionRepositoryInstance(); var mockStudentRepository = GetDefaultIStudentRepositoryInstance(); var mockUnitOfWork = GetDefaultIUnitOfWorkInstance(); var session = new Session { Id = 1, Description = string.Empty, EndDate = DateTime.Now, StartDate = DateTime.Now, Logo = string.Empty, Price = 20, QuantityMembers = 5, Title = "Fisica 1", CategoryId = 1, TutorId = 1, }; var student = new Student { Id = 1, Name = "Josias" }; var sessionReservation = new SessionReservation { Confirmed = false, Qualification = 0, Session = session, SessionId = session.Id, Student = student, StudentId = student.Id, }; mockSessionReservationRepository.Setup(r => r.FindByStudentIdAndSessionId(student.Id, session.Id)).Returns(Task.FromResult <SessionReservation>(sessionReservation)); mockStudentRepository.Setup(r => r.FindById(student.Id)).Returns(Task.FromResult <Student>(student)); mockSessionRepository.Setup(r => r.FindById(session.Id)).Returns(Task.FromResult <Session>(session)); var service = new SessionReservationService(mockSessionReservationRepository.Object, mockSessionRepository.Object, mockStudentRepository.Object, mockUnitOfWork.Object); //Act SessionReservationResponse result = await service.AssignSessionReservationAsync(student.Id, session.Id, sessionReservation); var message = result.Message; // Assert message.Should().Be("This session reservation already exist"); }
public async Task <SessionReservationResponse> UpdateSessionReservationAsync(int studentId, int sessionId, SessionReservation sessionReservation) { var existingSessionReserv = await _sessionResRepository.FindByStudentIdAndSessionId(studentId, sessionId); if (existingSessionReserv == null) { return(new SessionReservationResponse("SessionReservation not found")); } try { existingSessionReserv.Confirmed = sessionReservation.Confirmed; existingSessionReserv.Qualification = sessionReservation.Qualification; _sessionResRepository.Update(existingSessionReserv); await _unitOfWork.CompleteAsync(); return(new SessionReservationResponse(existingSessionReserv)); } catch (Exception e) { return(new SessionReservationResponse($"Ocurrió un error: {e.Message}")); } }
public async Task <SessionReservationResponse> AssignSessionReservationAsync(int studentId, int sessionId, SessionReservation sessionReservation) { var student = await _studentRepository.FindById(studentId); var session = await _sessionRepository.FindById(sessionId); if (student == null || session == null) { return(new SessionReservationResponse("SessionId or StudentId not found")); } var existsIt = await _sessionResRepository.FindByStudentIdAndSessionId(studentId, sessionId); if (existsIt != null) { return(new SessionReservationResponse("This session reservation already exist")); } try { sessionReservation.Session = session; sessionReservation.Student = student; sessionReservation.SessionId = sessionId; sessionReservation.StudentId = studentId; await _sessionResRepository.AddAsync(sessionReservation); await _unitOfWork.CompleteAsync(); return(new SessionReservationResponse(sessionReservation)); } catch (Exception e) { return(new SessionReservationResponse($"Ocurrió un error: {e.Message}")); } }
public void Update(SessionReservation SessionReservation) { _context.SessionReservations.Update(SessionReservation); }
public void Remove(SessionReservation SessionReservation) { _context.SessionReservations.Remove(SessionReservation); }
public async Task AddAsync(SessionReservation SessionReservation) { await _context.SessionReservations.AddAsync(SessionReservation); }
public HomeController(ITSRepository repo, SessionReservation sessionReservation) { repository = repo; sessionRes = sessionReservation; }