Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
C#
public partial class Loan
    {
        public virtual PledgePriceChange InitPledgePriceChangeDocument(PledgePriceChange document)
        {
            if (document == null)
                document = new PledgePriceChange();

            if (document.TranDate == default(DateTime))
            {
                document.TranDate = _core.TransactionDate();
            }
            document.CurrencyId = _config.DefaultCurrencyId;
            document.DocTypeId = DocumentType.PledgePriceChange;

            var plegde = _db.PledgeSales.Include(x => x.PledgeSaleJewelry)
                                        .Include(x => x.Items.Select(i => i.PledgeSaleJewelry))
                            .SingleOrDefault(x => x.Num == document.PledgeNum);

            if (plegde == null)
                throw BankCore.CreateException(String.Format("Pledge {0} does not exisis",
                                               document.PledgeNum));

            plegde.Price = _core.SubAccBalByConnection(plegde.SubAccountId,
                                 AccConnection.PledgePrice, document.TranDate);
            foreach (var item in plegde.Items)
            {
                item.Price = _core.SubAccBalByConnection(item.SubAccountId,
                                 AccConnection.PledgePrice, document.TranDate);
            }

            document.Jewelry = (JewelrySale)plegde;

            return document;
        }
Posted
Updated 27-Aug-14 0:45am
v3

1 solution

To write unit test you should :

1) Define what the correct input and output combinations should be.
2) Write tests for each combination.

Since your class is domain specific there is little we can help you with, try contacting the designer of the class or your supervisor.

To write tests, you have to say which testing framework you are using first.
Unit Testing Using NUnit[^]

http://stackoverflow.com/questions/16415229/how-do-i-add-a-mstest-unit-test-support-to-a-c-sharp-application[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900