コード例 #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);
        }
コード例 #2
0
        public void Initialize()
        {
            // Create test data
            _customerId       = _fixture.Create <Id <Customer> >();
            _customerLocation = _fixture.Create <Location>();

            _cab = _fixture.Create <Cab>();
            _trainStationLocation   = _fixture.Create <Location>();
            _currentTime            = _fixture.Create <DateTime>();
            _estimatedTimeOfArrival = _currentTime.AddMinutes(_fixture.Create <int>());

            // Setup stubs
            _locationProvider = Substitute.For <IProvideLocation>();
            _locationProvider.GetTrainStationLocation().Returns(_trainStationLocation);

            _cabProvider = Substitute.For <IProvideCab>();
            _cabProvider.GetNearestAvailableCab(Arg.Any <Location>()).Returns(_cab);

            _timeProvider = Substitute.For <IProvideTime>();
            _timeProvider.GetCurrentTime().Returns(_currentTime);

            _trafficInformationProvider = Substitute.For <IProvideTrafficInformation>();
            _trafficInformationProvider.GetTimeOfArival(Arg.Any <DateTime>(), Arg.Any <Kilometer>()).Returns(_estimatedTimeOfArrival);
            _trafficInformationProvider.GetDistanceBetweenLocations(Arg.Any <Location>(), Arg.Any <Location>()).Returns(_fixture.Create <Kilometer>());

            // Create subject under test
            _sut = new CabRideService(_locationProvider, _cabProvider, _timeProvider, _trafficInformationProvider);
        }
コード例 #3
0
        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);
        }