예제 #1
0
        public void GetBySenderOrderedByAmountDescending_ReturnsCorrectly()
        {
            CreateBulkOfTransactions();

            string sender = "Sender1";

            List <ITransaction> sendersOrdered = transactions.Values
                                                 .OrderByDescending(t => t.Amount)
                                                 .Where(t => t.From == sender)
                                                 .ToList();

            Assert.That(sendersOrdered, Is.EquivalentTo(testChainblock.GetBySenderOrderedByAmountDescending(sender)));
        }
예제 #2
0
    public void GetBySenderOrderedByAmountDescending_ShouldWorkCorrectly_OnExistingSender()
    {
        //Arrange
        IChainblock        cb       = new Chainblock();
        Transaction        tx1      = new Transaction(2, TransactionStatus.Successfull, "valq", "pesho", 14.8);
        Transaction        tx2      = new Transaction(1, TransactionStatus.Successfull, "valq", "pesho", 14.8);
        Transaction        tx3      = new Transaction(4, TransactionStatus.Successfull, "valq", "pesho", 15.6);
        Transaction        tx4      = new Transaction(3, TransactionStatus.Successfull, "valq", "pesho", 15.6);
        Transaction        tx5      = new Transaction(8, TransactionStatus.Failed, "valq", "pesho", 17.8);
        List <Transaction> expected = new List <Transaction>()
        {
            tx5, tx3, tx4, tx1, tx2
        };

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        //Assert
        List <Transaction> actual = cb.GetBySenderOrderedByAmountDescending("valq").ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
예제 #3
0
파일: Test42.cs 프로젝트: player200/SoftUni
    public void GetBySenderOrderedByAmountDescending_ShouldOn_MissingSender()
    {
        //Arrange
        IChainblock cb  = new Chainblock();
        Transaction tx1 = new Transaction(2, TransactionStatus.Successfull, "valq", "pesho", 14.8);
        Transaction tx2 = new Transaction(1, TransactionStatus.Successfull, "valq", "pesho", 14.8);
        Transaction tx3 = new Transaction(4, TransactionStatus.Successfull, "valq", "pesho", 15.6);
        Transaction tx4 = new Transaction(3, TransactionStatus.Successfull, "valq", "pesho", 15.6);
        Transaction tx5 = new Transaction(8, TransactionStatus.Failed, "valq", "pesho", 17.8);

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        cb.RemoveTransactionById(8);
        cb.RemoveTransactionById(3);
        //Assert
        Assert.Throws <InvalidOperationException>(() =>
        {
            List <Transaction> actual = cb
                                        .GetBySenderOrderedByAmountDescending("momo")
                                        .ToList();
        });
    }
예제 #4
0
    public void GetBySenderOrderedByAmountDescending_ShouldWorkFast()
    {
        IChainblock        cb  = new Chainblock();
        List <Transaction> txs = new List <Transaction>();

        for (int i = 0; i < 100000; i++)
        {
            Transaction tx = new Transaction(i, TransactionStatus.Successfull,
                                             "sender", i.ToString(), i);
            cb.Add(tx);
            txs.Add(tx);
        }

        int count = cb.Count;

        txs = txs.OrderByDescending(x => x.Amount).ToList();
        Assert.AreEqual(100000, count);
        Stopwatch watch = new Stopwatch();

        watch.Start();

        IEnumerable <Transaction> all = cb.GetBySenderOrderedByAmountDescending("sender");
        int c = 0;

        foreach (Transaction tx in all)
        {
            Assert.AreSame(tx, txs[c]);
            c++;
        }

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

        Assert.IsTrue(l1 < 200);
        Assert.AreEqual(100000, c);
    }
예제 #5
0
 public void GetBySenderOrderedByAmountDescending_ShouldThrowInvalidOperationException()
 {
     Assert.Throws <InvalidOperationException>(
         () => chainblock.GetBySenderOrderedByAmountDescending("Drago")
         );
 }