/// <summary> /// Splits the provided transaction into two. The provided transactions is removed, and two new transactions are /// created. Both transactions must add up to the existing transaction amount. /// </summary> /// <exception cref="System.ArgumentNullException"> /// </exception> public void SplitTransaction(Transaction originalTransaction, decimal splinterAmount1, decimal splinterAmount2, BudgetBucket splinterBucket1, BudgetBucket splinterBucket2) { if (originalTransaction == null) { throw new ArgumentNullException(nameof(originalTransaction)); } if (splinterBucket1 == null) { throw new ArgumentNullException(nameof(splinterBucket1)); } if (splinterBucket2 == null) { throw new ArgumentNullException(nameof(splinterBucket2)); } StatementModel.SplitTransaction( originalTransaction, splinterAmount1, splinterAmount2, splinterBucket1, splinterBucket2); }
private static decimal GetBudgetModelTotalForBucket(BudgetModel budgetModel, BudgetBucket bucket) { if (bucket is PayCreditCardBucket) { // Ignore return(0); } if (bucket is IncomeBudgetBucket) { throw new InvalidOperationException( "Code Error: Income bucket detected when Bucket Spending only applies to Expenses."); } // Use budget values instead if (bucket is SurplusBucket) { return(budgetModel.Surplus); } var budget = budgetModel.Expenses.FirstOrDefault(e => e.Bucket == bucket); if (budget != null) { return(budget.Amount); } return(0); }
public void ValidateShouldThrowGivenNullStringBuilder() { BudgetBucket subject = Arrange(); subject.Validate(null); Assert.Fail(); }
public void CtorShouldAllocateUpperCaseCode() { BudgetBucket subject = Arrange("Foo", "Bar"); Assert.AreEqual("FOO", subject.Code); Assert.AreNotEqual("Foo", subject.Code); }
public void Comparable_PhoneBucketIsEqualToAnotherInstance() { SpentMonthlyExpenseBucket phoneBucket = StatementModelTestData.PhoneBucket; BudgetBucket phooneBucket2 = Arrange(TestDataConstants.PhoneBucketCode, "Foo"); Assert.IsTrue(phoneBucket.CompareTo(phooneBucket2) == 0); }
public void SettingCodeShouldConvertToUpperCase() { BudgetBucket subject = Arrange("Foo", "Bar"); subject.Code = "White"; Assert.AreNotEqual("White", subject.Code); Assert.AreEqual("WHITE", subject.Code); }
public void ValidateShouldRetrunFalseGivenLongCode() { BudgetBucket subject = Arrange(); subject.Code = "ABC345678"; bool result = subject.Validate(new StringBuilder()); Assert.IsFalse(result); }
public void TwoReferencesToTheSameObjectAreEqual() { BudgetBucket subject1 = Arrange("Foo", "Name"); BudgetBucket subject2 = subject1; Assert.AreEqual(subject1, subject2); Assert.IsTrue(subject1 == subject2); Assert.AreEqual(subject1.GetHashCode(), subject2.GetHashCode()); }
public void TwoReferencesToDifferentObjectsAreNotEqual() { BudgetBucket subject1 = Arrange("Foo", "Name"); BudgetBucket subject2 = Arrange("Ben", "Is Awesome"); Assert.AreNotEqual(subject1, subject2); Assert.IsTrue(subject1 != subject2); Assert.AreNotEqual(subject1.GetHashCode(), subject2.GetHashCode()); }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns> /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. /// </returns> public override int GetHashCode() { unchecked { // ReSharper disable NonReadonlyMemberInGetHashCode - Properties are only set by persistence return(((BudgetBucket?.GetHashCode() ?? 0) * 397) ^ (StoredInAccount?.GetHashCode() ?? 0)); // ReSharper restore NonReadonlyMemberInGetHashCode } }
public void TestInitialise() { this.testData = new FixedBudgetProjectBucket(FixedProjectCode, "Foo bar dum-de-dum", 1000); PrivateAccessor.SetProperty(this.testData, "Created", this.testDataCreatedDate); var subject = new Mapper_BudgetBucketDto_BudgetBucket(new BudgetBucketFactory()); this.result = subject.ToDto(this.testData); }
public void TwoBucketsAreDifferentIfCodesAreDifferent() { BudgetBucket subject1 = Arrange("Foo1", "Name"); BudgetBucket subject2 = Arrange("Foo2", "Name"); Assert.AreNotEqual(subject1, subject2); Assert.IsTrue(subject1 != subject2); Assert.AreNotEqual(subject1.GetHashCode(), subject2.GetHashCode()); }
public void TwoBucketsAreTheSameIfCodesAreEqual() { BudgetBucket subject1 = Arrange("Foo", "Name"); BudgetBucket subject2 = Arrange("Foo", "Name"); Assert.AreEqual(subject1, subject2); Assert.IsTrue(subject1 == subject2); Assert.AreEqual(subject1.GetHashCode(), subject2.GetHashCode()); }
/// <summary> /// Validates the bucket provided is valid for use with this LedgerBucket. There is an explicit relationship between /// <see cref="BudgetBucket" />s and <see cref="LedgerBucket" />s. /// </summary> /// <exception cref="System.NotSupportedException"> /// Invalid budget bucket used, only Spent-Monthly-Expense-Bucket can be /// used with an instance of Spent-Monthly-Ledger. /// </exception> protected override void ValidateBucketSet(BudgetBucket bucket) { if (bucket is SpentMonthlyExpenseBucket) { return; } throw new NotSupportedException( "Invalid budget bucket used, only Spent-Monthly-Expense-Bucket can be used with an instance of Spent-Monthly-Ledger."); }
public void ValidateWillReturnFalseWhenCodeIsTooLong() { BudgetBucket subject = Arrange(); subject.Description = "FooBarHo"; var builder = new StringBuilder(); Assert.IsFalse(subject.Validate(builder)); Assert.IsTrue(builder.Length > 0); }
/// <summary> /// Validates the bucket provided is valid for use with this LedgerBucket. There is an explicit relationship between /// <see cref="BudgetBucket" />s and <see cref="LedgerBucket" />s. /// </summary> /// <exception cref="System.NotSupportedException"> /// Invalid budget bucket used, only the Surplus bucket can be used with an /// instance of Surplus-Ledger. /// </exception> protected override void ValidateBucketSet(BudgetBucket bucket) { if (bucket is SurplusBucket) { return; } throw new NotSupportedException( "Invalid budget bucket used, only the Surplus bucket can be used with an instance of Surplus-Ledger."); }
public void ValidateWillReturnFalseWhenNameIsNull() { BudgetBucket subject = Arrange(); subject.Code = "Foo"; var builder = new StringBuilder(); Assert.IsFalse(subject.Validate(builder)); Assert.IsTrue(builder.Length > 0); }
internal virtual void SplitTransaction( [NotNull] Transaction originalTransaction, decimal splinterAmount1, decimal splinterAmount2, [NotNull] BudgetBucket splinterBucket1, [NotNull] BudgetBucket splinterBucket2) { ThrowIfDisposed(); if (originalTransaction == null) { throw new ArgumentNullException(nameof(originalTransaction)); } if (splinterBucket1 == null) { throw new ArgumentNullException(nameof(splinterBucket1)); } if (splinterBucket2 == null) { throw new ArgumentNullException(nameof(splinterBucket2)); } var splinterTransaction1 = originalTransaction.Clone(); var splinterTransaction2 = originalTransaction.Clone(); splinterTransaction1.Amount = splinterAmount1; splinterTransaction2.Amount = splinterAmount2; splinterTransaction1.BudgetBucket = splinterBucket1; splinterTransaction2.BudgetBucket = splinterBucket2; if (splinterAmount1 + splinterAmount2 != originalTransaction.Amount) { throw new ArgumentException("The two new amounts do not add up to the original transaction value."); } RemoveTransaction(originalTransaction); this.changeHash = Guid.NewGuid(); if (AllTransactions == null) { AllTransactions = new List <Transaction>(); } List <Transaction> mergedTransactions = AllTransactions.ToList().Merge(new[] { splinterTransaction1, splinterTransaction2 }).ToList(); AllTransactions = mergedTransactions; splinterTransaction1.PropertyChanged += OnTransactionPropertyChanged; splinterTransaction2.PropertyChanged += OnTransactionPropertyChanged; this.duplicates = null; UpdateDuration(); Filter(this.currentFilter); }
public void TestInitialise() { this.testData = new FixedBudgetBucketDto { Code = FixedBudgetProjectBucket.CreateCode(TestDataCode), Description = "Foo bar tiddle-de-dum", FixedBudgetAmount = 2000 }; var subject = new Mapper_BudgetBucketDto_BudgetBucket(new BudgetBucketFactory()); this.result = subject.ToModel(this.testData); }
private static Func <BudgetModel, decimal> BuildIncomeFinder(BudgetBucket bucket) { return(b => { var first = b.Incomes.FirstOrDefault(e => e.Bucket == bucket); if (first == null) { return 0; } return first.Amount; }); }
/// <summary> /// Validates the bucket provided is valid for use with this LedgerBucket. There is an explicit relationship between /// <see cref="BudgetBucket" />s and <see cref="LedgerBucket" />s. /// </summary> /// <exception cref="System.NotSupportedException"> /// Invalid budget bucket used, only Saved-Up-For-Expense-Buckets or /// Savings-Commitment-Buckets can be used with an instance of Saved-Up-For-Ledger. /// </exception> protected override void ValidateBucketSet(BudgetBucket bucket) { if (bucket is SavedUpForExpenseBucket) { return; } if (bucket is SavingsCommitmentBucket) { return; } throw new NotSupportedException( "Invalid budget bucket used, only Saved-Up-For-Expense-Buckets or Savings-Commitment-Buckets can be used with an instance of Saved-Up-For-Ledger."); }
public void FetchBudgetBucketWithValidParamsShouldReturnBucketObject() { BankImportUtilities subject = CreateSubject(); string[] testArray = CreateTestArray(); var expectedResult = new SpentMonthlyExpenseBucket("FUEL", "Fuel"); BucketRepositoryMock.Setup(m => m.GetByCode("FUEL")).Returns(expectedResult); BudgetBucket result = subject.FetchBudgetBucket(testArray, 2, BucketRepositoryMock.Object); BucketRepositoryMock.Verify(); Assert.AreSame(expectedResult, result); }
/// <summary> /// Initializes a new instance of the <see cref="RulesGroupedByBucket" /> class. /// </summary> /// <param name="bucket">The bucket.</param> /// <param name="rules">The rules.</param> /// <exception cref="System.ArgumentNullException"> /// </exception> public RulesGroupedByBucket([NotNull] BudgetBucket bucket, [NotNull] IEnumerable <MatchingRule> rules) { if (bucket == null) { throw new ArgumentNullException(nameof(bucket)); } if (rules == null) { throw new ArgumentNullException(nameof(rules)); } Bucket = bucket; Rules = new ObservableCollection <MatchingRule>(rules.ToList()); }
public void ShowDialog(Transaction transaction, Guid correlationId) { Transaction = transaction; this.originalBucket = Transaction.BudgetBucket; Buckets = this.bucketRepo.Buckets.Where(b => b.Active); MessengerInstance.Send( new ShellDialogRequestMessage( BudgetAnalyserFeature.Transactions, this, ShellDialogType.SaveCancel) { CorrelationId = correlationId, Title = "Edit Transaction" }); }
/// <summary> /// Initializes a new instance of the <see cref="TransactionGroupedByBucket" /> class. /// </summary> /// <param name="transactions">The transactions.</param> /// <param name="groupByThisBucket">The group by this bucket.</param> /// <exception cref="System.ArgumentNullException"> /// </exception> public TransactionGroupedByBucket([NotNull] IEnumerable <Transaction> transactions, [NotNull] BudgetBucket groupByThisBucket) { if (transactions == null) { throw new ArgumentNullException(nameof(transactions)); } if (groupByThisBucket == null) { throw new ArgumentNullException(nameof(groupByThisBucket)); } Bucket = groupByThisBucket; Transactions = new ObservableCollection <Transaction>( transactions.Where(t => t.BudgetBucket == groupByThisBucket).OrderBy(t => t.Date)); }
private static decimal GetLedgerBalanceForBucket(BudgetModel budgetModel, LedgerEntryLine applicableLine, BudgetBucket bucket) { if (bucket is SurplusBucket) { return(applicableLine.CalculatedSurplus); } var ledger = applicableLine.Entries.FirstOrDefault(e => e.LedgerBucket.BudgetBucket == bucket); if (ledger != null) { return(ledger.Balance); } // The Ledger line might not actually have a ledger for the given bucket. return(GetBudgetModelTotalForBucket(budgetModel, bucket)); }
public BucketDtoType SerialiseType([NotNull] BudgetBucket bucket) { if (bucket == null) { throw new ArgumentNullException(nameof(bucket)); } if (bucket is IncomeBudgetBucket) { return(BucketDtoType.Income); } if (bucket is FixedBudgetProjectBucket) { return(BucketDtoType.FixedBudgetProject); } if (bucket is SurplusBucket) { return(BucketDtoType.Surplus); } if (bucket is PayCreditCardBucket) { return(BucketDtoType.PayCreditCard); } if (bucket is SavedUpForExpenseBucket) { return(BucketDtoType.SavedUpForExpense); } if (bucket is SpentMonthlyExpenseBucket) { return(BucketDtoType.SpentMonthlyExpense); } if (bucket is SavingsCommitmentBucket) { return(BucketDtoType.SavingsCommitment); } throw new NotSupportedException("Unsupported bucket type detected: " + bucket.GetType().FullName); }
internal void ReassignFixedProjectTransactions([NotNull] FixedBudgetProjectBucket bucket, [NotNull] BudgetBucket reassignmentBucket) { ThrowIfDisposed(); if (bucket == null) { throw new ArgumentNullException(nameof(bucket)); } if (reassignmentBucket == null) { throw new ArgumentNullException(nameof(reassignmentBucket)); } foreach (var transaction in AllTransactions.Where(t => t.BudgetBucket == bucket)) { transaction.BudgetBucket = reassignmentBucket; } }
/// <summary> /// Builds a <see cref="BudgetBucketDto" /> based on the model passed in. /// </summary> public BudgetBucketDto BuildDto(BudgetBucket bucket) { BudgetBucketDto dto; var fixedProjectBucket = bucket as FixedBudgetProjectBucket; if (fixedProjectBucket != null) { dto = new FixedBudgetBucketDto { Created = fixedProjectBucket.Created, FixedBudgetAmount = fixedProjectBucket.FixedBudgetAmount }; } else { dto = new BudgetBucketDto(); } dto.Type = SerialiseType(bucket); return dto; }
/// <summary> /// Builds a <see cref="BudgetBucketDto" /> based on the model passed in. /// </summary> public BudgetBucketDto BuildDto(BudgetBucket bucket) { BudgetBucketDto dto; var fixedProjectBucket = bucket as FixedBudgetProjectBucket; if (fixedProjectBucket != null) { dto = new FixedBudgetBucketDto { Created = fixedProjectBucket.Created, FixedBudgetAmount = fixedProjectBucket.FixedBudgetAmount }; } else { dto = new BudgetBucketDto(); } dto.Type = SerialiseType(bucket); return(dto); }
public BudgetBucketChosenEventArgs(Guid correlationId, BudgetBucket bucket, Account storeInThisAccount) : this(correlationId, bucket) { StoreInThisAccount = storeInThisAccount; }
// ReSharper disable once RedundantAssignment partial void DtoFactory(ref BudgetBucketDto dto, BudgetBucket model) { dto = this.bucketFactory.BuildDto(model); }
// ReSharper disable once RedundantAssignment partial void ModelFactory(BudgetBucketDto dto, ref BudgetBucket model) { model = this.bucketFactory.BuildModel(dto); }