public void Coun_TwoTransactions_ShouldReturnTrue()
        {
            ITransaction transactionTwo = new Transaction(2, "X", "Z", 1, TransactionStatus.Aborted);
            IChainblock  chainblock     = new Chainblock(transactionTwo, this.transactionOne);

            Assert.AreEqual(2, chainblock.Count);
        }
        public void ContainsId_ExistingCollection_ShoudReturnTrue()
        {
            IChainblock chainblock = new Chainblock(this.transactionOne);
            bool        actualRes  = chainblock.Contains(1);

            Assert.IsTrue(actualRes);
        }
Exemple #3
0
    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();
        });
    }
Exemple #4
0
    public void GetByReceiver_ShouldWorkCorrectly()
    {
        //Arrange
        IChainblock        cb       = new Chainblock();
        Transaction        tx1      = new Transaction(2, TransactionStatus.Successfull, "joro", "pesho", 1);
        Transaction        tx2      = new Transaction(1, TransactionStatus.Successfull, "joro", "pesho", 1);
        Transaction        tx3      = new Transaction(4, TransactionStatus.Successfull, "joro", "pesho", 15.6);
        Transaction        tx4      = new Transaction(3, TransactionStatus.Successfull, "joro", "pesho", 15.6);
        Transaction        tx5      = new Transaction(8, TransactionStatus.Failed, "joro", "pesho", 17.8);
        List <Transaction> expected = new List <Transaction>()
        {
            tx5, tx4, tx3, tx2, tx1
        };

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

        CollectionAssert.AreEqual(expected, actual);
    }
Exemple #5
0
    public void GetByTransactionStatus_ShouldReturnCorrectResult()
    {
        //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.Failed, "valq", "pesho", 15.6);
        Transaction        tx5      = new Transaction(8, TransactionStatus.Successfull, "valq", "pesho", 17.8);
        List <Transaction> expected = new List <Transaction>()
        {
            tx5, tx3, tx1, tx2
        };

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

        CollectionAssert.AreEqual(expected, actual);
    }
        public void ContainsId_EmptyCollection_ShoudReturnFalse()
        {
            IChainblock chainblock = new Chainblock();
            bool        actualRes  = chainblock.Contains(1);

            Assert.IsFalse(actualRes);
        }
        public void ContainsTransaction_EmptyCollection_ShoudReturnFalse()
        {
            IChainblock chainblock = new Chainblock();
            bool        actualRes  = chainblock.Contains(this.transactionOne);

            Assert.IsFalse(actualRes);
        }
Exemple #8
0
    public void GetInAmountRange_ShouldReturn_CorrectTransactionsByInsertionOrder()
    {
        //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>()
        {
            tx4, tx5
        };

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

        //Assert
        CollectionAssert.AreEqual(expected, actual);
    }
Exemple #9
0
    public void GetByReceiverAndAmountRange_ShouldWorkCorrectly_On_CorrectRange()
    {
        //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", "resho", 7.8);
        List <Transaction> expected = new List <Transaction>()
        {
            tx4, tx2, tx3, tx1
        };

        //Act
        cb.Add(tx1);
        cb.Add(tx3);
        cb.Add(tx2);
        cb.Add(tx4);
        cb.Add(tx5);
        //Assert
        List <Transaction> actual = cb.GetByReceiverAndAmountRange("pesho", 0, 20).ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
        public void ChangeTransactionStatus_NotExistingTransaction_ShouldThrowArgumentException()
        {
            IChainblock chainblock = new Chainblock(this.transactionOne);

            Assert.Throws <ArgumentException>(() =>
                                              chainblock.ChangeTransactionStatus(2, TransactionStatus.Aborted));
        }
Exemple #11
0
    public void GetByTransactionStatusAndMaximumAmount_ShouldWorkCorrectly()
    {
        //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.Successfull, "valq", "pesho", 17.8);
        List <Transaction> expected = new List <Transaction>()
        {
            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
                                    .GetByTransactionStatusAndMaximumAmount(TransactionStatus.Successfull, 17.0)
                                    .ToList();

        CollectionAssert.AreEqual(expected, actual);
    }
Exemple #12
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);
        });
    }
