예제 #1
0
    public void GetAllOrderedByAmountDescendingThenById_ShouldWorkCorrectlyAfterRemove()
    {
        //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.Successfull, "joro", "pesho", 7.8);
        List <Transaction> expected = new List <Transaction>()
        {
            tx5, tx3, tx1
        };

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        List <Transaction> before = cb.GetAllOrderedByAmountDescendingThenById().ToList();

        Assert.AreEqual(5, before.Count);
        cb.RemoveTransactionById(tx4.Id);
        cb.RemoveTransactionById(tx2.Id);
        List <Transaction> actual = cb.GetAllOrderedByAmountDescendingThenById().ToList();

        //Assert
        CollectionAssert.AreEqual(expected, actual);
    }
예제 #2
0
    public void GetAllInAmountRange_ShouldReturn_EmptyCollectionOnNonExistingRange()
    {
        //Arrange
        IChainblock        cb       = new Chainblock();
        Transaction        tx1      = new Transaction(5, TransactionStatus.Successfull, "joro", "pesho", 1);
        Transaction        tx2      = new Transaction(6, TransactionStatus.Successfull, "joro", "pesho", 2);
        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.Successfull, "joro", "pesho", 7.8);
        List <Transaction> expected = new List <Transaction>();

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        List <Transaction> actual = cb.GetAllInAmountRange(7.7, 7.75).ToList();

        //Assert
        CollectionAssert.AreEqual(expected, actual);
        cb.RemoveTransactionById(12);
        cb.RemoveTransactionById(15);
        actual = cb.GetAllInAmountRange(7.8, 16).ToList();
        CollectionAssert.AreEqual(expected, actual);
    }
예제 #3
0
    public void GetBySenderAndMinimumAmountDescending_ShouldOrderAndPickCorrectly()
    {
        //Arrange
        IChainblock        cb       = new Chainblock();
        Transaction        tx1      = new Transaction(2, TransactionStatus.Successfull, "joro", "pesho", 1);
        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>()
        {
            tx3
        };

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        cb.RemoveTransactionById(8);
        cb.RemoveTransactionById(3);
        //Assert
        List <Transaction> actual = cb.GetBySenderAndMinimumAmountDescending("valq", 15.5).ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
    public void GetByTransactionStatus_ShouldReturnCorrectResultAfterRemove()
    {
        //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>()
        {
            tx3, tx1, tx2
        };

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        cb.RemoveTransactionById(8);
        cb.RemoveTransactionById(3);
        //Assert
        List <Transaction> actual = cb
                                    .GetByTransactionStatus(TransactionStatus.Successfull)
                                    .ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
예제 #5
0
파일: Test29.cs 프로젝트: player200/SoftUni
    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);
        });
    }
예제 #6
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();
        });
    }
