Beispiel #1
0
    public void GetAllSendersWithTransactionStatus_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.GetAllSendersWithTransactionStatus(TransactionStatus.Failed);
        });
    }
    public void GetAllSendersWithTransactionStatus_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, "boro", "pesho", 15.6);
        Transaction   tx5      = new Transaction(15, TransactionStatus.Unauthorized, "moro", "pesho", 7.8);
        List <string> expected = new List <string>()
        {
            "boro", "moro"
        };

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

        //Assert
        CollectionAssert.AreEqual(expected, actual);
    }
Beispiel #3
0
    public void GetAllSendersWithTransactionStatus_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 (TS == TransactionStatus.Successfull)
            {
                txs.Add(tx);
            }
        }
        txs.Reverse();
        int count = cb.Count;

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

        watch.Start();

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

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

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

        Assert.Less(l1, 150);
        Assert.AreEqual(txs.Count, c);
    }
Beispiel #4
0
    static void Main(string[] args)
    {
        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
        var res = cb.GetAllSendersWithTransactionStatus(TransactionStatus.Unauthorized);
    }
Beispiel #5
0
    public void GetAllSendersWithTransactionStatus_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.GetAllSendersWithTransactionStatus(TransactionStatus.Unauthorized)
            );
    }
Beispiel #6
0
 public void GetAllSendersWithTransactionStatus_ThrowsException_WhenEmpty()
 {
     Assert.Throws <InvalidOperationException>(() => testChainblock.GetAllSendersWithTransactionStatus(TransactionStatus.Aborted));
 }
Beispiel #7
0
 public void GetAllSendersWithTransactionStatus_ShouldThrowInvalidOperationException()
 {
     Assert.Throws <InvalidOperationException>(
         () => chainblock.GetAllSendersWithTransactionStatus(TransactionStatus.Aborted)
         );
 }