Last active
December 19, 2015 03:59
-
-
Save stoolrossa/5894100 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 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