using System; using NUnit.Framework; using Rhino.Mocks; namespace ChrisDonnan.DevSession.Tdd.Tests { [TestFixture] public class BigFatGuyTests { [Test] public void CanOrder() { ///setup mocks MockRepository mocks = new MockRepository(); IPizzaShop pizzeShop = mocks.DynamicMock(); /// set dependencies PizzaOrder order = new PizzaOrder(); order.Pizzas.Add(new PizzaSpecification(3)); const double cost = 9.99*3; const int timeToDeliver = 30; /// set expectations Expect.Call(pizzeShop.AcceptOrder(order)).Return(new PizzaExpectation(timeToDeliver, cost)); mocks.ReplayAll(); /// instantiate CUT BigFatGuy hungryGuy = new BigFatGuy(pizzeShop); /// Give CUT depends/ call MUT PizzaExpectation myOrder = hungryGuy.OrderPizza(order); Assert.AreEqual(myOrder.Cost, cost); Assert.AreEqual(myOrder.MinutesToDelivery, timeToDeliver); mocks.VerifyAll(); } [Test] public void CanEat() { ///setup mocks MockRepository mocks = new MockRepository(); IPizzaShop pizzeShop = mocks.DynamicMock(); /// set dependencies PizzaOrder order = new PizzaOrder(); order.Pizzas.Add(new PizzaSpecification(3)); const double cost = 9.99 * 3; const int timeToDeliver = 30; /// set expectations Expect.Call(pizzeShop.AcceptOrder(order)).Return(new PizzaExpectation(timeToDeliver, cost)); mocks.ReplayAll(); /// instantiate CUT BigFatGuy hungryGuy = new BigFatGuy(pizzeShop); /// Give CUT depends PizzaExpectation myOrder = hungryGuy.OrderPizza(order); ///call MUT SatisfactionLevel satisfaction = hungryGuy.Eat(); Assert.AreEqual(myOrder.Cost, cost); Assert.AreEqual(myOrder.MinutesToDelivery, timeToDeliver); Assert.AreEqual(satisfaction, SatisfactionLevel.Somewhat); mocks.VerifyAll(); } [Test] [ExpectedException(typeof(Exception), "NO FOOD!")] public void CantEat() { ///setup mocks MockRepository mocks = new MockRepository(); IPizzaShop pizzeShop = mocks.DynamicMock(); /// set dependencies PizzaOrder order = new PizzaOrder(); order.Pizzas.Add(new PizzaSpecification(3)); const double cost = 9.99 * 3; const int timeToDeliver = 30; /// set expectations Expect.Call(pizzeShop.AcceptOrder(order)).Return(new PizzaExpectation(timeToDeliver, cost)); mocks.ReplayAll(); /// instantiate CUT BigFatGuy hungryGuy = new BigFatGuy(pizzeShop); ///call MUT hungryGuy.Eat(); mocks.VerifyAll(); } } }