public void BuySomeDrinksBeforeGetChange() { Init(); { Drink1.CostPrice = 2; Drink1.Count = 3; } { Drink2.CostPrice = 3; Drink2.Count = 5; } { } VengineMachine.AddCoin(Coin2, CurrentState); VengineMachine.AddCoin(Coin2, CurrentState); VengineMachine.BuyDrink(Drink1, CurrentState, CoinEntitiesList); Assert.AreEqual(2, CurrentState.Change); VengineMachine.AddCoin(Coin2, CurrentState); VengineMachine.AddCoin(Coin1, CurrentState); VengineMachine.AddCoin(Coin1, CurrentState); VengineMachine.BuyDrink(Drink2, CurrentState, CoinEntitiesList); Assert.AreEqual(3, CurrentState.Change); Assert.AreEqual(2, Drink1.Count); Assert.AreEqual(4, Drink2.Count); }
public DrinkOperationInfo BuyDrink(Guid id) { DrinkEntity drink = _drinkRepository.Get(id); CurrentStateEntity currentState = _stateRepository.GetFirst(); _logger.Info(" before buy drink"); _printer.DrinkAndStateInfo(drink, currentState); bool success = true; var msg = ""; if (!_vengineMachine.BuyDrink(drink, currentState, _coinRepository.Queryable().ToList())) { success = false; msg = " Невозможно совершить покупку! В автомате нет сдачи! Деньги возвращены полностью в качестве сдачи"; _logger.Warning(msg); } _logger.Info(" after buy drink"); _printer.DrinkAndStateInfo(drink, currentState); _logger.Info(" before _db.SaveChanges()..."); _drinkRepository.SaveChanges(); return(new DrinkOperationInfo { Drink = drink, Change = currentState.Change, Success = success, Msg = msg }); }
public void BuyDrink() { Init(); CurrentState.Deposit = 15; VengineMachine.BuyDrink(Drink1, CurrentState, CoinEntitiesList); Assert.AreEqual(1, Drink1.Count); Assert.AreEqual(5, CurrentState.Change); }