public CommandParser(LineSystem lineSystem, ILineSystemUI ui) { LineSystem = lineSystem; UI = ui; adminCommands.Add(":close", args => UI.Close()); adminCommands.Add(":activate", args => { ChangeProductBoolField(":activate", args, ProductBoolField.Active, true); }); adminCommands.Add(":deactivate", args => { ChangeProductBoolField(":deactivate", args, ProductBoolField.Active, false); }); adminCommands.Add(":crediton", args => { ChangeProductBoolField(":crediton", args, ProductBoolField.CanBeBoughtOnCredit, true); }); adminCommands.Add(":creditoff", args => { ChangeProductBoolField(":creditoff", args, ProductBoolField.CanBeBoughtOnCredit, false); }); adminCommands.Add(":addcredits", args => { InsertCashTransaction transaction; User user; int amount; if (IsValidArgs(":addcredits", args, 2)) { user = LineSystem.GetUser(args[0]); if (user != null) { if (args[1].TryToCredit(out amount)) { transaction = LineSystem.AddCreditsToAccount(user, amount); UI.DisplayAdminAddedCredits(transaction); LineSystem.ExecuteTransaction(transaction); } else { UI.DisplayGeneralError(args[1] + " is not a invalid cash amount"); } } else { UI.DisplayUserNotFound(args[0]); } } }); }
public void NullAddCreditsToAccount() { Assert.Null(lineSystem.AddCreditsToAccount(null, 200)); Assert.NotNull(lineSystem.AddCreditsToAccount(testUser, 200)); }