public async Task CalculateAsync_WhenCalled_ReturnsSameAccountBase() { IAccountBase <IAccountBase> sut = CreateSut(); IAccountBase result = await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); Assert.That(result, Is.SameAs(sut)); }
public void Equals_WhenObjectIsNoneAccountBase_ReturnsFalse() { IAccountBase <IAccountBase> sut = CreateSut(); bool result = sut.Equals(_fixture.Create <object>()); Assert.That(result, Is.False); }
public async Task CalculateAsync_WhenCalled_AssertAlreadyCalculatedWasNotCalledOnSut() { IAccountBase <IAccountBase> sut = CreateSut(); Sut result = (Sut)await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); Assert.That(result.AlreadyCalculatedWasCalled, Is.False); }
public void Equals_WhenObjectIsNull_ReturnsFalse() { IAccountBase <IAccountBase> sut = CreateSut(); bool result = sut.Equals(null); Assert.That(result, Is.False); }
public async Task CalculateAsync_WhenCalled_AssertGetCalculationResultAsyncWasCalledOnSut() { IAccountBase <IAccountBase> sut = CreateSut(); Sut result = (Sut)await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); Assert.That(result.GetCalculationResultAsyncWasCalled, Is.True); }
public void GetHashCode_WhenCalled_AssertNumberWasCalledOnAccounting() { Mock <IAccounting> accountingMock = _fixture.BuildAccountingMock(); IAccountBase <IAccountBase> sut = CreateSut(accountingMock.Object); sut.GetHashCode(); accountingMock.Verify(m => m.Number, Times.Once); }
public async Task CalculateAsync_WhenCalled_ReturnsSameAccountBaseWhereStatusDateEqualDateFromCall() { IAccountBase <IAccountBase> sut = CreateSut(); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); IAccountBase result = await sut.CalculateAsync(statusDate); Assert.That(result.StatusDate, Is.EqualTo(statusDate.Date)); }
public async Task CalculateAsync_WhenCalled_AssertAllCalculationTasksIsCompleted() { Task[] calculationTasks = CreateCalculationTasks(); IAccountBase <IAccountBase> sut = CreateSut(calculationTasks); await sut.CalculateAsync(DateTime.Now.AddDays(_random.Next(1, 365) * -1)); Assert.That(calculationTasks.All(calculationTask => calculationTask.IsCompleted), Is.True); }
public async Task CalculateAsync_WhenCalled_AssertGetCalculationTasksWasCalledWithSameStatusDate() { IAccountBase <IAccountBase> sut = CreateSut(); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); Sut result = (Sut)await sut.CalculateAsync(statusDate); Assert.That(result.GetCalculationTasksWasCalledWithStatusDate, Is.EqualTo(statusDate.Date)); }
public async Task CalculateAsync_WhenCalledMultipleTimesWithSameStatusDate_ReturnsSameAccountBase() { IAccountBase <IAccountBase> sut = CreateSut(); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); IAccountBase result = await((IAccountBase <IAccountBase>)await((IAccountBase <IAccountBase>) await sut.CalculateAsync(statusDate)).CalculateAsync(statusDate)).CalculateAsync(statusDate); Assert.That(result, Is.SameAs(sut)); }
public async Task CalculateAsync_WhenCalledMultipleTimesWithSameStatusDate_AssertAlreadyCalculatedWasCalledTwiceOnSut() { IAccountBase <IAccountBase> sut = CreateSut(); DateTime statusDate = DateTime.Now.AddDays(_random.Next(1, 365) * -1); Sut result = (Sut)await((IAccountBase <IAccountBase>)await((IAccountBase <IAccountBase>) await sut.CalculateAsync(statusDate)).CalculateAsync(statusDate)).CalculateAsync(statusDate); Assert.That(result.AlreadyCalculatedWasCalledTimes, Is.EqualTo(2)); }
public void AddAccount(IAccountBase account) { //error checking if (_accounts.ContainsKey(account.Name)) { throw new ArgumentException("That account already exists!"); } _accounts.Add(account.Name, account); }
public void GetHashCode_WhenCalled_ReturnsHashCodeBasedOnAccountingNumberAndAccountNumber() { int accountingNumber = _fixture.Create <int>(); IAccounting accounting = _fixture.BuildAccountingMock(accountingNumber).Object; string accountNumber = _fixture.Create <string>(); IAccountBase <IAccountBase> sut = CreateSut(accounting, accountNumber); Assert.That(sut.GetHashCode(), Is.EqualTo(string.GetHashCode($"{accountNumber.ToUpper()}@{accountingNumber}"))); }
public Income(string name, decimal paydayAmount, IncomeFrequencyEnum incomeFrequency, IAccountBase depositAccount, DateTime firstDeposit) { Name = name; PaydayAmount = paydayAmount; PaydayFrequency = incomeFrequency; DepositAccount = depositAccount; FirstDeposit = firstDeposit; NextDeposit = FirstDeposit; NumPaydaysPaidThisYear = 0; }
public HardBill(string name, decimal amount, DateTime firstBillDue, HardBillFrequencyEnum frequency, IAccountBase paymentSource, bool autoPay) { Name = name; Amount = amount; FirstBillDue = firstBillDue; NextBillDue = firstBillDue; Frequency = frequency; PaymentAccount = paymentSource; AutoPay = autoPay; }
public PostingWarning(PostingWarningReason reason, IAccountBase account, decimal amount, IPostingLine postingLine) { NullGuard.NotNull(account, nameof(account)) .NotNull(postingLine, nameof(postingLine)); Reason = reason; Account = account; Amount = amount; PostingLine = postingLine; }
public void Equals_WhenObjectIsAccountBaseWithSameAccountingAndSameAccountNumber_ReturnsTrue() { int accountingNumber = _fixture.Create <int>(); IAccounting accounting = _fixture.BuildAccountingMock(accountingNumber).Object; string accountNumber = _fixture.Create <string>(); IAccountBase <IAccountBase> sut = CreateSut(accounting, accountNumber); bool result = sut.Equals(CreateSut(accounting, accountNumber)); Assert.That(result, Is.True); }
static bool Deposit(IAccountBase acc) { Console.WriteLine("How much would you like to Deposit"); double amt; try { double.TryParse(Console.ReadLine(), out amt); acc.CreditAccount(amt); return(true); } catch (Exception) { return(false); } }
static bool WithDrawal(IAccountBase acc) { Console.WriteLine("How much would you like to Withdraw"); double amt; try { double.TryParse(Console.ReadLine(), out amt); acc.DebitAccount(amt); return(true); } catch (Exception) { return(false); } }
private SharedPlugin(IAccountBase account) { string name = "unknown"; string accountSource = "unknown"; if (account is IFriendlyAccount fAccount) { name = fAccount.Username; accountSource = "FriendlyBot <3"; } else if (account is IDofusAccount dAccount) { name = dAccount.FriendlyAccount.Username; accountSource = "Dofus <3"; } account.BotManager.Logger.Add($"Salut {name}, tu m'as charger à partir de ton compte {accountSource}!", FriendlyBot.API.Enums.LogType.Debug); }
public void SerializeTest() { string filepath = @"C:\Users\Batman\budgets\BudgetTest.bin"; yearTop.FastForward(new DateTime(2020, 12, 31)); //transaction details decimal amount; string description; DateTime date; SoftBillTransaction sbt; /* Credit checks */ amount = 100; description = "grocery store"; date = new DateTime(2020, 1, 15); sbt = yearTop.GetSoftBillTransaction(description, amount, date.Month); sbt.SoftGroupSplit["food"] = amount; yearTop.GetAccount("credit").NewDebitTransaction(sbt); /* Checking checks */ amount = 150; description = "gas station"; date = new DateTime(2020, 1, 16); sbt = yearTop.GetSoftBillTransaction(description, amount, date.Month); sbt.SoftGroupSplit["gas"] = amount; yearTop.GetAccount("checking").NewDebitTransaction(sbt); yearTop.SaveToFile(filepath); YearTop desYearTop = YearTop.LoadFromFile(filepath); var accountNames = yearTop.GetAccountsNames(); foreach (var name in accountNames) { IAccountBase origAccount = yearTop.GetAccount(name); IAccountBase copyAccount = desYearTop.GetAccount(name); Assert.AreEqual(origAccount.CurrentBalance, copyAccount.CurrentBalance); IReadOnlyList <Transaction> origTs = origAccount.GetTransactions(); IReadOnlyList <Transaction> copyTs = copyAccount.GetTransactions(); for (int i = 0; i < origTs.Count; i++) { Transaction origT = origTs[i]; Transaction copyT = copyTs[i]; Assert.AreEqual(origT.Amount, copyT.Amount); Assert.AreEqual(origT.Date, copyT.Date); Assert.AreEqual(origT.Description, copyT.Description); if (origT.GetType().Name.Contains("SoftBill")) { SoftBillTransaction origSbt = origT as SoftBillTransaction; SoftBillTransaction copySbt = copyT as SoftBillTransaction; foreach (var item in origSbt.SoftGroupSplit) { Assert.AreEqual(item.Value, copySbt.SoftGroupSplit[item.Key]); } } } } }
private void RefreshPage() { if (_skipRefreshing) { return; } //i wonder if i'll ever notice how slow this is.. YearTop localYt; if (_dateSelected > DateTime.Today) { localYt = _year.Copy(); localYt.FastForward(_dateSelected); _fastForwardNoEditing = true; } else { localYt = _year; _fastForwardNoEditing = false; } //using accountsLv here so the order matches up //accountsLv is for name & selection //accountInfoLv is to display any info for each of those accounts accountInfoLv.Items.Clear(); foreach (ListViewItem item in accountsLv.Items) { if (item == null) { continue; } ListViewItem lvi = new ListViewItem(localYt.GetAccount(item.Text).GetBalance(_dateSelected).ToString()); lvi.SubItems.Add(localYt.GetAccount(item.Text).StartingDate.ToShortDateString()); accountInfoLv.Items.Add(lvi); } var softBillUsage = localYt.GetSoftBillUsed(_monthSelected); softBillsLbl.Text = string.Format("Soft Bills Month: {0}", Months[_monthSelected]); //update softbilllbl softBillsLv.Items.Clear(); foreach (var softBill in localYt.GetSoftBillGroup(_monthSelected)) { ListViewItem lvi = new ListViewItem(softBill.Key); lvi.SubItems.Add(softBill.Value.ToString()); lvi.SubItems.Add((softBill.Value - softBillUsage[softBill.Key]).ToString()); lvi.Tag = softBill.Value; softBillsLv.Items.Add(lvi); } transactionsLv.Items.Clear(); List <Transaction> displayTransactions = new List <Transaction>(); var accountNames = localYt.GetAccountsNames(); if (accountNames.Contains(_selectedAccountName)) { IAccountBase selectedAccount = localYt.GetAccount(_selectedAccountName); if (_allDatesTransactions) { displayTransactions = selectedAccount.GetTransactions().ToList(); } else { displayTransactions = selectedAccount.GetTransactions().Where(p => (p.Date.Month == _dateSelected.Month)).ToList(); } foreach (var t in displayTransactions.OrderBy(t => t.Date).ToList()) { ListViewItem lvi = new ListViewItem(t.Description); lvi.SubItems.Add(t.Amount.ToString()); lvi.SubItems.Add(selectedAccount.Name); //subitems 2? lvi.SubItems.Add(t.Date.ToShortDateString()); lvi.Tag = t; if (t.Date < selectedAccount.StartingDate) { lvi.BackColor = Color.LightGray; } transactionsLv.Items.Add(lvi); } } hardBillsLv.Items.Clear(); var hbList = localYt.GetHardBills(); hbList.Sort((pair1, pair2) => pair1.NextBillDue.CompareTo(pair2.NextBillDue)); int count = 0; foreach (var hb in hbList) { ListViewItem lvi = new ListViewItem(hb.Name); lvi.SubItems.Add(hb.Amount.ToString()); lvi.SubItems.Add(hb.NextBillDue.ToShortDateString()); if ((hb.AutoPay == false) && (hb.NextBillDue <= _dateSelected)) { lvi.BackColor = Color.Red; } else if (hb.AutoPay) { lvi.BackColor = Color.LightGreen; } hardBillsLv.Items.Add(lvi); count++; if (count > 5) { break; } } incomeLv.Items.Clear(); var incomeList = localYt.GetIncomeSources(); incomeList.Sort((pair1, pair2) => pair1.NextDeposit.CompareTo(pair2.NextDeposit)); count = 0; foreach (var income in incomeList) { ListViewItem lvi = new ListViewItem(income.Name); lvi.SubItems.Add(income.PaydayAmount.ToString()); lvi.SubItems.Add(income.NextDeposit.ToShortDateString()); incomeLv.Items.Add(lvi); count++; if (count > 5) { break; } } }
//public HardBill(HardBill hb) //{ // this.Name = hb.Name; // this.Amount = hb.Amount; // this.FirstBillDue = hb.FirstBillDue; // this.Frequency = hb.Frequency; // this.PaymentAccount = AccountBaseFactory.CopyAccountBase(hb.PaymentAccount); // this.NextBillDue = hb.NextBillDue; // this.AutoPay = hb.AutoPay; //} #endregion public void AssignPaymentAccount(IAccountBase account) { PaymentAccount = account; }
static void CheckBalance(IAccountBase acc) { Console.WriteLine($"Account Balance is : {acc.GetBalance()}"); }