示例#1
0
    public void GetAllReceiversWithTransactionStatus_ShouldWorkCorrectly()
    {
        //Arrange
        IChainblock   cb       = new Chainblock();
        Transaction   tx1      = new Transaction(5, TransactionStatus.Successfull, "joro", "pesho", 1);
        Transaction   tx2      = new Transaction(6, TransactionStatus.Aborted, "joro", "pesho", 5.5);
        Transaction   tx3      = new Transaction(7, TransactionStatus.Successfull, "joro", "pesho", 5.5);
        Transaction   tx4      = new Transaction(12, TransactionStatus.Unauthorized, "joro", "pesho", 15.6);
        Transaction   tx5      = new Transaction(15, TransactionStatus.Unauthorized, "moro", "vesho", 7.8);
        List <string> expected = new List <string>()
        {
            "pesho", "vesho"
        };

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        List <string> actual = cb
                               .GetAllReceiversWithTransactionStatus(TransactionStatus.Unauthorized)
                               .ToList();

        //Assert
        CollectionAssert.AreEqual(expected, actual);
    }
示例#2
0
    public void GetAllReceiversWithTransactionStatus_ShoudlThrowAfterRemove()
    {
        //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", "pesho", 7.8);

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        cb.RemoveTransactionById(5);
        cb.RemoveTransactionById(7);
        cb.RemoveTransactionById(6);
        cb.RemoveTransactionById(12);
        cb.RemoveTransactionById(15);
        //Assert
        Assert.Throws <InvalidOperationException>(() =>
        {
            cb.GetAllReceiversWithTransactionStatus(TransactionStatus.Failed);
        });
    }
示例#3
0
    public void GetAllReceiversWithTransactionStatus_ShouldWorkFast()
    {
        IChainblock        cb  = new Chainblock();
        List <Transaction> txs = new List <Transaction>();

        TransactionStatus[] statuses = new TransactionStatus[]
        {
            TransactionStatus.Aborted,
            TransactionStatus.Failed,
            TransactionStatus.Successfull,
            TransactionStatus.Unauthorized
        };
        Random    rand = new Random();
        Stopwatch sw   = new Stopwatch();

        for (int i = 0; i < 100000; i++)
        {
            int status           = rand.Next(0, 4);
            TransactionStatus TS = statuses[status];
            Transaction       tx = new Transaction(i, TS,
                                                   i.ToString(), i.ToString(), i);
            cb.Add(tx);
            if (status == 2)
            {
                txs.Add(tx);
            }
        }
        txs.Reverse();
        int count = cb.Count;

        Assert.AreEqual(100000, count);
        Stopwatch watch = new Stopwatch();

        watch.Start();

        IEnumerable <string> all = cb.GetAllReceiversWithTransactionStatus(TransactionStatus.Successfull);
        int c = 0;

        foreach (string tx in all)
        {
            Assert.AreEqual(tx, txs[c].To);
            c++;
        }

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

        Assert.Less(l1, 150);
        Assert.AreEqual(txs.Count, c);
    }
示例#4
0
    public void GetAllReceiversWithTransactionStatus_OnNonExistantTxs_ShouldThrow()
    {
        //Arrange
        IChainblock cb  = new Chainblock();
        Transaction tx1 = new Transaction(5, TransactionStatus.Successfull, "joro", "pesho", 1);
        Transaction tx2 = new Transaction(6, TransactionStatus.Aborted, "joro", "pesho", 5.5);
        Transaction tx3 = new Transaction(7, TransactionStatus.Aborted, "joro", "pesho", 5.5);
        Transaction tx4 = new Transaction(12, TransactionStatus.Failed, "joro", "pesho", 15.6);
        Transaction tx5 = new Transaction(15, TransactionStatus.Successfull, "joro", "pesho", 7.8);

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        //Assert
        Assert.Throws <InvalidOperationException>(
            () => cb.GetAllReceiversWithTransactionStatus(TransactionStatus.Unauthorized)
            );
    }
示例#5
0
 public void GetAllReceiversWithTransactionStatus_ThrowsException_WhenNoMatches()
 {
     Assert.Throws <InvalidOperationException>(() => testChainblock.GetAllReceiversWithTransactionStatus(TransactionStatus.Unauthorized));
 }
示例#6
0
 public void GetAllReceiversWithTransactionStatus_ShouldThrowInvalidOperationException()
 {
     Assert.Throws <InvalidOperationException>(
         () => chainblock.GetAllReceiversWithTransactionStatus(TransactionStatus.Aborted)
         );
 }