public void CreateRideBooking_ShouldWork() { Booking SampleBooking = BookingTestingData.GetSampleBooking(); User SampleUser = UserTestingData.GetSampleUser(); OfferRide SampleRide = RideOfferTestingData.GetSampleRideOffer(); RideBooking SampleRideRequest = BookingTestingData.GetSampleRideBooking(); using (var mock = AutoMock.GetStrict()) { var TestService = mock.Create <BookingService>(); mock.Mock <IRepositoryManager <Booking> >().Setup(x => x.Post(SampleBooking)); mock.Mock <IMapper>().Setup(x => x.Map <RideBooking, Booking>(SampleRideRequest)).Returns(SampleBooking).Verifiable(); mock.Mock <IRepositoryManager <User> >().Setup(x => x.Get(19)).Returns(SampleUser).Verifiable(); mock.Mock <IRepositoryManager <User> >().Setup(x => x.Put(SampleUser)).Verifiable(); mock.Mock <IRepositoryManager <OfferRide> >().Setup(x => x.Get(5)).Returns(SampleRide).Verifiable(); mock.Mock <IRepositoryManager <OfferRide> >().Setup(x => x.Put(SampleRide)).Verifiable(); TestService.CreateRideBooking(SampleRideRequest); mock.Mock <IRepositoryManager <Booking> >().Verify(x => x.Post(SampleBooking), Times.Exactly(1)); } }
public void CreateRideBooking(RideBooking booking) { Booking rideBooking = _mapper.Map <RideBooking, Booking>(booking); rideBooking.Id = GenerateId(); rideBooking.Status = BookingStatus.Requested; _repository.Post(rideBooking); User user = _userRepository.Get(rideBooking.BookingUserId); if (user != null) { user.LastBookingId = rideBooking.Id; _userRepository.Put(user); } OfferRide RideOffer = _rideOffersRepository.Get(booking.RideOfferId); if (RideOffer != null) { RideOffer.AvailableSeats = RideOffer.AvailableSeats - booking.Seats; _rideOffersRepository.Put(RideOffer); } }
public RideBooking GetSampleRideBooking() { RideBooking rideBooking = new RideBooking() { StartPoint = "Ashoknagar", Destination = "Venkampet", Seats = 4, RideBookingDate = DateTime.Now.Date, Time = "3am-6am", RideFair = 500, RideOfferId = 5, BookingUserId = 19 }; return(rideBooking); }
public void CreateBooking([FromBody] RideBooking booking) { _bookingService.CreateRideBooking(booking); }