public void GetBySenderAndMinimumAmountDescending_ShouldWorkCorrectly_OnExistingSender() { //Arrange IChainblock cb = new Chainblock(); Transaction tx1 = new Transaction(2, TransactionStatus.Successfull, "joro", "pesho", 1); Transaction tx2 = new Transaction(1, TransactionStatus.Successfull, "valq", "pesho", 14.8); Transaction tx3 = new Transaction(4, TransactionStatus.Successfull, "valq", "pesho", 15.6); Transaction tx4 = new Transaction(3, TransactionStatus.Successfull, "valq", "pesho", 15.6); Transaction tx5 = new Transaction(8, TransactionStatus.Failed, "valq", "pesho", 17.8); List <Transaction> expected = new List <Transaction>() { tx5, tx3, tx4 }; //Act cb.Add(tx1); cb.Add(tx3); cb.Add(tx2); cb.Add(tx4); cb.Add(tx5); //Assert List <Transaction> actual = cb.GetBySenderAndMinimumAmountDescending("valq", 15.5).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void GetBySenderAndMinimumAmountDescending_ShouldThrowOnEmpty_CB() { //Arrange IChainblock cb = new Chainblock(); //Act //Assert Assert.Throws <InvalidOperationException>(() => { cb.GetBySenderAndMinimumAmountDescending("pesho", 5); }); }
public void GetBySenderAndMinimumAmountDescending_ShouldWorkFast() { IChainblock cb = new Chainblock(); List <Transaction> txs = new List <Transaction>(); Random rand = new Random(); for (int i = 0; i < 100000; i++) { int amount = rand.Next(0, 1000); Transaction tx = new Transaction(i, TransactionStatus.Successfull, "sender", i.ToString(), amount); cb.Add(tx); if (amount > 500) { txs.Add(tx); } } txs = txs.OrderByDescending(x => x.Amount).ToList(); int count = cb.Count; Assert.AreEqual(100000, count); Stopwatch watch = new Stopwatch(); watch.Start(); IEnumerable <Transaction> all = cb.GetBySenderAndMinimumAmountDescending( "sender", 500); int c = 0; foreach (Transaction tx in all) { Assert.AreSame(tx, txs[c]); c++; } watch.Stop(); long l1 = watch.ElapsedMilliseconds; Assert.IsTrue(l1 < 150); Assert.AreEqual(txs.Count, c); }
public void GetBySenderAndMinimumAmountDescending_ShouldThrow_OnMissingSender() { //Arrange IChainblock cb = new Chainblock(); Transaction tx1 = new Transaction(2, TransactionStatus.Successfull, "joro", "pesho", 1); Transaction tx2 = new Transaction(1, TransactionStatus.Successfull, "valq", "pesho", 14.8); Transaction tx3 = new Transaction(4, TransactionStatus.Successfull, "valq", "pesho", 15.6); Transaction tx4 = new Transaction(3, TransactionStatus.Successfull, "valq", "pesho", 15.6); Transaction tx5 = new Transaction(8, TransactionStatus.Failed, "valq", "pesho", 17.8); //Act cb.Add(tx1); cb.Add(tx3); cb.Add(tx2); cb.Add(tx4); cb.Add(tx5); //Assert Assert.Throws <InvalidOperationException>(() => { cb.GetBySenderAndMinimumAmountDescending("poncho", 15.5).ToList(); }); }
public void GetBySenderAndMinimumAmountDescending_ThrowsException_WhenNoMatches(string sender, double amount) { CreateBulkOfTransactions(); Assert.Throws <InvalidOperationException>(() => testChainblock.GetBySenderAndMinimumAmountDescending(sender, amount)); }
public void GetBySenderAndMinimumAmountDescending_ShouldThrowInvalidOperationException() { Assert.Throws <InvalidOperationException>( () => chainblock.GetBySenderAndMinimumAmountDescending("Drago", 10) ); }