public void BuySnack_NoSnackAvailable_CannotBuy() { //Arrange var snackMachine = new SnackMachine(); //Act var valid = snackMachine.CanBuySnack(1); //Assert false.Should().Equals(valid); true.Should().Equals(snackMachine.AnyErrors()); Constants.NoSnackAvailableToBuy.Should().Equals(snackMachine.Project()); }
public void BuySnack_Cannot_buy_snack_if_not_enough_change_in_machine() { var snackMachine = new SnackMachine(); snackMachine.LoadSnacks(1, new SnackPile(Snack.None, 1, 0.5m)); snackMachine.InsertMoney(Dollar); var valid = snackMachine.CanBuySnack(1); //Assert false.Should().Equals(valid); true.Should().Equals(snackMachine.AnyErrors()); Constants.NotEnoughChange.Should().Equals(snackMachine.Project()); }
public void BuySnack_Can_buy_snack_if_enough_change_in_machine() { var snackMachine = new SnackMachine(Dollar + Dollar); snackMachine.LoadSnacks(1, new SnackPile(Snack.None, 1, 3m)); snackMachine.InsertMoney(FiveDollar); var valid = snackMachine.CanBuySnack(1); //Assert true.Should().Equals(valid); false.Should().Equals(snackMachine.AnyErrors()); snackMachine.Project().Should().Be(string.Empty); }
private void BuySnack(int position) { var error = _snackMachine.CanBuySnack(position); if (error != string.Empty) { MessageBox.Show(error, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _snackMachine.BuySnack(position); _snackMachineRepository.Save(_snackMachine); SetSnackPiles(); NotifyClient("You have bought a snack"); }
private void BuySnack(string positionString) { int position = int.Parse(positionString); string error = _snackMachine.CanBuySnack(position); if (error != string.Empty) { NotifyClient(error); return; } _snackMachine.BuySnack(position); _repository.Save(_snackMachine); NotifyClient("You have bought a snack"); }
public void BuySnack_Cannot_NotEnoughMoneyInserted_CannotBuy() { //Arrange var snackMachine = new SnackMachine(); snackMachine.LoadSnacks(1, new SnackPile(Snack.None, 1, 2m)); //Action snackMachine.InsertMoney(Dollar); var valid = snackMachine.CanBuySnack(1); //Assert false.Should().Equals(valid); true.Should().Equals(snackMachine.AnyErrors()); Constants.NotEnoughMoneyInserted.Should().Equals(snackMachine.Project()); }
private void BuySnack(string position) { string error = _snackMachine.CanBuySnack(int.Parse(position)); if (!string.IsNullOrEmpty(error)) { NotifyClient(error); } else { _snackMachine.BuySnack(int.Parse(position)); snackMachineRepository.Save(_snackMachine); NotifyClient("You've bought a snack."); } }
private void BuySnack(string positionString) { var position = int.Parse(positionString); var error = _snackMachine.CanBuySnack(position); if (!string.IsNullOrEmpty(error)) { NotifyClient(error); return; } _snackMachine.BuySnack(position); _repository.Save(_snackMachine); NotifyClient("You have bought a snack"); }
private void BuySnack(string positionString) // handling client exception -> could return value and then by value serving client correct one // but it violates CQRS pattern { int position = int.Parse(positionString); string error = _snackMachine.CanBuySnack(position); if (error != string.Empty) { NotifyClient(error); return; } _snackMachine.BuySnack(position); _repository.Save(_snackMachine); //using (ISession session = SessionFactory.OpenSession()) //using (ITransaction transaction = session.BeginTransaction()) //{ // session.SaveOrUpdate(_snackMachine); // transaction.Commit(); //} NotifyClient("You have bought a snack"); }