Exemple #13
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);
    }
Exemple #14
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));
    }
Exemple #15
0
    public void GetAllOrderedByAmountDescendingThenById_ShouldWorkCorrectly()
    {
        //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>()
        {
            tx4, tx5, tx2, tx3, tx1
        };

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

        //Assert
        CollectionAssert.AreEqual(expected, actual);
    }
Exemple #16
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);
    }
Exemple #17
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);
    }
Exemple #18
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);
    }
    public void GetByTransactionStatusAndMaximumAmount_ShouldReturnEmptyCollection()
    {
        //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);
        //Assert
        List <Transaction> actual = cb
                                    .GetByTransactionStatusAndMaximumAmount(TransactionStatus.Unauthorized, 5)
                                    .ToList();

        CollectionAssert.AreEqual(new List <Transaction>(), actual);
        cb     = new Chainblock();
        actual = cb
                 .GetByTransactionStatusAndMaximumAmount(TransactionStatus.Unauthorized, 10)
                 .ToList();
        CollectionAssert.AreEqual(new List <Transaction>(), actual);
    }
Exemple #20
0
    public void GetOrderedByAmountDescendingThenById_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,
                                             i.ToString(), i.ToString(), i);
            cb.Add(tx);
            txs.Add(tx);
        }

        int count = cb.Count;

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

        watch.Start();

        IEnumerable <Transaction> all = cb.GetAllOrderedByAmountDescendingThenById();
        int c = 0;

        foreach (Transaction tx in all)
        {
            c++;
        }

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

        Assert.IsTrue(l1 < 150);
        Assert.AreEqual(100000, c);
    }
    public void Add_100000_Transactions_Should_WorkFast()
    {
        IChainblock cb    = new Chainblock();
        Stopwatch   sw    = new Stopwatch();
        int         count = 100_000;

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

        sw.Start();
        for (int i = 0; i < count; i++)
        {
            //int status = rand.Next(0, 4);
            cb.Add(new Transaction(i, TransactionStatus.Successfull,
                                   i.ToString(), i.ToString(), i));
        }

        sw.Stop();
        Assert.AreEqual(count, cb.Count);
        Assert.IsTrue(sw.ElapsedMilliseconds < 400);
    }
Exemple #22
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 ContainsId_NotExistingCollection_ShoudReturnFalse()
        {
            ITransaction transactionTwo = new Transaction(2, "X", "Z", 1, TransactionStatus.Aborted);
            IChainblock  chainblock     = new Chainblock(transactionOne);
            bool         actualRes      = chainblock.Contains(2);

            Assert.IsFalse(actualRes);
        }
        public void ContainsTransaction_ExistingCollection_ShoudReturnTrue()
        {
            ITransaction transactionTwo = new Transaction(1, "X", "Z", 1, TransactionStatus.Aborted);
            IChainblock  chainblock     = new Chainblock(transactionTwo);
            bool         actualRes      = chainblock.Contains(this.transactionOne);

            Assert.IsTrue(actualRes);
        }
        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);
        }
Exemple #27
0
    public void Count_Should_Be_0_On_EmptyCollection()
    {
        //Arrange
        IChainblock cb = new Chainblock();

        //Act
        //Assert
        Assert.AreEqual(0, cb.Count);
    }
        public void GetById_EmptyCollection_ShouldThrowInvalidOperationException()
        {
            IChainblock chainblock = new Chainblock();

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

            Assert.AreEqual(NotExistingTransactionId, ex.Message);
        }
Exemple #29
0
    public void GetById_On_Empty_Chainblock_ShouldThrow()
    {
        //Arrange
        IChainblock cb = new Chainblock();

        //Act
        //Assert
        Assert.Throws <InvalidOperationException>(() => cb.GetById(5));
    }
        public void ChangeTransactionStatus_NonExistingTransaction_ShouldThrowArgumentException()
        {
            IChainblock chainblock = new Chainblock();

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

            Assert.AreEqual(NotExistingTransactionId, ex.Message);
        }