public void ChangeTransactionStatus_NotExistingTransaction_ShouldThrowArgumentException()
        {
            IChainblock chainblock = new Chainblock(this.transactionOne);

            Assert.Throws <ArgumentException>(() =>
                                              chainblock.ChangeTransactionStatus(2, TransactionStatus.Aborted));
        }
        public void ChangeTransactionStatus_NonExistingTransaction_ShouldThrowArgumentException()
        {
            IChainblock chainblock = new Chainblock();

            Exception ex = Assert.Throws <ArgumentException>(() =>
                                                             chainblock.ChangeTransactionStatus(1, TransactionStatus.Aborted));

            Assert.AreEqual(NotExistingTransactionId, ex.Message);
        }
        public void ChangeTransactionStatus_ExistingTransaction_ShouldChangeStatus(TransactionStatus transactionStatus)
        {
            IChainblock chainblock = new Chainblock(this.transactionOne);

            chainblock.ChangeTransactionStatus(1, transactionStatus);

            TransactionStatus actualStatus = this.transactionOne.Status;

            Assert.AreEqual(transactionStatus, actualStatus);
        }
Example #4
0
    public void ChangeTransactionStatus_On_NonExistingTranasction_ShouldThrow()
    {
        //Arrange
        IChainblock cb = new Chainblock();

        //Act
        //Assert
        Assert.Throws <ArgumentException>(
            () => cb.ChangeTransactionStatus(6, TransactionStatus.Failed)
            );
    }
Example #5
0
    public void ChangeTransactionStatus_OnMultipleTransactions_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);
        cb.ChangeTransactionStatus(7, TransactionStatus.Unauthorized);
        cb.ChangeTransactionStatus(5, TransactionStatus.Aborted);
        cb.ChangeTransactionStatus(6, TransactionStatus.Successfull);
        //Assert
        Assert.AreEqual(3, cb.Count);
        Assert.AreEqual(tx1.Status, TransactionStatus.Aborted);
        Assert.AreEqual(tx3.Status, TransactionStatus.Unauthorized);
        Assert.AreEqual(tx2.Status, TransactionStatus.Successfull);
    }
Example #6
0
    public void ChangeTransactionStatus_ShouldWorkCorrectly_On_ExistingTX()
    {
        //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.ChangeTransactionStatus(5, TransactionStatus.Aborted);
        //Assert
        Assert.AreEqual(TransactionStatus.Aborted, tx1.Status);
        Assert.AreEqual(3, cb.Count);
    }
Example #7
0
    public void ChangeTransactionStatus_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 < 90000; i++)
        {
            int         amount = rand.Next(0, 50000);
            int         status = amount % 4;
            Transaction tx     = new Transaction(i, statuses[status],
                                                 i.ToString(), i.ToString(), amount);
            cb.Add(tx);
            txs.Add(tx);
        }

        int count = cb.Count;

        Assert.AreEqual(90000, count);

        Stopwatch watch = new Stopwatch();

        watch.Start();

        foreach (Transaction tx in txs)
        {
            int status = rand.Next(0, 4);
            cb.ChangeTransactionStatus(tx.Id, statuses[status]);
        }

        watch.Stop();
        long l1 = watch.ElapsedMilliseconds;

        Assert.Less(l1, 330);
    }
Example #8
0
        public void ChangeTransactionStatus_ThrowsArgumentException_WhenDoesNotExist()
        {
            int ID = 1;

            Assert.Throws <ArgumentException>(() => testChainblock.ChangeTransactionStatus(ID, TransactionStatus.Failed));
        }
Example #9
0
 public void ChangeTransactionStatus_NonExistingTransactionShouldThrowInvalidOperationException()
 {
     Assert.Throws <InvalidOperationException>(
         () => chainblock.ChangeTransactionStatus(12, TransactionStatus.Failed)
         );
 }
Example #10
0
 public void ChangeTransactionStatusShouldThrowExceptionIfTransactionDesntExist()
 {
     //Assert
     Assert.That(() => chainblock.ChangeTransactionStatus(10, TransactionStatus.Failed),
                 Throws.ArgumentException.With.Message.EqualTo("Transaction doesn't exist."));
 }