public void GetByReceiverAndAmountRange_ShouldWorkCorrectly_On_CorrectRange() { //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.Failed, "joro", "resho", 7.8); List <Transaction> expected = new List <Transaction>() { tx4, tx2, tx3, tx1 }; //Act cb.Add(tx1); cb.Add(tx3); cb.Add(tx2); cb.Add(tx4); cb.Add(tx5); //Assert List <Transaction> actual = cb.GetByReceiverAndAmountRange("pesho", 0, 20).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void GetByRceiver_ShouldReturnCorrectRange_CorrectlyOrdered() { //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.GetByReceiverAndAmountRange("pesho", 0, 20).ToList(); CollectionAssert.AreEqual(expected, actual); }
public void GetByReceiverAndAmountRange_ShouldThrow_On_EmptyCB() { //Arrange IChainblock cb = new Chainblock(); //Act //Assert Assert.Throws <InvalidOperationException>(() => { cb.GetByReceiverAndAmountRange("pesho", 0, 20).ToList(); }); }
public void GetByReceiverAndAmountRange_ShouldThrow_AfterRemovingReceiver() { //Arrange IChainblock cb = new Chainblock(); Transaction tx1 = new Transaction(5, TransactionStatus.Successfull, "joro", "pesho", 1); Transaction tx2 = new Transaction(6, TransactionStatus.Successfull, "joro", "mesho", 5.5); Transaction tx3 = new Transaction(7, TransactionStatus.Successfull, "joro", "vesho", 5.5); //Act cb.Add(tx1); cb.Add(tx3); cb.Add(tx2); cb.RemoveTransactionById(5); //Assert Assert.Throws <InvalidOperationException>(() => { cb.GetByReceiverAndAmountRange("pesho", 0, 20).ToList(); }); }
public void GetByReceiverAndAmountRange() { 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", "from", amount); cb.Add(tx); if (amount >= 200 && amount < 600) { txs.Add(tx); } } txs = txs.OrderByDescending(x => x.Amount).ThenBy(x => x.Id).ToList(); int count = cb.Count; Assert.AreEqual(100000, count); Stopwatch watch = new Stopwatch(); watch.Start(); IEnumerable <Transaction> all = cb.GetByReceiverAndAmountRange( "from", 200, 600); 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 GetByReceiverAndAmountRange_ThrowsException_WhenThereAreNoMatches(string receiver, double minimum, double maximum) { CreateBulkOfTransactions(); Assert.Throws <InvalidOperationException>(() => testChainblock.GetByReceiverAndAmountRange(receiver, minimum, maximum)); }
public void GetByReceiverAndAmountRange_ShouldThrowInvalidOperationException() { Assert.Throws <InvalidOperationException>( () => chainblock.GetByReceiverAndAmountRange("Drago", 10, 100) ); }