예제 #1
0
        public void ParseData_InvalidDataTooShort_ThrowsException()
        {
            byte[] data;

            data = HelperFunctions.ConvertHex(cDATA_INVALID);
            TransactionParser.Parse(data);
        }
예제 #2
0
        public void ParserParsesDebitTransaction()
        {
            var parser       = new TransactionParser(TransactionTestData.ValidTransactionLineWithDebitAmount);
            var transactions = parser.Parse();

            Assert.AreEqual(-3.52M, transactions[0].Amount);
        }
예제 #3
0
        public void ParserCanParseMultipleTransactions()
        {
            var parser       = new TransactionParser(TransactionTestData.TwoValidTransactions);
            var transactions = parser.Parse();

            Assert.AreEqual(2, transactions.Count);
        }
예제 #4
0
        public IList <ITransaction> GetTransactionHistory(string address, int num)
        {
            IList <ITransaction> result = new List <ITransaction>();

            if (num <= 0)
            {
                return(result);
            }
            string url  = string.Format("{0}/transactions/address/{1}/limit/{2}", NodeUrl, address, num);
            string json = HttpHelper.Get(url);

            try
            {
                List <List <object> > list = JsonConvert.DeserializeObject <List <List <object> > >(json);
                if (list.Count == 0)
                {
                    return(result);
                }
                List <object> txList = list[0];
                foreach (object txObj in txList)
                {
                    string       txStr = JsonConvert.SerializeObject(txObj);
                    ITransaction tx    = TransactionParser.Parse(txStr);
                    result.Add(tx);
                }
            }
            catch (Exception)
            {
                throw ApiError.FromJson(json);
            }
            return(result);
        }
예제 #5
0
        public void CanParseTransactionXml()
        {
            Transaction transaction = TransactionParser.Parse(_xml);

            CheckIf.EqualId("419124c2108f39c94378c488dda67348", transaction.Id, "Transaction id should be parsed");
            Assert.AreEqual("RUB", transaction.Currency, "Transaction currency should be parsed");

            Assert.AreEqual(
                new DateTimeOffset(2013, 12, 9, 23, 00, 00, new TimeSpan(3, 0, 0)),
                transaction.Posted,
                "Transaction posted date should be parsed");

            Assert.AreEqual(
                new DateTimeOffset(2014, 1, 6, 15, 30, 21, new TimeSpan(3, 0, 0)),
                transaction.Entered,
                "Transaction entered date should be parsed");

            Assert.AreEqual("Обои (отдавать маме)", transaction.Description, "Transaction description should be parsed");

            Assert.AreEqual(2, transaction.Splits.Count, "Transaction splits should be parsed");

            AssertSplitValues(
                "e739f02a5e4ced52a8974292d183727f", "b43f593c319ae9bf475ddb2af3953b38", 10000.00m, 10000.00m,
                transaction.Splits[0]);

            AssertSplitValues(
                "0db32508c93b252e0acb168787d82289", "f7e5c9bd34d8cd881f481d837d98f94d", -10000.00m, -10000.00m,
                transaction.Splits[1]);
        }
예제 #6
0
        public void ParserThrowsArgumentExceptionWhenParsingEmptyTransactions(string invalidInputTransaction)
        {
            var parser = new TransactionParser(invalidInputTransaction);

            _ = Assert.Throws <ArgumentException>(
                delegate { parser.Parse(); });
        }
예제 #7
0
        public void ParserParsesDescription()
        {
            var parser = new TransactionParser(TransactionTestData.ValidTransactionLineWithDebitAmount);

            var transactions = parser.Parse();

            Assert.AreEqual("ACME Company", transactions[0].Description);
        }
예제 #8
0
        public void ParserSkipsEmptyLine()
        {
            var parser = new TransactionParser(TransactionTestData.ValidTransactionLineWithDebitAmount + Environment.NewLine);

            var transactions = parser.Parse();

            Assert.AreEqual(1, transactions.Count);
        }
예제 #9
0
        public void ParserReadsLine()
        {
            var parser = new TransactionParser(TransactionTestData.ValidTransactionLineWithDebitAmount);

            var transactions = parser.Parse();

            Assert.AreEqual(1, transactions.Count);
        }
예제 #10
0
        public void ParseStream_EmptyData_ThrowsException()
        {
            MemoryStream stream = new MemoryStream {
                Capacity = 0
            };

            TransactionParser.Parse(stream);
        }
예제 #11
0
        public void ParserParsesTransactionDate()
        {
            var parser = new TransactionParser(TransactionTestData.ValidTransactionLineWithDebitAmount);

            var transactions = parser.Parse();

            Assert.AreEqual(new DateTime(2020, 12, 18), transactions[0].Date);
        }
예제 #12
0
        public void ParseStream_InvalidDataTooShort_ThrowsException()
        {
            byte[]       data;
            MemoryStream stream;

            data   = HelperFunctions.ConvertHex(cDATA_INVALID);
            stream = new MemoryStream(data);
            TransactionParser.Parse(stream);
        }
예제 #13
0
        public void ParseData_ValidData_IsValid()
        {
            byte[]      data;
            Transaction result;

            data   = HelperFunctions.ConvertHex(cDATA_VALID_1_1);
            result = TransactionParser.Parse(data);
            Assert.IsNotNull(result);
            Assert.AreEqual(result.Inputs.Count, 1);
            Assert.AreEqual(result.LockTime.Type, LockTimeType.NoLockTime);
            Assert.AreEqual(result.Outputs.Count, 1);
            Assert.AreEqual(result.Version, 1);
        }
예제 #14
0
        public ITransaction GetUnconfirmedTransactionById(string txId)
        {
            string url  = string.Format("{0}/transactions/unconfirmed/info/{1}", NodeUrl, txId);
            string json = HttpHelper.Get(url);

            try
            {
                return(TransactionParser.Parse(json));
            }
            catch (Exception)
            {
                throw TransactionError.FromJson(json);
            }
        }
예제 #15
0
        public ITransaction GetTransactionById(string txId)
        {
            string       url  = string.Format("{0}/transactions/info/{1}", NodeUrl, txId);
            string       json = HttpHelper.Get(url);
            ITransaction tx;

            try
            {
                tx = TransactionParser.Parse(json);
            }
            catch (Exception)
            {
                throw TransactionError.FromJson(json);
            }
            if (tx != null && tx.Status.Equals("error"))
            {
                throw TransactionError.FromJson(json);
            }
            return(tx);
        }
예제 #16
0
 public void ParseData_EmptyData_ThrowsException()
 {
     TransactionParser.Parse(new byte[0]);
 }
예제 #17
0
 public void ParseData_NullData_ThrowsException()
 {
     TransactionParser.Parse(null as byte[]);
 }
예제 #18
0
 public void ParseStream_NullData_ThrowsException()
 {
     TransactionParser.Parse(null as Stream);
 }