public void CancelReservation_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 = 1, 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.CancelReservation(driveId, userId); // assert result.Should().Equals(new KeyValuePair <bool, string>(true, "Your registration has been canceled.")); }
public void CancelReservation_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.CancelReservation(driveId, userId); // assert result.Should().Equals(new KeyValuePair <bool, string>(false, "This user does not exist.")); }