Ejemplo n.º 1
0
        public async Task CalculatePriceAsync_WhenRideIsASoloRide_ReturnsTheCorrectPrice()
        {
            decimal distance        = 10;
            decimal calculatedPrice = 100;

            _googleMapsApiService.GetDistanceInKmAsync(Arg.Any <string>(), Arg.Any <string>())
            .ReturnsForAnyArgs(distance);

            _soloRidePriceStrategy.CalculatePrice(distance).Returns(calculatedPrice);
            _priceStrategyFactory.GetPriceStrategy(Arg.Any <RideType>()).Returns(_soloRidePriceStrategy);

            decimal price = await _rideService.CalculatePriceAsync(_anAddress, _anAddress, RideType.SoloRide);

            Assert.That(price, Is.EqualTo(calculatedPrice));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calculates the price of a ride between two addresses.
        /// <remarks>
        /// The algorithm deducts a discount if the ride is shared.<br/>
        /// A solo ride costs the full price.
        /// </remarks>
        /// </summary>
        /// <param name="first">The first address</param>
        /// <param name="second">The second address</param>
        /// <param name="type">The type of the ride</param>
        /// <returns>The price of the ride.</returns>
        public async Task <decimal> CalculatePriceAsync(Address first, Address second, RideType type)
        {
            var distance = await GetDistanceInKilometersAsync(first, second);

            var priceStrategy = _priceStrategyFactory.GetPriceStrategy(type);

            return(priceStrategy.CalculatePrice(distance));
        }