public void GetByReceiver_ShouldWorkCorrectly() { //Arrange IChainblock cb = new Chainblock(); Transaction tx1 = new Transaction(2, TransactionStatus.Successfull, "joro", "pesho", 1); Transaction tx2 = new Transaction(1, TransactionStatus.Successfull, "joro", "pesho", 1); Transaction tx3 = new Transaction(4, TransactionStatus.Successfull, "joro", "pesho", 15.6); Transaction tx4 = new Transaction(3, TransactionStatus.Successfull, "joro", "pesho", 15.6); Transaction tx5 = new Transaction(8, TransactionStatus.Failed, "joro", "pesho", 17.8); List <Transaction> expected = new List <Transaction>() { tx5, tx4, tx3, tx2, tx1 }; //Act cb.Add(tx1); cb.Add(tx3); cb.Add(tx2); cb.Add(tx4); cb.Add(tx5); //Assert List <Transaction> actual = cb.GetByReceiverOrderedByAmountThenById("pesho").ToList(); CollectionAssert.AreEqual(expected, actual); }
public void GetByReceiver_ShouldThrow_On_EmptyCB() { //Arrange IChainblock cb = new Chainblock(); //Act //Assert Assert.Throws <InvalidOperationException>(() => { cb.GetByReceiverOrderedByAmountThenById("pesho"); }); }
public void GetByReceiver_On_NonExisting_Receiver_ShouldThrow() { //Arrange IChainblock cb = new Chainblock(); Transaction tx1 = new Transaction(2, TransactionStatus.Successfull, "joro", "pesho", 1); Transaction tx2 = new Transaction(1, TransactionStatus.Successfull, "joro", "mesho", 1); Transaction tx3 = new Transaction(4, TransactionStatus.Successfull, "joro", "kalin", 15.6); Transaction tx4 = new Transaction(3, TransactionStatus.Successfull, "joro", "pesho", 15.6); Transaction tx5 = new Transaction(8, TransactionStatus.Failed, "joro", "barko", 17.8); //Act cb.Add(tx1); cb.Add(tx3); cb.Add(tx2); cb.Add(tx4); cb.Add(tx5); //Assert Assert.Throws <InvalidOperationException>(() => { cb.GetByReceiverOrderedByAmountThenById("mecho"); }); }
public void GetByReceiverOrderedByAmountThenById_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(), "to", i); cb.Add(tx); txs.Add(tx); } int count = cb.Count; txs = txs.OrderByDescending(x => x.Amount).ThenBy(x => x.Id).ToList(); Assert.AreEqual(100000, count); Stopwatch watch = new Stopwatch(); watch.Start(); IEnumerable <Transaction> all = cb.GetByReceiverOrderedByAmountThenById("to"); int c = 0; foreach (Transaction tx in all) { Assert.AreSame(tx, txs[c]); c++; } watch.Stop(); long l1 = watch.ElapsedMilliseconds; Assert.IsTrue(l1 < 200); Assert.AreEqual(100000, c); }
public void GetByReceiverOrderedByAmountThenById_ThrowsException_WhenReceiverDoesNotExist() { Assert.Throws <InvalidOperationException>(() => testChainblock.GetByReceiverOrderedByAmountThenById("Pulio")); }
public void GetByReceiverOrderedByAmountThenById_ShouldThrowInvalidOperationException() { Assert.Throws <InvalidOperationException>( () => chainblock.GetByReceiverOrderedByAmountThenById("Drago") ); }