public IScreen HandleInput(string input) { if (input == "q") { dataBus.Remove(Constants.DataKeys.SelectedProduct); } else { int quantity = -1; if (!int.TryParse(input, out quantity) || quantity < 1) { throw new InvalidInputException("Invalid quantity"); } User currentUser = dataBus.GetData <User>(Constants.DataKeys.User) .Assert(() => new InvalidOperationException("Select user")); transactionsFacade.Buy(currentUser.Name, _product.Id, quantity); dataBus.SetData(Constants.DataKeys.User, usersRepository.GetByName(currentUser.Name)); } return(mainScreen.Value); }
public void WrongQuantityValue() { Assert.Throws(typeof(InvalidOperationException), () => facade.Buy("Jerry", 1, -5)); Assert.Throws(typeof(InvalidOperationException), () => facade.Buy("Jerry", 1, 0)); }