public void GetAllOrderedByAmountDescendingThenById_ShouldWorkCorrectlyAfterRemove() { //Arrange IChainblock cb = new Chainblock(); Transaction tx1 = new Transaction(5, TransactionStatus.Successfull, "joro", "pesho", 1); Transaction tx2 = new Transaction(6, TransactionStatus.Successfull, "joro", "pesho", 5.5); Transaction tx3 = new Transaction(7, TransactionStatus.Successfull, "joro", "pesho", 5.5); Transaction tx4 = new Transaction(12, TransactionStatus.Successfull, "joro", "pesho", 15.6); Transaction tx5 = new Transaction(15, TransactionStatus.Successfull, "joro", "pesho", 7.8); List <Transaction> expected = new List <Transaction>() { tx5, tx3, tx1 }; //Act cb.Add(tx1); cb.Add(tx3); cb.Add(tx2); cb.Add(tx4); cb.Add(tx5); List <Transaction> before = cb.GetAllOrderedByAmountDescendingThenById().ToList(); Assert.AreEqual(5, before.Count); cb.RemoveTransactionById(tx4.Id); cb.RemoveTransactionById(tx2.Id); List <Transaction> actual = cb.GetAllOrderedByAmountDescendingThenById().ToList(); //Assert CollectionAssert.AreEqual(expected, actual); }
public void GetOrderedByAmountDescendingThenById_ShouldWorkFast() { IChainblock cb = new Chainblock(); List <Transaction> txs = new List <Transaction>(); for (int i = 0; i < 100000; i++) { Transaction tx = new Transaction(i, TransactionStatus.Successfull, i.ToString(), i.ToString(), i); cb.Add(tx); txs.Add(tx); } int count = cb.Count; Assert.AreEqual(100000, count); Stopwatch watch = new Stopwatch(); watch.Start(); IEnumerable <Transaction> all = cb.GetAllOrderedByAmountDescendingThenById(); int c = 0; foreach (Transaction tx in all) { c++; } watch.Stop(); long l1 = watch.ElapsedMilliseconds; Assert.IsTrue(l1 < 150); Assert.AreEqual(100000, c); }
public void GetAllOrderedByAmountDescendingThenById_ShouldReturnEmpty_OnEmptyCB() { //Arrange IChainblock cb = new Chainblock(); //Act List <Transaction> actual = cb.GetAllOrderedByAmountDescendingThenById().ToList(); //Assert CollectionAssert.AreEqual(new List <Transaction>(), actual); }
public void GetAllOrderedByAmountDescendingThenById_ReturnsCorrectly() { CreateBulkOfTransactions(); List <ITransaction> orderedTransactions = transactions.Values .OrderByDescending(t => t.Amount) .ThenBy(t => t.Id) .ToList(); Assert.That(orderedTransactions, Is.EquivalentTo(testChainblock.GetAllOrderedByAmountDescendingThenById())); }
public void GetAllOrderedByAmountDescendingThenById_ShouldReturnCorrectly() { ITransaction transaction1 = new Transaction(1, TransactionStatus.Successfull, "Pesho", "Gosho", 100); ITransaction transaction2 = new Transaction(2, TransactionStatus.Successfull, "Pesho", "Gichka", 1100); ITransaction transaction3 = new Transaction(3, TransactionStatus.Aborted, "Drago", "Gichka", 10); chainblock.Add(transaction1); chainblock.Add(transaction2); chainblock.Add(transaction3); var expected = new List <ITransaction> { transaction2, transaction1, transaction3 }; var actual = chainblock.GetAllOrderedByAmountDescendingThenById(); Assert.AreEqual(expected, actual); }