예제 #7
0
    public void GetByTransactionStatusAndMaximumAmount_ShouldWorkCorrectly_AfterRemove()
    {
        //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>()
        {
            tx2
        };

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        cb.RemoveTransactionById(tx1.Id);
        //Assert
        List <Transaction> actual = cb
                                    .GetByTransactionStatusAndMaximumAmount(TransactionStatus.Successfull, 15.0)
                                    .ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
예제 #8
0
    public void RemoveById_ShoudlWorkFast()
    {
        IChainblock        cb   = new Chainblock();
        List <Transaction> txs  = new List <Transaction>();
        Random             rand = new Random();

        for (int i = 0; i < 100000; i++)
        {
            int         amount = rand.Next(0, 40000);
            int         status = amount % 4;
            Transaction tx     = new Transaction(i, (TransactionStatus)status,
                                                 i.ToString(), i.ToString(), amount);
            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)
        {
            cb.RemoveTransactionById(tx.Id);
        }

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

        Assert.Less(l1, 220);
    }
예제 #9
0
    public static void Main()
    {
        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>()
        //{
        //    tx2
        //};
        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        cb.RemoveTransactionById(tx1.Id);
        //Assert
        List <Transaction> actual = cb
                                    .GetByTransactionStatusAndMaximumAmount(TransactionStatus.Successfull, 15.0)
                                    .ToList();

        Console.WriteLine(cb.Count);
        Console.WriteLine(string.Join(Environment.NewLine, actual));
    }
        public void RemoveTransactionById_ExistingTransaction_ShouldChageCountToZero()
        {
            IChainblock chainblock = new Chainblock(this.transactionOne);

            chainblock.RemoveTransactionById(1);

            Assert.AreEqual(0, chainblock.Count);
        }
        public void GetById_InvalidTransaction_ShouldThrowInvalidOperationException()
        {
            IChainblock chainblock = new Chainblock(this.transactionOne);

            Exception ex = Assert.Throws <InvalidOperationException>(() =>
                                                                     chainblock.RemoveTransactionById(2));

            Assert.AreEqual(NotExistingTransactionId, ex.Message);
        }
예제 #12
0
파일: Test09.cs 프로젝트: player200/SoftUni
    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 RemoveTransactionById_EmptyCollection_ShouldThrowInvalidOperationException()
        {
            IChainblock chainblock = new Chainblock();

            Exception ex = Assert.Throws <InvalidOperationException>(() =>
                                                                     chainblock.RemoveTransactionById(1));

            Assert.AreEqual(NotExistingTransactionId, ex.Message);
        }
        public void RemoveTransactionById_AddTwoTransactionsWithExistingTransaction_ShouldChageCountToOne()
        {
            ITransaction transactionTwo =
                new Transaction(2, "X", "Z", 1, TransactionStatus.Aborted);
            IChainblock chainblock = new Chainblock(this.transactionOne, transactionTwo);

            chainblock.RemoveTransactionById(1);

            Assert.AreEqual(1, chainblock.Count);
        }
예제 #15
0
    public void CB_ShouldReturn_TransactionsInCorrectOrder_AfterDelete()
    {
        //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);
        List <Transaction> expected = new List <Transaction>()
        {
            tx2
        };

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.RemoveTransactionById(5);
        cb.RemoveTransactionById(7);
        List <Transaction> actual = cb.Take(cb.Count).ToList();

        //Assert
        CollectionAssert.AreEqual(expected, actual);
    }
        public void RemoveTransactionById_AddTwoTransactionsWithExistingTransaction_ShouldRemoveCorrectTransaction()
        {
            ITransaction transactionTwo =
                new Transaction(2, "X", "Z", 1, TransactionStatus.Aborted);
            IChainblock chainblock = new Chainblock(this.transactionOne, transactionTwo);

            int removeTrId = 1;

            chainblock.RemoveTransactionById(removeTrId);

            ITransaction actualTransaction =
                chainblock.Transactions
                .SingleOrDefault(t => t.Id == removeTrId);

            Assert.IsNull(actualTransaction);
        }
예제 #17
0
    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));
    }
예제 #18
0
파일: Test31.cs 프로젝트: player200/SoftUni
    public void GetByReceiverAndAmountRange_ShouldThrow_AfterRemovingReceiver()
    {
        //Arrange
        IChainblock cb  = new Chainblock();
        Transaction tx1 = new Transaction(5, TransactionStatus.Successfull, "joro", "pesho", 1);
        Transaction tx2 = new Transaction(6, TransactionStatus.Successfull, "joro", "mesho", 5.5);
        Transaction tx3 = new Transaction(7, TransactionStatus.Successfull, "joro", "vesho", 5.5);

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.RemoveTransactionById(5);
        //Assert
        Assert.Throws <InvalidOperationException>(() =>
        {
            cb.GetByReceiverAndAmountRange("pesho", 0, 20).ToList();
        });
    }
예제 #19
0
        public void RemoveTransactionById_ThrowsException_WhenTransactionDoesNotExist()
        {
            int ID = 1;

            Assert.Throws <InvalidOperationException>(() => testChainblock.RemoveTransactionById(ID));
        }
예제 #20
0
 public void RemoveById_NonExistingTransactionShouldThrowInvalidOperationException()
 {
     Assert.Throws <InvalidOperationException>(() => chainblock.RemoveTransactionById(2));
 }