Exemplo n.º 1
0
        public void ReserveSeat_GivenNonExistingUserId_ShouldReturnFalseAndErrorMessage()
        {
            // arrange
            int driveId = 1;
            int userId  = 1;

            Mock <IDbRepository <Drive> > mockRepository = new Mock <IDbRepository <Drive> >();

            mockRepository.Setup(m => m.GetById(It.Is <int>(i => i == driveId)))
            .Returns(new Drive()
            {
                Id = driveId
            });

            Mock <IUsersService> mockUsersService = new Mock <IUsersService>();

            mockUsersService.Setup(m => m.CheckIfUserExists(It.Is <int>(i => i == userId)))
            .Returns(false);

            IDrivesService service = new DrivesService(mockRepository.Object, null, mockUsersService.Object);

            // act
            var result = service.ReserveSeat(driveId, userId);

            // assert
            result.Should().Equals(new KeyValuePair <bool, string>(false, "This user does not exist."));
        }
Exemplo n.º 2
0
        public void ReserveSeat_GivenUserIdWithReservation_ShouldReturnFalseAndErrorMessage()
        {
            // arrange
            int driveId = 1;
            int userId  = 1;

            Mock <IDbRepository <Drive> > mockRepository = new Mock <IDbRepository <Drive> >();

            mockRepository.Setup(m => m.GetById(It.Is <int>(i => i == driveId)))
            .Returns(new Drive()
            {
                Id = driveId,
                DrivesPassengers = new List <DrivesPassengers>()
                {
                    new DrivesPassengers()
                    {
                        DriveId = driveId, PassengerId = userId
                    }
                }
            });

            Mock <IUsersService> mockUsersService = new Mock <IUsersService>();

            mockUsersService.Setup(m => m.CheckIfUserExists(It.Is <int>(i => i == userId)))
            .Returns(true);

            IDrivesService service = new DrivesService(mockRepository.Object, null, mockUsersService.Object);

            // act
            var result = service.ReserveSeat(driveId, userId);

            // assert
            result.Should().Equals(new KeyValuePair <bool, string>(false, "You already have a reservation for the drive."));
        }
Exemplo n.º 3
0
        public void ReserveSeat_GivenValidDriveIdAndValidUserId_ShouldReturnTrueAndSuccessMessage()
        {
            // arrange
            int driveId = 1;
            int userId  = 1;

            Mock <IDbRepository <Drive> > mockRepository = new Mock <IDbRepository <Drive> >();

            mockRepository.Setup(m => m.GetById(It.Is <int>(i => i == driveId)))
            .Returns(new Drive()
            {
                Id               = driveId,
                DeclaredSeats    = 2,
                DrivesPassengers = new List <DrivesPassengers>()
                {
                    new DrivesPassengers()
                }
            });

            Mock <IUsersService> mockUsersService = new Mock <IUsersService>();

            mockUsersService.Setup(m => m.CheckIfUserExists(It.Is <int>(i => i == userId)))
            .Returns(true);

            IDrivesService service = new DrivesService(mockRepository.Object, null, mockUsersService.Object);

            // act
            var result = service.ReserveSeat(driveId, userId);

            // assert
            result.Should().Equals(new KeyValuePair <bool, string>(true, "You made a reservation! Have a safe drive."));
        }