Created
June 30, 2013 06:59
-
-
Save stoolrossa/5894175 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 extremely difficult to test | |
public class Checkout | |
{ | |
public decimal CalculateCost(List<Order> orders) | |
{ | |
// get the price list | |
var drinksMenu = getDrinksMenu(); | |
var total = 0.0m; | |
// total the orders | |
foreach(var order in orders) | |
{ | |
total += drinksMenu.LookupPrice(order.Drink) * order.Quantity; | |
} | |
// half price on Friday 5pm-6pm | |
var dateTimeNow = DateTime.Now; | |
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; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment