Created
June 30, 2013 08:34
-
-
Save stoolrossa/5894375 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
// tests with mocked dependencies | |
[TestClass] | |
public class CheckoutTests | |
{ | |
private Mock<IPriceList> drinksMenu; | |
private Mock<IClock> clock; | |
private List<Order> orders; | |
[TestInitialize] | |
public void Setup() | |
{ | |
// create mock price list | |
this.drinksMenu = new Mock<IPriceList>(); | |
// setup lookup method for three drinks | |
drinksMenu.Setup(dm => dm.LookupPrice("Little Creatures Pale Ale")).Returns(7); | |
drinksMenu.Setup(dm => dm.LookupPrice("Pigs Fly Pale Ale")).Returns(8); | |
drinksMenu.Setup(dm => dm.LookupPrice("Hitachino White Ale")).Returns(9); | |
// create mock clock | |
this.clock = new Mock<IClock>(); | |
// create the list of orders | |
this.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 }); | |
} | |
[TestMethod] | |
public void CalculateCostNormalTest() | |
{ | |
// setup clock to be 6:26pm on Sunday 30th of the June 2013 | |
this.clock.Setup(c => c.GetDateTimeNow()).Returns(new DateTime(2013, 06, 30, 18, 26, 00)); | |
var checkout = new Checkout(this.drinksMenu.Object, this.clock.Object); | |
Assert.AreEqual(34.10m, checkout.CalculateCost(this.orders)); | |
} | |
[TestMethod] | |
public void CalculateCostHappyHourTest() | |
{ | |
// setup clock to be 5:13pm on Friday 28th of the June 2013 | |
this.clock.Setup(c => c.GetDateTimeNow()).Returns(new DateTime(2013, 06, 28, 17, 13, 00)); | |
var checkout = new Checkout(this.drinksMenu.Object, this.clock.Object); | |
Assert.AreEqual(17.05m, checkout.CalculateCost(this.orders)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment