Пример #1
0
        public void ShouldCreateBookingByCabType()
        {
            var pickupLocation       = new GeoCoordinate(12.99711, 77.61469);
            var bookingRepo          = new Mock <IBookingRepository>();
            var availableCabsService = new Mock <IAvailableCabsService>();
            var availableCab         = new Domain.Cab("3", "Toyota Etios", CabType.Pink);

            availableCabsService.Setup(a => a.GetNearestCab(pickupLocation, new[] { CabType.Pink })).Returns(availableCab);

            var bookingService       = new BookingService(bookingRepo.Object, availableCabsService.Object);
            var createBookingRequest = new CreateBookingRequest()
            {
                PickupLocation = pickupLocation,
                Destination    = new GeoCoordinate(13, 77),
                Time           = DateTime.Now,
                UserId         = "1",
                CabType        = "Pink"
            };
            var booking = bookingService.CreateBooking(createBookingRequest);

            Assert.That(booking != null);
            Assert.That(booking.CabId == availableCab.Id);
            Assert.That(booking.UserId == createBookingRequest.UserId);
            Assert.That(booking.PickupLocation.Equals(createBookingRequest.PickupLocation));
            Assert.That(booking.Destination.Equals(createBookingRequest.Destination));
            Assert.That(booking.Time.Equals(createBookingRequest.Time));

            availableCabsService.Verify(a => a.GetNearestCab(createBookingRequest.PickupLocation, new[] { CabType.Pink }));
            bookingRepo.Verify(b => b.Save(booking));
        }
Пример #2
0
        public void ShouldReturnCabToPoolIfCreateBookingFails()
        {
            var pickupLocation = new GeoCoordinate(12.99711, 77.61469);
            var bookingRepo    = new Mock <IBookingRepository>();

            bookingRepo.Setup(b => b.Save(It.IsAny <Domain.Booking>())).Throws <Exception>();
            var availableCabsService = new Mock <IAvailableCabsService>();
            var availableCab         = new Domain.Cab("3", "Toyota Etios", CabType.Pink);

            availableCabsService.Setup(a => a.GetNearestCab(pickupLocation, new CabType[] { CabType.Regular, CabType.Pink })).Returns(availableCab);

            var bookingService       = new BookingService(bookingRepo.Object, availableCabsService.Object);
            var createBookingRequest = new CreateBookingRequest()
            {
                PickupLocation = pickupLocation,
                Destination    = new GeoCoordinate(13, 77),
                Time           = DateTime.Now,
                UserId         = "1"
            };

            Assert.Throws <Exception>(() => bookingService.CreateBooking(createBookingRequest));

            availableCabsService.Verify(a => a.GetNearestCab(createBookingRequest.PickupLocation, new CabType[] { CabType.Regular, CabType.Pink }));
            availableCabsService.Verify(a => a.ReturnCabToPool(availableCab));
        }
Пример #3
0
        public void ReturnCabToPoolShouldCallAddCabToPool()
        {
            var cab = new Domain.Cab("1", "Toyota", CabType.Regular);
            var cabLocationService = new Mock <ICabLocationService>();
            var availableCabsRepo  = new Mock <IAvailableCabsRepository>();

            var availableCabsService = new AvailableCabsService(cabLocationService.Object, availableCabsRepo.Object);

            availableCabsService.ReturnCabToPool(cab);

            availableCabsRepo.Verify(a => a.AddCabToPool(cab));
        }
Пример #4
0
 public void RemoveCabFromPool(Domain.Cab cab)
 {
     AvailableCabs.Remove(cab);
 }
Пример #5
0
 public void AddCabToPool(Domain.Cab cab)
 {
     AvailableCabs.Add(cab);
 }
Пример #6
0
 public void ReturnCabToPool(Domain.Cab cab)
 {
     AvailableCabsRepository.AddCabToPool(cab);
 }