/// <summary> /// The entry point for a unit test, represents the basic structure of a test-case. /// </summary> /// <remarks> /// This is mostly structural code for the unit tests. /// </remarks> /// <param name="carType">The car type to use</param> /// <param name="age">The age of the car</param> /// <param name="accidents">The number of accidents</param> /// <param name="market">The market to sell on</param> /// <param name="service">(Optional) Specify a service to run against, leaving this blank will create one.</param> /// <returns></returns> private decimal BasicTest( CarType carType, int age = 0, int accidents = 0, CarMarket market = CarMarket.Lot, Improve service = null) { // Construct the advertisement to test var advertisement = new CarAdvertisement() { Type = carType, Age = age, Accidents = accidents, SellingMarket = market }; // If the service wasn't provided, let's provide one. if (service == null) { // Request an instance from the provider. service = InstanceProvider.GetInstance <Improve>(() => new Improve(_auctionService)); } // Run the test case return(service.GetSellingPrice(advertisement)); }
/// <summary> /// Get the selling price of a car based on the advertisement information /// </summary> /// <remarks> /// Given a CarAdvertisement: /// - Type - The car type, determines the base price of the vehicle /// - Age - Determines the depreciation of the vehicle /// - Accidents - Determines the depreciation rate of a vehicle /// - Market - Determines the additional pricing rules based on the market (see below) /// Type: /// - Sedan - Base Price: $15,000 /// - Coupe - Base Price: $13,000 /// - Hatchback - Base Price: $18,000 /// - PickupTruck - Base Price: $25,000 /// Age: /// - See accident to determine rate /// Accidents: /// - 0 Accidents: 5% per year (compounding) /// - 1 Accident: 15% per year (compounding) /// - 2 or More: 25% per year (compounding) /// Market: /// - Lot: No changes /// - Online: Price reduced by $1000 if car's total price is over $5000 /// - Auction: Base price halved + surcharge from the auction service. /// Notes: /// - Values are rounded to the nearest cent on the way out /// </remarks> /// <param name="advertisement"></param> /// <returns></returns> public virtual decimal GetSellingPrice(CarAdvertisement advertisement) { throw new TestUnfinishedException(); if (advertisement != null) { decimal price = 0m; switch (advertisement.Type) { case CarType.Sedan: price = 15000m; break; case CarType.Coupe: price = 1000m; break; case CarType.Hatchback: price = 18000m; break; case CarType.PickupTruck: price = 25000m; break; } switch (advertisement.SellingMarket) { case CarMarket.Lot: price = Accidents(advertisement.Accidents, advertisement.Age, price); break; case CarMarket.Online: price = Accidents(advertisement.Accidents, advertisement.Age, price); if (price > 5000m) { price = price - 1000m; } break; default: price = price / 2m; var surcharge = _auctionService.GetSurcharge(advertisement.Type, advertisement.Accidents); price = price + surcharge; price = Accidents(advertisement.Accidents, advertisement.Age, price); break; } return(Math.Round(price, 2, MidpointRounding.AwayFromZero)); } else { throw new ArgumentNullException(); } }