public void Initialize() { (coinSizes, coins, notes, users, atm, currencyDictionary) = Helpers .DatabaseHelper .CreateEntitiesArrays(); var allDispensers = new Dictionary <CoinSize, bool>(); foreach (var size in coinSizes) { allDispensers.Add(size, true); } emptyCurrenctyDictionary = new CurrencyDictionary() { CoinDictionary = new Dictionary <Coin, int>(), NoteDictionary = new Dictionary <Note, int>() }; emptyAtm = new AutomatedTellerMachine() { CurrencyDictionary = emptyCurrenctyDictionary, Alias = "Empty ATM", CoinDispensersDictionary = allDispensers, HasNoteDispenser = true }; }
public async Task <IActionResult> Edit(int id, AutomatedTellerMachine automatedTellerMachine) { if (id != automatedTellerMachine.AutomatedTellerMachineId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(automatedTellerMachine); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AutomatedTellerMachineExists(automatedTellerMachine.AutomatedTellerMachineId)) { return(NotFound()); } else { throw; } } return(RedirectToAction("Index")); } return(View(automatedTellerMachine)); }
public void Commission_Should_Be_At_Least_One_Cent() { var atm = new AutomatedTellerMachine(); atm.LoadMoney(Money.OneCent); atm.TakeMoney(.01m); atm.MoneyCharged.Should().Be(.02m); }
public AutomatedTellerMachine UpdateATM(AutomatedTellerMachine machine) { _atms.UpdateOne(Builders <MongoObject <AutomatedTellerMachine> > .Filter.Eq("_id", ObjectId.Parse(machine.Id)), Builders <MongoObject <AutomatedTellerMachine> > .Update .Set("Element.MoneyCharged", machine.MoneyCharged) .Set("Element.MoneyInside", machine.MoneyInside)); return(GetATM(machine.Id)); }
public void Commission_Should_Be_Rounded_Up_To_Nearest_Cent() { var atm = new AutomatedTellerMachine(); atm.LoadMoney(Money.FiveDollar); atm.LoadMoney(Money.Quarter); atm.TakeMoney(.25m); atm.MoneyCharged.Should().Be(.26m); }
public void Take_Money_Should_Exchange_Money_With_Commission() { var atm = new AutomatedTellerMachine(); atm.LoadMoney(Money.Dollar); atm.TakeMoney(1.00m); atm.MoneyInside.Amount.Should().Be(0m); atm.MoneyCharged.Should().Be(1.01m); }
public AutomatedTellerMachine CreateAutomatedTellerMachine(AutomatedTellerMachine machine, AdministrationAccessLevel accessLevel = AdministrationAccessLevel.ReadOnlyAccessToSystem) { if (accessLevel == AdministrationAccessLevel.FullAccessToSystem) { if (db.Banks.Any()) { var bank = db.Banks.First(); AddBankAutomatedTellerMachine(bank, machine, AdministrationAccessLevel.FullAccessToSystem); } } return(machine); }
public static AutomatedTellerMachineViewModel FromModel(AutomatedTellerMachine model) { return(new AutomatedTellerMachineViewModel() { AutomatedTellerMachineId = model.AutomatedTellerMachineId, Alias = model.Alias, CoinDictionary = model.CurrencyDictionary.CoinDictionary.ToDictionary(k => k.Key.CoinId, v => v.Value), NoteDictionary = model.CurrencyDictionary.NoteDictionary.ToDictionary(k => k.Key.NoteId, v => v.Value), HasNoteDispenser = model.HasNoteDispenser, CoinDispensersDictionary = model .CoinDispensersDictionary .ToDictionary(k => k.Key.CoinSizeId, v => v.Value) }); }
public WhenAskedToWithdrawCash() { const long accountNumber = 178817326296; _withdrawalAmount = 64.00m; _accountService = new Mock<IAccountService>(); _accountService .Setup(x => x.DebitAccount(accountNumber, _withdrawalAmount)) .Verifiable(); _cashDespencer = new Mock<ICashDispenser>(); _cashDespencer .Setup(x => x.GetCash(_withdrawalAmount)) .Returns(_withdrawalAmount) .Verifiable(); var subject = new AutomatedTellerMachine(_accountService.Object, _cashDespencer.Object); _result = subject.Withdraw(_withdrawalAmount, accountNumber); }
public static CurrencyDictionary WithdrawFromAtm(User user, AutomatedTellerMachine atm, int amount, CoinifyWebContext context = null) { var curDict = atm.CurrencyDictionary; var ret = new CurrencyDictionary() { CoinDictionary = new Dictionary <Coin, int>(), NoteDictionary = new Dictionary <Note, int>() }; if (user.Balance - amount < 0) { throw new InsufficentFundsException($"User {user.UserId} has insuficient funds to withdraw ${amount}"); } user.Balance -= amount; var validMoney = GenerateValidMoneyDictionary(curDict); foreach (var kvp in validMoney.ToList()) { while (validMoney[kvp.Key] != 0) { if ((amount - kvp.Key.Value) < 0) { break; } amount -= kvp.Key.Value; validMoney[kvp.Key]--; if (kvp.Key is Note) { var note = kvp.Key as Note; if (ret.NoteDictionary.ContainsKey(note)) { ret.NoteDictionary[note]++; } else { ret.NoteDictionary[note] = 1; } curDict.NoteDictionary[note]--; } else if (kvp.Key is Coin) { var coin = kvp.Key as Coin; if (ret.CoinDictionary.ContainsKey(coin)) { ret.CoinDictionary[coin]++; } else { ret.CoinDictionary[coin] = 1; } curDict.CoinDictionary[coin]--; } else { break; } } } if (amount > 0) { throw new InsufficientChangeException($"There is no change in ATM {atm.AutomatedTellerMachineId} to withdraw ${amount}"); } if (context != null) { context.Update(user); context.Update(atm); context.SaveChanges(); } return(ret); }
public void AddAutomatedTellerMachineHistoryRecord(AutomatedTellerMachine machine, AutomatedTellerMachineHistory record, AdministrationAccessLevel accessLevel = AdministrationAccessLevel.ReadOnlyAccessToSystem) { //Bug here! db.Banks.First().BankAutomatedTellerMachines.First().OperationsHistory.Add(record); db.SaveChanges(); }
public void AddBankAutomatedTellerMachine(Bank bank, AutomatedTellerMachine automatedTellerMachine, AdministrationAccessLevel accessLevel = AdministrationAccessLevel.ReadOnlyAccessToSystem) { db.Banks.Find(bank).BankAutomatedTellerMachines.Add(automatedTellerMachine); db.SaveChanges(); }
) CreateEntitiesArrays() { var coinSizes = new[] { new CoinSize() { Size = 10 }, new CoinSize() { Size = 20 }, new CoinSize() { Size = 30 }, new CoinSize() { Size = 40 }, new CoinSize() { Size = 50 }, }; var coins = new[] { new Coin() { Value = 20, Size = coinSizes[3] }, new Coin() { Value = 10, Size = coinSizes[1] }, new Coin() { Value = 5, Size = coinSizes[4] }, new Coin() { Value = 2, Size = coinSizes[2] }, new Coin() { Value = 1, Size = coinSizes[0] }, }; var notes = new[] { new Note() { Value = 1000 }, new Note() { Value = 500 }, new Note() { Value = 200 }, new Note() { Value = 100 }, new Note() { Value = 50 }, }; var currencyDictionary = new CurrencyDictionary() { CoinDictionary = new System.Collections.Generic.Dictionary <Coin, int>() { { coins[0], 100 }, { coins[1], 200 }, { coins[2], 300 }, { coins[3], 400 }, { coins[4], 500 }, }, NoteDictionary = new System.Collections.Generic.Dictionary <Note, int>() { { notes[0], 100 }, { notes[1], 200 }, { notes[2], 300 }, { notes[3], 400 }, { notes[4], 500 }, } }; var atm = new AutomatedTellerMachine() { Alias = "AmsTerdaM", CurrencyDictionary = currencyDictionary, HasNoteDispenser = true, CoinDispensersDictionary = new System.Collections.Generic.Dictionary <CoinSize, bool>() { { coinSizes[4], true }, { coinSizes[2], true }, } }; var users = new[] { new User() { Name = "Bill Gates", Balance = 1000000000 }, new User() { Name = "Bruno", Balance = 1000 } }; return(coinSizes, coins, notes, users, atm, currencyDictionary); }
public void Setup() { _accountService = new TestingAccountService(); _cashDispenser = new TestingCashDispenser(); _tellerMachine = new AutomatedTellerMachine(_accountService, _cashDispenser); }
public void SendMoneyToCustomerViaAtm(Customer reciever, Customer sender, AutomatedTellerMachine executer, double amount) { }