Skip to content

Commit

Permalink
Merge pull request #36 from AArnott/fixTxSortOnLoad
Browse files Browse the repository at this point in the history
Fix transaction sort on load
  • Loading branch information
AArnott authored Oct 10, 2021
2 parents a1b4ebf + e767dab commit a1ab132
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Nerdbank.MoneyManagement/ViewModels/AccountViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public IReadOnlyList<TransactionViewModel> Transactions
foreach (Transaction transaction in transactions)
{
TransactionViewModel transactionViewModel = new(this, transaction);
this.transactions.Add(transactionViewModel);
int index = this.transactions.BinarySearch(transactionViewModel, TransactionSort.Instance);
this.transactions.Insert(index < 0 ? ~index : index, transactionViewModel);
}

this.UpdateBalances(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,22 @@ public void TransactionSorting_3Transactions()
Assert.Equal(new[] { tx2.Id, tx3.Id, tx1.Id }, this.checking.Transactions.Select(tx => tx.Id));
}

[Fact]
public void TransactionsSortedOnLoad()
{
TransactionViewModel tx1 = this.checking.NewTransaction(volatileOnly: false);
tx1.When = new DateTime(2021, 1, 3);

TransactionViewModel tx2 = this.checking.NewTransaction(volatileOnly: false);
tx2.When = new DateTime(2021, 1, 2);

// Confirm that a reload does not mess up transaction order.
Assert.Equal(new[] { tx2.Id, tx1.Id }, this.checking.Transactions.Select(tx => tx.Id));
this.ReloadViewModel();
AccountViewModel newChecking = this.DocumentViewModel.AccountsPanel.Accounts.Single(a => a.Id == this.checking.Id);
Assert.Equal(new[] { tx2.Id, tx1.Id }, newChecking.Transactions.Select(tx => tx.Id));
}

[Fact]
public async Task Balance_Updates()
{
Expand Down

0 comments on commit a1ab132

Please sign in to comment.