예제 #1
0
        public async Task <Ride> BringCustomerToTheTrainStation(Id <Customer> customerId, Location customerLocation)
        {
            var currentTime = await _timeProvider.GetCurrentTime();

            // Find a cab
            var cab = await _cabProvider.GetNearestAvailableCab(customerLocation);

            cab.Embarc(customerId);

            // Bring the customer to the trainstation
            var rideId = Id <Ride> .CreateNew();

            var destination = await _locationProvider.GetTrainStationLocation();

            var ride = new Ride(rideId, customerId, cab.Id);

            ride.SetDestination(destination);
            ride.Start(currentTime);

            var distance = await _trafficInformationProvider.GetDistanceBetweenLocations(destination, customerLocation);

            var eta = await _trafficInformationProvider.GetTimeOfArival(currentTime, distance);

            ride.Stop(eta);

            // Update the cab administration
            cab.GoTo(destination);
            await _cabProvider.Update(cab);

            return(ride);
        }
        public async Task WhenNewCab_ShouldPersistCab()
        {
            // Arrange
            var location = _fixture.Create <Location>();
            var cab      = _fixture.Create <Cab>();

            AddRecordsToLookupTable(cab.CurrentLocation, location);

            // Act
            await _sut.Update(cab);

            var itemInDatabase = await _sut.GetNearestAvailableCab(location);

            // Assert
            itemInDatabase.Should().Be(cab);
        }