/// <summary>
        /// to xml
        /// </summary>
        /// <returns></returns>
        public XElement ToXml()
        {
            XElement xelem = new XElement(TransDataUtils.XML_ITEM);

            // line number
            xelem.Add(new XAttribute(TransDataUtils.XML_LINE_NUM, _lineNum.ToString()));

            // account type
            xelem.Add(new XAttribute(TransDataUtils.XML_ACCOUNT_TYPE, ((char)_type).ToString()));

            // g/l account
            xelem.Add(new XAttribute(TransDataUtils.XML_GL_ACCOUNT, _glAccount.ToString()));

            // customer
            if (_customer != null)
            {
                xelem.Add(new XAttribute(TransDataUtils.XML_CUSTOMER, _customer.ToString()));
            }

            // vendor
            if (_vendor != null)
            {
                xelem.Add(new XAttribute(TransDataUtils.XML_VENDOR, _vendor.ToString()));
            }

            // amount
            xelem.Add(new XAttribute(TransDataUtils.XML_AMOUNT, _amount.ToNumber()));

            // credit debit indicator
            xelem.Add(new XAttribute(TransDataUtils.XML_CD_INDICATOR, ((char)_cdIndicator).ToString()));

            // business area
            if (_businessArea != null)
            {
                xelem.Add(new XAttribute(TransDataUtils.XML_BUSINESS_AREA,
                                         _businessArea.ToString()));
            }

            return(xelem);
        }
예제 #2
0
        public void TestMasterDataIdentity()
        {
            MasterDataIdentity test;
            // test length
            StringBuilder builder = new StringBuilder();

            for (int i = 1; i <= 10; ++i)
            {
                builder.Append('A');
                try
                {
                    test = new MasterDataIdentity(builder.ToString());
                    test.ToString();
                }
                catch (Exception e)
                {
                    Assert.Fail(e.Message);
                }
            }

            // test low case
            test = new MasterDataIdentity("abcdefg");
            Assert.AreEqual(test.ToString(), "000ABCDEFG");


            // test number
            test = new MasterDataIdentity("123456789");
            Assert.AreEqual(test.ToString(), "0123456789");

            // test '_'
            test = new MasterDataIdentity("_123456789");
            Assert.AreEqual(test.ToString(), "_123456789");


            // test equals
            MasterDataIdentity test1 = new MasterDataIdentity("123");
            MasterDataIdentity test2 = new MasterDataIdentity("123");

            Assert.AreEqual(test1, test2);
            Assert.AreEqual(test1.GetHashCode(), test2.GetHashCode());

            // zero length
            try
            {
                test = new MasterDataIdentity("");
                test.ToString();
                Assert.Fail("IdentityNoData should occur when length is zero");
            }
            catch (IdentityNoData)
            {
                // pass
            }
            catch (Exception)
            {
                Assert.Fail("IdentityNoData should occur when length is zero, but it is other exception");
            }

            // no data
            try
            {
                test = new MasterDataIdentity("00");
                test.ToString();
                Assert.Fail("IdentityNoData should occur when there is no data");
            }
            catch (IdentityNoData)
            {
                // pass
            }
            catch (Exception)
            {
                Assert.Fail("IdentityNoData should occur when length is zero, but it is other exception");
            }

            // format error
            try
            {
                test = new MasterDataIdentity("a?");
                test.ToString();
                Assert.Fail("IdentityNoData should occur when there is no data");
            }
            catch (IdentityInvalidChar)
            {
                // pass
            }
            catch (Exception)
            {
                Assert.Fail("IdentityInvalidChar should occur when length is zero, but it is other exception");
            }

            // too long
            try
            {
                test = new MasterDataIdentity("12345678901");
                test.ToString();
                Assert.Fail("IdentityNoData should occur when there is no data");
            }
            catch (IdentityTooLong)
            {
                // pass
            }
            catch (Exception)
            {
                Assert.Fail("IdentityInvalidChar should occur when length is zero, but it is other exception");
            }

            // identity for gl account
            MasterDataIdentity_GLAccount glAccountTest = new MasterDataIdentity_GLAccount(
                "113100");

            Assert.AreEqual(glAccountTest.ToString(), "0000113100");


            // identity for gl account
            // format error
            try
            {
                glAccountTest = new MasterDataIdentity_GLAccount("abcd");
                test.ToString();
                Assert.Fail("IdentityNoData should occur when there is no data");
            }
            catch (IdentityInvalidChar)
            {
                // pass
            }
            catch (Exception)
            {
                Assert.Fail("IdentityInvalidChar should occur when length is zero, but it is other exception");
            }
        }