Last active
December 19, 2015 03:59
-
-
Save stoolrossa/5894325 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// code that's testable | |
public class Checkout | |
{ | |
private IPriceList drinksMenu; | |
private IClock clock; | |
public Checkout(IPriceList drinksMenu, IClock clock) | |
{ | |
this.drinksMenu = drinksMenu; | |
this.clock = clock; | |
} | |
public decimal CalculateCost(List<Order> orders) | |
{ | |
var total = 0.0m; | |
// total the orders | |
foreach(var order in orders) | |
{ | |
total += this.drinksMenu.LookupPrice(order.Drink) * order.Quantity; | |
} | |
// half price on Friday 5pm-6pm | |
var dateTimeNow = this.clock.GetDateTimeNow(); | |
if (dateTimeNow.DayOfWeek == DayOfWeek.Friday && dateTimeNow.Hour == 17) | |
{ | |
total /= 2; | |
} | |
// calculate the tax | |
total += total * 0.1m; | |
return total; | |
} | |
} | |
public class Order | |
{ | |
public string Drink { get; set; } | |
public int Quantity { get; set; } | |
} | |
public interface IPriceList | |
{ | |
decimal LookupPrice(string itemName); | |
} | |
public interface IClock | |
{ | |
DateTime GetDateTimeNow(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment