コード例 #1
0
        public void Initalize()
        {
            _factory = new MockRepository(MockBehavior.Loose);
            _container = new AutoMockContainer(_factory);
            _coins = new List<Coin>();
            _purchaseServiceMock = _container.GetMock<IPurchaseService>();

            var product_a = new Product() { Price = 1, Title = "Apple" };
            var product_b = new Product() { Price = .75m, Title = "Banana" };

            var slot_a = new Slot() { Button = "A", Product = product_a, MaxNumberOfProduct = 5, Quantity = 4 };
            var slot_b = new Slot() { Button = "B", Product = product_b, MaxNumberOfProduct = 5, Quantity = 0 };

            _dollar = new Coin() { Title = "One Dollar", Value = 1, ShortName = "O" };
            _quarter = new Coin() { Title = "Quarter", Value = .25m, ShortName = "Q" };
            _dime = new Coin() { Title = "Dime", Value = .1m, ShortName = "d" };
            _nickle = new Coin() { Title = "Nickle", Value = .05m, ShortName = "n" };
            _penny = new Coin() { Title = "Penny", Value = .01m, ShortName = "p" };

            _slots = new List<Slot>() { slot_a, slot_b };

            _maxSlots = 5;

            _machineService = new MachineService(_maxSlots, _purchaseServiceMock.Object);
        }
コード例 #2
0
 public Product Deliver(Slot slot)
 {
     var retval = new Product();
     if (slot.Quantity > 0)
     {
         slot.Quantity = slot.Quantity - 1;
         retval = slot.Product;
     }
     return retval;
 }
コード例 #3
0
ファイル: MachineService.cs プロジェクト: andrewleaf/CodeKata
 public string CreateSlot(string slotLetter, int maxNumberOfProduct, int numberOfProducts, Product product)
 {
     var msg = "No room to add more products";
     if (_machine.Slots.Count < _machine.MaxSlots)
     {
         var slot = new Slot() {Button = slotLetter, MaxNumberOfProduct = maxNumberOfProduct, Product = product, Quantity = numberOfProducts};
         _machine.Slots.Add(slot);
         msg = string.Format("Your products were added to the slot: {0}", slot.Button);
     }
     return msg;
 }
コード例 #4
0
 public decimal Purchase(Slot slot, ICollection<Coin> coins)
 {
     var totalCoins = coins.Sum(c => c.Value);
     decimal change = 0;
     if (slot.Product.Price <= totalCoins)
     {
         change = totalCoins - slot.Product.Price;
     }
     return change;
 }