Skip to content

Instantly share code, notes, and snippets.

@stoolrossa
Last active December 19, 2015 03:59
Show Gist options
  • Save stoolrossa/5894100 to your computer and use it in GitHub Desktop.
Save stoolrossa/5894100 to your computer and use it in GitHub Desktop.
// code that's 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;
}
// calculate the tax
total += total * 0.1m;
return total;
}
}
public class Order
{
public string Drink { get; set; }
public int Quantity { get; set; }
}
[TestClass]
public class CheckoutTests
{
[TestMethod]
public void CalculateCostTest()
{
var orders = new List<Order>();
orders.Add(new Order() { Drink = "Little Creatures Pale Ale", Quantity = 2 });
orders.Add(new Order() { Drink = "Pigs Fly Pale Ale", Quantity = 1 });
orders.Add(new Order() { Drink = "Hitachino White Ale", Quantity = 1 });
var checkout = new Checkout();
// Little Creatures Pale Ale - $7
// Pigs Fly Pale Ale - $8
// Hitachino White Ale - $9
Assert.AreEqual(34.10m, checkout.CalculateCost(orders));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment