Example #1
0
        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);
        }
Example #2
0
        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");
        }
Example #3
0
        public async Task AsyncDeleteWhenSessionReservationNotFound()
        {
            //Arrange
            var mockSessionReservationRepository = GetDefaultISessionReservationRepositoryInstance();
            var mockSessionRepository            = GetDefaultISessionRepositoryInstance();
            var mockStudentRepository            = GetDefaultIStudentRepositoryInstance();
            var mockUnitOfWork = GetDefaultIUnitOfWorkInstance();
            int studentId      = 0;
            int sessionId      = 0;

            var service = new SessionReservationService(mockSessionReservationRepository.Object, mockSessionRepository.Object, mockStudentRepository.Object, mockUnitOfWork.Object);

            // Act
            SessionReservationResponse result = await service.UpdateSessionReservationAsync(studentId, sessionId, new SessionReservation { Confirmed = false, Qualification = 0 });

            var message = result.Message;

            // Assert
            message.Should().Be("SessionReservation not found");
        }
Example #4
0
        public async Task GetByStudentIdAndSessionIdAsyncWhenInvalidIdsReturnsNotFoundResponse()
        {
            //Arrange
            var mockUnitOfWork = GetDefaultIUnitOfWorkInstance();
            var mockSessionReservationRepository = GetDefaultISessionReservationRepositoryInstance();
            var mockSessionRepository            = GetDefaultISessionRepositoryInstance();
            var mockStudentRepository            = GetDefaultIStudentRepositoryInstance();
            int sessionId = 1;
            int studentId = 1;

            mockSessionReservationRepository.Setup(sr => sr.FindByStudentIdAndSessionId(studentId, sessionId))
            .Returns(Task.FromResult <SessionReservation>(null));
            var service = new SessionReservationService(mockSessionReservationRepository.Object, mockSessionRepository.Object, mockStudentRepository.Object, mockUnitOfWork.Object);


            // Act
            SessionReservationResponse result = await service.GetByStudentIdAndSessionId(studentId, sessionId);

            var message = result.Message;

            // Assert
            message.Should().Be("This session reservation is not found");
        }