public void GetById_EmptyCollection_ShouldThrowInvalidOperationException() { IChainblock chainblock = new Chainblock(); Exception ex = Assert.Throws <InvalidOperationException>(() => chainblock.GetById(1)); Assert.AreEqual(NotExistingTransactionId, ex.Message); }
public void GetById_On_Empty_Chainblock_ShouldThrow() { //Arrange IChainblock cb = new Chainblock(); //Act //Assert Assert.Throws <InvalidOperationException>(() => cb.GetById(5)); }
public void GetById_On_ExistingElement_ShouldWorkCorrectly() { //Arrange IChainblock cb = new Chainblock(); Transaction tx1 = new Transaction(5, TransactionStatus.Successfull, "joro", "pesho", 5); Transaction tx2 = new Transaction(6, TransactionStatus.Successfull, "joro", "pesho", 5); Transaction tx3 = new Transaction(7, TransactionStatus.Successfull, "joro", "pesho", 5); //Act cb.Add(tx1); cb.Add(tx2); cb.Add(tx3); //Assert Assert.AreSame(tx1, cb.GetById(5)); Assert.AreNotSame( new Transaction(53, TransactionStatus.Failed, "a", "b", 5), cb.GetById(7) ); }
public void GetById_ExistingTransaction_ShouldReturnCorrectTransaction(int id) { ITransaction transaction = new Transaction(id, "x", "z", 1, TransactionStatus.Aborted); IChainblock chainblock = new Chainblock(transaction); ITransaction actualTransaction = chainblock.GetById(id); Assert.AreEqual(id, actualTransaction.Id); }
public void GetById_AddThreeTransactionsWithExistingTransaction_ShouldReturnCorrectTransaction() { ITransaction transactionTwo = new Transaction(2, "X", "Z", 1, TransactionStatus.Aborted); ITransaction transactionThree = new Transaction(5, "i", "p", 1, TransactionStatus.Unauthorized); IChainblock chainblock = new Chainblock(this.transactionOne, transactionTwo, transactionThree); ITransaction actualTransaction = chainblock.GetById(2); Assert.AreEqual(2, actualTransaction.Id); }
public void GetById_On_NonExistingElement_ShouldThrow() { //Arrange IChainblock cb = new Chainblock(); Transaction tx1 = new Transaction(5, TransactionStatus.Successfull, "joro", "pesho", 5); Transaction tx2 = new Transaction(6, TransactionStatus.Successfull, "joro", "pesho", 5); Transaction tx3 = new Transaction(7, TransactionStatus.Successfull, "joro", "pesho", 5); //Act cb.Add(tx1); cb.Add(tx2); cb.Add(tx3); cb.RemoveTransactionById(5); //Assert Assert.Throws <InvalidOperationException>(() => cb.GetById(5)); }
public void Count_Should_RemainCorrect_AfterRemoving() { //Arrange IChainblock cb = new Chainblock(); Transaction tx1 = new Transaction(5, TransactionStatus.Successfull, "joro", "pesho", 5); Transaction tx2 = new Transaction(6, TransactionStatus.Successfull, "joro", "pesho", 5); Transaction tx3 = new Transaction(7, TransactionStatus.Successfull, "joro", "pesho", 5); //Act cb.Add(tx1); cb.Add(tx2); cb.Add(tx3); cb.RemoveTransactionById(tx1.Id); cb.RemoveTransactionById(tx3.Id); //Assert Assert.AreEqual(1, cb.Count); Assert.AreNotSame(tx1, cb.GetById(tx2.Id)); }
public void GetById_ShouldWorkFast() { IChainblock cb = new Chainblock(); TransactionStatus[] statuses = new TransactionStatus[] { TransactionStatus.Aborted, TransactionStatus.Failed, TransactionStatus.Successfull, TransactionStatus.Unauthorized }; Random rand = new Random(); List <Transaction> txs = new List <Transaction>(); for (int i = 0; i < 100000; i++) { int status = rand.Next(0, 4); Transaction tx = new Transaction(i, statuses[status], 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(); foreach (Transaction tx in txs) { Assert.AreSame(tx, cb.GetById(tx.Id)); } watch.Stop(); long l1 = watch.ElapsedMilliseconds; Assert.IsTrue(l1 < 150); }
public void GetById_ThrowsException_WhenIdDoesNotExist() { int ID = 1; Assert.Throws <InvalidOperationException>(() => testChainblock.GetById(ID)); }
public void GetById_InvalidIdShouldThrowInvalidOperationException() { Assert.Throws <InvalidOperationException>(() => chainblock.GetById(22)); }