public void CanCreateJsonDal() { // Arrange JsonFileAccessLayer fal = new JsonFileAccessLayer("C:\\testAcct.act"); HumanAcccountHolder hah = new HumanAcccountHolder("TestUser", "TestPass", new string[] { "Test", "McTester" }); Account act = new Account(hah, 0d, 0d, new Currency(1d, "fakemonies", '!')); // Act fal.SaveAccount(act); }
static void Main(string[] args) { IDataAccessLayer dal = new JsonFileAccessLayer("C:\\testingAccount.bank"); //CreateTestAccounts(dal); AccountHolder ach = DemandAuthentication(dal); Command userCommand = null; while (userCommand == null || userCommand.Inquiry != TransactionTypes.Quit) { string amount = ""; string direction = ""; userCommand = PromptUser("Please select one of the following commands:", ach.AvailableCommands); if (userCommand != null && userCommand.Inquiry != TransactionTypes.Quit) { Account chosen = null; if (RequireCountAndDirection.Contains(userCommand.Inquiry)) { Command takeOneAcount = new Command(string.Format("return only 1 account."), TransactionTypes.ListAccounts); Command takeFiveAccounts = new Command(string.Format("return 5 accounts."), TransactionTypes.ListAccounts); List<Command> howManyAccounts = new List<Command>() { takeOneAcount, takeFiveAccounts }; Command oneOrFive = PromptUser("How many accounts would you like to list?", howManyAccounts); amount = oneOrFive == takeOneAcount ? "1" : "5"; Command takeTopAccounts = new Command(string.Format("view the top {0} account(s).", amount), TransactionTypes.ListAccounts); Command takeBottomAccounts = new Command(string.Format("view the bottom {0} account(s).", amount), TransactionTypes.ListAccounts); List<Command> possibleInquiries = new List<Command>() { takeTopAccounts, takeBottomAccounts }; Command topOrBottom = PromptUser("Which accounts would you like?", possibleInquiries); userCommand = topOrBottom; direction = userCommand == takeTopAccounts ? "desc" : "asc"; } if (RequireAccount.Contains(userCommand.Inquiry)) { chosen = ChooseTargetAccount(dal.LoadAccountsForUser(ach.Id)); } if (userCommand.Inquiry == TransactionTypes.GetAccountAtDate) { chosen = ChooseTargetAccount(dal.GetAllAcccounts()); } if (userCommand.Inquiry == TransactionTypes.ChangeCurrency) { Command useDollars = new Command(string.Format("view currency in {0}.", AvailableCurrencies.CurrencyList[0].Name), TransactionTypes.ListAccounts); Command useEuros = new Command(string.Format("view currency in {0}", AvailableCurrencies.CurrencyList[1].Name), TransactionTypes.ListAccounts); List<Command> possibleCurrencies = new List<Command>() { useDollars, useEuros }; Command dOrE = PromptUser("Please choose a currency: ", possibleCurrencies); if (dOrE == useEuros) amount = AvailableCurrencies.CurrencyList[1].Name; else amount = AvailableCurrencies.CurrencyList[0].Name; } if (RequireMoney.Contains(userCommand.Inquiry)) { Console.WriteLine("Please enter the amount."); amount = Console.ReadLine(); } if (userCommand.Inquiry == TransactionTypes.GetAccountAtDate) { Console.WriteLine("Please enter a date to view account balance for."); amount = Console.ReadLine(); } InquiryResult result = ach.PerformInquiry(chosen, userCommand, dal, amount, direction); foreach (string s in result.Response) Console.WriteLine(s); if (chosen != null) dal.SaveAccount(chosen); } } // Say goodbye to the user. Console.WriteLine("Goodbye {0}!, press enter to conclude your session.", ach.DisplayName); Console.ReadLine(); }