private static void InsertCassette(string path, CashMachine atm) { var reader = ReaderSelector.Select(path); if (reader == null) { Console.WriteLine(ConsoleLanguagePack.FormatIsntDetected); return; } try { atm.InsertCassettes(reader.Read(path)); } catch (FileNotFoundException) { Console.WriteLine(ConsoleLanguagePack.FileNotFound); return; } catch (SerializationException) { Console.WriteLine(ConsoleLanguagePack.FileCantBeRead); return; } Console.WriteLine(ConsoleLanguagePack.ReadSuccessfully); }
public void LogsToConsoleAndFile() { // ARRANGE using var writer = new StringWriter(); Console.SetOut(writer); Action <string> logger = LogToConsole; logger += LogToFile; var cashMachine = new CashMachine(logger); const string Pin = "1234"; cashMachine.VerifyPin(Pin); cashMachine.ShowBalance(); writer.Flush();// Ensure writer is flushed // ASSERT var expectedOutput = $"VerifyPin called: PIN={Pin}ShowBalance called: Balance=999"; var actualConsole = writer.ToString(); Assert.AreEqual(expectedOutput, actualConsole); var fileText = File.ReadAllText(OutputFile); Assert.AreEqual(expectedOutput, fileText); }
public static string WithdrawMethod(CashMachine machine, Person person, int money) { if (person.Purse.Money >= money) { if (machine.Money >= money) { person.Purse.Money -= money; machine.Money -= money; using (BankContext context = new BankContext()) { context.Purses.Find(person.PurseId).Money -= money; context.CashMachines.Find(machine.Id).Money -= money; History history = new History(); history.CashMachine = machine; history.Person = person; history.Money = money; history.Time = DateTime.Now; context.Histories.Add(history); context.SaveChanges(); } return("Транзакция успешно завершена"); } else { return("К сожалению в банкомате не достаточно средств"); } } else { return("К сожалению у вас не достаточно средств"); } }
public static string AddMoneyMethod(CashMachine machine, Person person, int money) { try { person.Purse.Money += money; using (BankContext context = new BankContext()) { context.Purses.Find(person.PurseId).Money += money; context.CashMachines.Find(machine.Id).Money += money; History history = new History(); history.CashMachine = machine; history.Person = person; history.Money = money; history.Time = DateTime.Now; context.Histories.Add(history); context.SaveChanges(); } return("Транзакция успешно завершена"); } catch { return("Во время транзакции возникла ошибка"); } }
public void TestSuccessiveSameAdds() { CashMachine atm = new CashMachine(); // Add a 500 atm.AddCash(500, 1); Dictionary <Int32, Int32> remainingCash = new Dictionary <Int32, Int32> { { 500, 1 }, { 200, 0 }, { 100, 0 }, { 50, 0 }, { 20, 0 }, { 10, 0 }, { 5, 0 } }; Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding one 500 to an empty machine should change the remaining cash accordingly" ); // Add two 500 atm.AddCash(500, 2); remainingCash[500] = 3; Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding two 500 to a one 500 machine should change the remaining cash accordingly" ); // Add ten 500 atm.AddCash(500, 10); remainingCash[500] = 13; Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding ten 500 to a three 500 machine should change the remaining cash accordingly" ); }
static void Main(string[] args) { var moneyReceived = new CashMachine(20, new Dollar()); var result = moneyReceived.Calculate(); Console.WriteLine(result); }
public void TestMultipleBillWithdraw() { CashMachine atm = new CashMachine(); atm.AddCash(500, 10); atm.AddCash(200, 10); atm.AddCash(100, 10); atm.AddCash(50, 10); atm.AddCash(20, 10); atm.AddCash(10, 10); atm.AddCash(5, 10); Dictionary <Int32, Int32> withdrawedCash = new Dictionary <Int32, Int32> { { 500, 1 }, { 200, 1 }, { 100, 1 }, { 50, 1 }, { 20, 2 }, { 5, 1 } }; Assert.AreEqual(withdrawedCash, atm.Withdraw(895), "Withdraw 895 should get you one of each 500/200/100/50/5 and two 20 if the machine have enough" ); Dictionary <Int32, Int32> remainingCash = new Dictionary <Int32, Int32> { { 500, 9 }, { 200, 9 }, { 100, 9 }, { 50, 9 }, { 20, 8 }, { 10, 10 }, { 5, 9 } }; Assert.AreEqual(remainingCash, atm.RemainingCash, "Withdrawing 895 from a machine with ten of each bill should change the machine accordingly" ); }
public void SetUp() { var bankAccountRepository = new BankAccountRepository(); var clock = new Clock(); _newAccountCreator = new NewAccountCreator(bankAccountRepository, clock); _accountRetriever = new AccountRetriever(); _cashMachine = new CashMachine(bankAccountRepository); }
public boolean GimmehMoniez(int howMuch) { try { CashMachine.eject(howMuch); //I don't know what methods your driver exposes... return(true); } catch (CashMachineException cme) { return(false); } }
public void SetUp() { var bankAccountRepository = new BankAccountRepository(); var clock = new Clock(); _newAccountCreator = new NewAccountCreator(bankAccountRepository, clock); _accountRetriever = new AccountRetriever(); _cashMachine = new CashMachine(bankAccountRepository); _customerServiceRepresentative = new CustomerServiceRepresentative(bankAccountRepository, clock); }
public void Withdraw_WithValidAmount_UpdatesBalance() { var machine = new CashMachine(); machine.Withdraw(208); Assert.AreEqual(machine.CurrentBalance[100], 8); Assert.AreEqual(machine.CurrentBalance[5], 9); Assert.AreEqual(machine.CurrentBalance[1], 7); }
public void TestEmpty() { CashMachine atm = new CashMachine(); Dictionary <Int32, Int32> remainingCash = new Dictionary <Int32, Int32> { { 500, 0 }, { 200, 0 }, { 100, 0 }, { 50, 0 }, { 20, 0 }, { 10, 0 }, { 5, 0 } }; Assert.AreEqual(remainingCash, atm.RemainingCash, "A new CashMachine should have 0 of every possible bills"); }
private static void Main() { XmlConfigurator.Configure(); Log.Debug("start"); ILanguage languagePack = new LanguagePack("en-US"); //ILanguage languagePack = new LanguagePack("ru-RU"); Dictionary <AtmState, string> statesDictionary = new Dictionary <AtmState, string>() { { AtmState.Ok, languagePack.Ok }, { AtmState.NotEnoughMoney, languagePack.NotEnoughMoney }, { AtmState.ImpossibleToCollectMoney, languagePack.ImpossibleToCollectMoney }, { AtmState.TooManyBanknotes, languagePack.TooManyBanknotes } }; _atm = CashMachine.Deserialize(ConfigurationManager.AppSettings["SerializationFile"]) ?? new CashMachine(); CommandPerformer commandPerformer = new CommandPerformer(ref _atm, ref languagePack); commandPerformer.TryPerform("help"); while (true) { Console.WriteLine("\n" + _atm.TotalMoney); var readLine = Console.ReadLine(); decimal requestedSum; if (decimal.TryParse(readLine, out requestedSum) && requestedSum > decimal.Zero) { var money = _atm.WithdrawMoney(requestedSum); switch (_atm.CurrentState) { case AtmState.Ok: { Console.WriteLine(MoneyConverter.ConvertToString(money)); break; } default: Console.WriteLine(statesDictionary[_atm.CurrentState]); break; } continue; } bool isCommand = readLine != null && commandPerformer.TryPerform(readLine.Trim().ToLower()); if (!isCommand) { Console.WriteLine(languagePack.WrongInput); } } }
public void DisplayDenominations_ReturnsCorrectDenominations() { var machine = new CashMachine(); machine.Withdraw(123); var denominations = machine.DisplayDenominations(100, 20, 1); Assert.AreEqual(denominations[100], 9); Assert.AreEqual(denominations[20], 9); Assert.AreEqual(denominations[1], 7); }
public void Withdraw_WithNegativeAmount_DoesntUpdateBalance() { var machine = new CashMachine(); machine.Withdraw(-100); Assert.AreEqual(machine.CurrentBalance[100], 10); Assert.AreEqual(machine.CurrentBalance[50], 10); Assert.AreEqual(machine.CurrentBalance[20], 10); Assert.AreEqual(machine.CurrentBalance[10], 10); Assert.AreEqual(machine.CurrentBalance[5], 10); Assert.AreEqual(machine.CurrentBalance[1], 10); }
public void TestAddZero() { CashMachine atm = new CashMachine(); atm.AddCash(200, 0); Dictionary <Int32, Int32> remainingCash = new Dictionary <Int32, Int32> { { 500, 0 }, { 200, 0 }, { 100, 0 }, { 50, 0 }, { 20, 0 }, { 10, 0 }, { 5, 0 } }; Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding 0 of an existing bill should let the CashMachine unchanged"); }
private bool ValidateMoney(decimal value, ref CashMachine cashMachine) { bool result; if (value % 50 == 0) { cashMachine.Balance -= (long)value; cashMachine.Fifty -= (int)(value / 50); result = true; } else if (value % 50 > 0 && (value % 50) % 20 == 0) { cashMachine.Balance -= (long)value; cashMachine.Fifty -= (int)(value / 50); cashMachine.Twenty -= (int)((value % 50) / 20); result = true; } else if ((value % 50) % 20 > 0 && ((value % 50) % 20) % 10 == 0) { cashMachine.Balance -= (long)value; cashMachine.Fifty = cashMachine.Fifty - (int)(value / 50); cashMachine.Twenty = cashMachine.Twenty - (int)((value % 50) / 20); cashMachine.Ten = cashMachine.Ten - (int)(((value % 50) % 20) / 10); result = true; } else if (((value % 50) % 20) % 10 > 0 && (((value % 50) % 20) % 10) % 5 == 0) { cashMachine.Balance -= (long)value; cashMachine.Fifty = cashMachine.Fifty - (int)(value / 50); cashMachine.Twenty = cashMachine.Twenty - (int)((value % 50) / 20); cashMachine.Ten = cashMachine.Ten - (int)(((value % 50) % 20) / 10); cashMachine.Five = cashMachine.Five - (int)((((value % 50) % 20) % 10) / 5); result = true; } else if ((((value % 50) % 20) % 10) % 5 > 0 && ((((value % 50) % 20) % 10) % 5) % 2 == 0) { cashMachine.Balance -= (long)value; cashMachine.Fifty -= (int)(value / 50); cashMachine.Twenty -= (int)((value % 50) / 20); cashMachine.Ten -= (int)(((value % 50) % 20) / 10); cashMachine.Five -= (int)((((value % 50) % 20) % 10) / 5); cashMachine.Two -= (int)(((((value % 50) % 20) % 10) % 5) / 2); result = true; } else { result = false; } return(result); }
private static void Main() { XmlConfigurator.Configure(); Log.Info("start"); try { _signalHandler += HandleConsoleSignal; ConsoleHelper.SetSignalHandler(_signalHandler, true); var errors = Configurator.Config(); _atm = CashMachine.Deserialize(ConfigurationManager.AppSettings["SerializationAtm"]) ?? new CashMachine(new GreedyAlgorithm()); _statistics = Statistics.Statistics.Deserialize(ConfigurationManager.AppSettings["SerializationStatistics"]) ?? new Statistics.Statistics(); AtmEvent.InsertCassettesEvent += _statistics.InsertCassettes; AtmEvent.WithdrawMoneyEvent += _statistics.WithdrawMoney; AtmEvent.RemoveCassettesEvent += _statistics.RemoveCassettes; var commandPerfomer = new Commands.CommandPerfomer(_atm, errors, _statistics); Console.WriteLine(ConsoleLanguagePack.MainMessage); while (true) { var input = Console.ReadLine(); Log.Debug(input); if (string.IsNullOrEmpty(input)) { continue; } if (ConsoleLanguagePack.ExitFlags.Contains(input)) { break; } if (!commandPerfomer.TryPerform(input)) { Console.WriteLine(ConsoleLanguagePack.CommandNotFound); } } _atm.Serialize(ConfigurationManager.AppSettings["SerializationAtm"]); _statistics.Serialize(ConfigurationManager.AppSettings["SerializationStatistics"]); } catch (Exception ex) { Log.Fatal(ex); } Log.Info("end"); }
public CommandPerformer(ref CashMachine atm, ref ILanguage lang) { _atm = atm; _lang = lang; _commandsDictionary = new Dictionary <string, Action> { { "help", Help }, { "insert", InsertCassettes }, { "exit", Exit }, { "delete", DeleteCassettes }, { "clear", Clear } }; }
public void Restock_ResetsBalance() { var machine = new CashMachine(); machine.Withdraw(123); machine.Restock(); Assert.AreEqual(machine.CurrentBalance[100], 10); Assert.AreEqual(machine.CurrentBalance[50], 10); Assert.AreEqual(machine.CurrentBalance[20], 10); Assert.AreEqual(machine.CurrentBalance[10], 10); Assert.AreEqual(machine.CurrentBalance[5], 10); Assert.AreEqual(machine.CurrentBalance[1], 10); }
public void TestSuccessiveDifferentAdds() { CashMachine atm = new CashMachine(); // Add a 200 atm.AddCash(200, 1); Dictionary <Int32, Int32> remainingCash = new Dictionary <Int32, Int32> { { 500, 0 }, { 200, 1 }, { 100, 0 }, { 50, 0 }, { 20, 0 }, { 10, 0 }, { 5, 0 } }; Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding one 200 to an empty machine should change the remaining cash accordingly" ); // Add a 100 atm.AddCash(100, 1); remainingCash[100] = 1; Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding one 100 to a one 200 machine should change the remaining cash accordingly" ); // Add a 50 atm.AddCash(50, 1); remainingCash[50] = 1; Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding one 50 to a one 200/100 machine should change the remaining cash accordingly" ); // Add a 20 atm.AddCash(20, 1); remainingCash[20] = 1; Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding one 20 to a one 200/100/50 machine should change the remaining cash accordingly" ); // Add a 10 atm.AddCash(10, 1); remainingCash[10] = 1; Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding one 10 to a one 200/100/50/20 machine should change the remaining cash accordingly" ); // Add a 5 atm.AddCash(5, 1); remainingCash[5] = 1; Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding one 5 to a one 200/100/50/20/10 machine should change the remaining cash accordingly" ); }
/*public async Task<CashMachineViewModel> SaqueService(SaqueViewModel saqueViewModel, Guid id) * { * bool cashMachineIsValid, moneyIsValid; * * var saqueModel = _mapper.Map<SaqueViewModel, Saque>(saqueViewModel); * * var cashMachineData = await _cashMachineRepository.GetCashMachinesById(id); * //await _caixasRepository.CaixasAsync(saqueDomain.IdCaixa, _correlationId); * * cashMachineIsValid = ValidateCashMachine(cashMachineData, saqueModel); * * moneyIsValid = ValidateMoney(saqueModel.Value, ref cashMachineData); * * if (cashMachineIsValid && moneyIsValid) * { * var caixaComSaque = await _saquesRepository.SaqueAsync(saqueDomain, caixa, _correlationId); * * await _produtoService.Atualizar(_mapper.Map<Produto>(produtoAtualizacao)); * * result = _mapper.Map<Caixa, CaixaViewModel>(caixaComSaque); * } * * * return result; * }*/ private bool ValidateCashMachine(CashMachine cashMachineData, Saque saqueModel) { bool returnStatus; if (cashMachineData.Status == 1 && cashMachineData.Balance > saqueModel.Value) { returnStatus = true; } else { returnStatus = false; } return(returnStatus); }
static void Main(string[] args) { //double[] notas = {100, 50, 20, 10, 5, 2}; //lista organizada double[] moneyBill = { 2, 5, 10, 20, 50, 100 }; //lista desorganizada CashMachine cashMachine = new CashMachine(); cashMachine.SortMoneyBill(moneyBill); cashMachine.MoneyDraft(moneyBill, 11); //testando notas de maior valor cashMachine.MoneyDraft(moneyBill, 11.5); //testando decimais cashMachine.MoneyDraft(moneyBill, 6); //testando MoneyDraft impossível Console.WriteLine("Press enter to exit..."); Console.ReadLine(); }
public MainForm() { InitializeComponent(); //Путь по умолчанию к файлу с кассетами _path = @"D:\Visual Studio\OOP\ATM\bin\Debug\data.json"; _cashMachine = new CashMachine(_path); _lang = new LanguageConfig(_cashMachine.CurrentCulture); LoadLang(); _statsCounter = new StatsCounter(); XmlConfigurator.Configure(); //Вывод текущего состояния счёта DisplayPrintln(_lang.Status + ":"); DisplayPrintln(_cashMachine.Status() + '\n'); }
public MainWindow() { InitializeComponent(); using (BankContext context = new BankContext()) { context.CashMachines.ToList(); CashMachine cashMachine = new CashMachine(); cashMachine.Money = 10000000; cashMachine.Addres = "Московская 25"; context.CashMachines.Add(cashMachine); context.SaveChanges(); } this.Content = new SigInPage(this); }
static void Main(string[] args) { // Load bank with client base. BankServer bank = new BankServer(); bank.LoadDefaultClientBase(); bank.Show(); // Create cash machine to deal with credic cards. CashMachine cashMachine = new CashMachine(bank); while (true) { cashMachine.InsertCardDialog(); } }
public CommandPerfomer(CashMachine atm, Dictionary <AtmState, string> errors, Statistics.Statistics statistics) { _atm = atm; _errors = errors; _statistics = statistics; _commands = new Dictionary <string, Action> { { ConsoleLanguagePack.HelpFlag, HelpCommand }, { ConsoleLanguagePack.InsertFlag, InsertCassettesCommand }, { ConsoleLanguagePack.LanguageFlag, RefreshLanguageCommand }, { ConsoleLanguagePack.RemoveFlag, RemoveCasssettesCommand }, { ConsoleLanguagePack.StatisticsFlag, StatisticsCommand } }; _userViewer = new UserViewer(errors); }
public void TestAddNegative() { CashMachine atm = new CashMachine(); Dictionary <Int32, Int32> remainingCash = new Dictionary <Int32, Int32> { { 500, 0 }, { 200, 0 }, { 100, 0 }, { 50, 0 }, { 20, 0 }, { 10, 0 }, { 5, 0 } }; Assert.Throws <ArgumentException>(delegate { atm.AddCash(100, -1); // }, "An exception should be throwned when adding a negative number of an existing bill"); Assert.AreEqual(remainingCash, atm.RemainingCash, "Adding a negative number of an existing bill should let the CashMachine unchanged" ); }
private static void Main() { Console.WriteLine("OPTIONS:"); Console.WriteLine("1 - OCP"); Console.WriteLine("2 - LSP"); var option = Console.ReadKey(); switch (option.KeyChar) { case '1': CashMachine.Operations(); break; case '2': AreaComputation.Computation(); break; } }
public MainPage(Window window, Person person) { InitializeComponent(); _window = window; _person = person; int cashMachineId = 1; using (BankContext context = new BankContext()) { _cashMachine = context.CashMachines.Find(cashMachineId); } cashTextBlock.Text = _person.Purse.Money.ToString(); _operation = new Operation(); _operation.RegisterHandler(AddMoneyMethod, WithdrawMethod); }
//--Unity void Start() { //reverse= false; //speed = 0.0003f; //speed of the line //MaxNumberOfBalls= 20; //number of balls which are going to appear //BallDeath= true; //Balldeath mode? shooter = (Shooter)FindObjectOfType(typeof(Shooter)); //find the shooter path = (Path)gameObject.AddComponent ("Path"); //add the path numShotedBalls= 0; nextFireTime= Time.time+rememberTime; if(cashMachine==true){ cashmachine = (CashMachine)gameObject.AddComponent ("CashMachine"); //add the path } }