Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / C#

Testable Applications

Rate me:
Please Sign up or sign in to vote.
3.30/5 (9 votes)
20 Apr 200712 min read 45.2K   198   35  
Make your application testable.
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using TestableApplication.Testable.Dalc;

namespace TestableApplication.Testable
{
    public partial class Invoice : IInvoice
    {
        private ICustomer _customer;
        public ICustomer Customer
        {
            get { return _customer; }

        }

        private IInvoiceDalc _invoiceDalc;
        public IInvoiceDalc InvoiceDalc
        {
            get
            {
                if (_invoiceDalc == null) _invoiceDalc = new InvoiceDalc(this);

                return _invoiceDalc;
            }
#if DEBUG
            set
            {
                this._invoiceDalc = value;
            }
#endif
        }

        private int _invoiceNumber;
        public int InvoiceNumber
        {
            get { return _invoiceNumber; }
            set { _invoiceNumber = value; }
        }



        DateTime _issueDate;
        public DateTime IssueDate
        {
            get { return _issueDate; }
            set { _issueDate = value; }
        }



        string _description;
        public string Description
        {
            get { return _description; }

        }
        internal Status _status;
        public Status Status
        {
            get
            {
                return _status;
            }

        }

        public DateTime DueDate
        {
            get { return _issueDate.AddMonths(1); }

        }
        List<InvoiceItem> _items;




        public List<InvoiceItem> Items
        {
            get
            {
                if (_items == null) _items = new List<InvoiceItem>();
                return _items;
            }
            set { _items = value; }
        }

        public Invoice(int invoiceNumber, string description, ICustomer customer)
        {
            this._invoiceNumber = invoiceNumber;
            this._description = description;
            this._customer = customer;

        }

        public Invoice(int invoiceNumber, string description, ICustomer customer, DateTime issueDate, Status status, List<InvoiceItem> items)
            : this(invoiceNumber, description, customer)
        {

            this._items = items;
            this._issueDate = issueDate;
            this._status = status;
        }

        public Invoice()
        {

        }

        public Invoice IssueInvoice(string description, ICustomer customer, List<InvoiceItem> items)
        {
            Console.WriteLine("--- IssueInvoice Method was invoked from object {0} ", this);
            Console.WriteLine("press enter to continue ....");
            Console.ReadLine();

            return this.InvoiceDalc.IssueInvoice(description, customer, items);

        }
        public void PayOffInvoice(ICustomer customer)
        {
            Console.WriteLine("--- PayOffInvoice Method was invoked from object {0} ", this);
            Console.WriteLine("press enter to continue ....");
            Console.ReadLine();

            this.InvoiceDalc.PayOffInvoice(customer);
        }




        public Invoice GetInvoice(int invoiceNomber)
        {
            Console.WriteLine("--- GetInvoice Method was invoked from object {0} ", this);
            Console.WriteLine("press enter to continue ....");
            Console.ReadLine();

            return this.InvoiceDalc.GetInvoice(invoiceNomber);
        }



        public int ItemsCount
        {
            get
            {
                return Items.Count;
            }

        }

        public bool Contains(string itemDescription)
        {
            foreach (InvoiceItem item in Items)
            {
                if (string.Compare(item.Description, itemDescription, true) == 0) return true;
            }
            return false;
        }
        public decimal TotalAmount
        {
            get
            {
                decimal amount = 0;
                foreach (InvoiceItem item in Items)
                {
                    amount += item.Quantity * item.Price;
                }
                return amount;
            }
        }
        public void Update()
        {
            Console.WriteLine("--- Update Method was invoked from object {0} ", this);
            Console.WriteLine("press enter to continue ....");
            Console.ReadLine();

            this.InvoiceDalc.Update();
        }
        public override string ToString()
        {
            return string.Format("{0}-{1}", this.InvoiceNumber, this.Description);
        }

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) NSW Curriculum & Learning Innovation Centre
Australia Australia
I am a senior developer self taught,
the main study is electronics and communication engineering

I am working as senior programmer in center for learning and innovation
www.cli.nsw.edu.au

I develop Software since 1995 using Delphi with Microsoft SQL Server

before 2000, I didn’t like Microsoft tools and did many projects using all database tools and other programming tools specially Borland C++ Builder, Delphi, Power Builder
And I loved Oracle database for its stability until I was certified as Master in Database Administration from Oracle University.

I tried to work in web programming but I felt that Java is hard and slow in programming, specially I love productivity.

I began worked with .Net since 2001 , and at the same time Microsoft SQL Server 7 was very stable so I switched all my way to Microsoft Tech.
I really respect .Net Platform especially in web applications

I love database Applications too much
And built library with PowerBuilder it was very useful for me and other developers

I have a wide experience due to my work in different companies
But the best experience I like in wireless applications, and web applications.
The best Application I did in my life is Novartis Marketing System 1999 it takes 8 months developing with PowerBuilder and Borland C++, SQL Server
Performance was the key challenge in this Application.
The other 2 applications that I loved Multilingual Project in Scada company in Italy 2000 and SDP Mobile media content platform server for ChinaUnicom 2004
I hope that you enjoy any Article I post.
God bless you.

Comments and Discussions