public void NullBuyProductTest() { Assert.Null(lineSystem.BuyProduct(null, null)); Assert.Null(lineSystem.BuyProduct(new User("test", "test", "test", "*****@*****.**"), null)); Assert.Null(lineSystem.BuyProduct(null, new Product("test", 1337, true))); Assert.NotNull(lineSystem.BuyProduct(new User("test", "test", "test", "*****@*****.**"), new Product("test", 1337, true))); }
private void QuickBuy(string[] inputArray, int inputCount, User user) { Product product; BuyTransaction transaction; int id; if (int.TryParse(inputArray[1], out id)) { product = LineSystem.GetProduct(id); if (product != null && product.Active) { transaction = LineSystem.BuyProduct(user, product); if (LineSystem.ExecuteTransaction(transaction)) { UI.DisplayUserBuysProduct(transaction); } else { UI.DisplayInsufficientCash(user, product); } } else { UI.DisplayProductNotFound(inputArray[1]); } } else { UI.DisplayGeneralError(inputArray[1] + " is not a invalid productID"); } }
private void MultiBuy(string[] inputArray, int inputCount, User user) { List <BuyTransaction> transactions = new List <BuyTransaction>(); Product product; int amount, id, price; if (int.TryParse(inputArray[1], out amount) && amount > 0) { if (int.TryParse(inputArray[2], out id)) { product = LineSystem.GetProduct(id); if (product != null && product.Active) { for (int i = 0; i < amount; i++) { transactions.Add(LineSystem.BuyProduct(user, product)); } price = transactions[0].Amount * amount; if (price <= user.Balance) { foreach (var transaction in transactions) { LineSystem.ExecuteTransaction(transaction); } UI.DisplayUserBuysProduct(transactions[0], amount); } else { UI.DisplayInsufficientCash(user, product, amount); } } else { UI.DisplayProductNotFound(inputArray[2]); } } else { UI.DisplayGeneralError(inputArray[2] + " is not a valid productID"); } } else { UI.DisplayGeneralError(inputArray[1] + " is not a valid amount"); } }