Skip to content

Instantly share code, notes, and snippets.

@stoolrossa
Created June 30, 2013 06:59
Show Gist options
  • Save stoolrossa/5894175 to your computer and use it in GitHub Desktop.
Save stoolrossa/5894175 to your computer and use it in GitHub Desktop.
// 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