Click here to Skip to main content
15,893,622 members
Articles / Database Development / SQL Server

How design patterns can help you in developing unit testing-enabled applications

Rate me:
Please Sign up or sign in to vote.
4.61/5 (34 votes)
15 Nov 2007CPOL15 min read 127.5K   323   177  
This article shows how you can mix together Model-View-Presenter, Domain Model, Services, ActiveRecord, and Repository patterns to create a testable application.
using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
using Castle.ActiveRecord.Queries;
using NHibernate;
using NHibernate.Expression;
using Northwind.Domain;
using System;
using System.Collections.Generic;
using System.Text;

namespace Northwind.Domain.Model
{
    /// <summary>
    /// This domain model class is mapped to the Orders table of Northwind database for Castle Project ActiveRecorrd framework.
    /// Besides, it is also mapped to the OrderTO transfer class.
    /// </summary>
    [ActiveRecord("Orders")]
    [MappedTO("Northwind.TransferObjects.Model.OrderTO")]
    public class Order : DomainBase<int>
    {
        int orderID;
        string customerID;
        int? employeeID;
        DateTime? orderDate;
        DateTime? requiredDate;
        DateTime? shippedDate;
        int? shipVia;
        float? freight;
        string shipName;
        string shipAddress;
        string shipCity;
        string shipRegion;
        string shipPostalCode;
        string shipCountry;

        public Order()
        {
        }

        [PrimaryKey(Column = "OrderID", Generator = PrimaryKeyType.Identity)]
        public override int ID
        {
            get {return orderID; }
            set { orderID = value; }
        }

        [Property()]
        public string CustomerID
        {
            get { return customerID; }
            set { customerID = value; }
        }

        [Property()]
        public int? EmployeeID
        {
            get { return employeeID; }
            set { employeeID = value; }
        }

        [Property()]
        public DateTime? OrderDate
        {
            get { return orderDate; }
            set { orderDate = value; }
        }

        [Property()]
        public DateTime? RequiredDate
        {
            get { return requiredDate; }
            set { requiredDate = value; }
        }

        [Property()]
        public DateTime? ShippedDate
        {
            get { return shippedDate; }
            set { shippedDate = value; }
        }

        [Property()]
        public int? ShipVia
        {
            get { return shipVia; }
            set { shipVia = value; }
        }

        [Property()]
        public float? Freight
        {
            get { return freight; }
            set { freight = value; }
        }

        [Property()]
        public string ShipName
        {
            get { return shipName; }
            set { shipName = value; }
        }

        [Property()]
        public string ShipAddress
        {
            get { return shipAddress; }
            set { shipAddress = value; }
        }

        [Property()]
        public string ShipCity
        {
            get { return shipCity; }
            set { shipCity = value; }
        }

        [Property()]
        public string ShipRegion
        {
            get { return shipRegion; }
            set { shipRegion = value; }
        }

        [Property()]
        public string ShipPostalCode
        {
            get { return shipPostalCode; }
            set { shipPostalCode = value; }
        }

        [Property()]
        public string ShipCountry
        {
            get { return shipCountry; }
            set { shipCountry = value; }
        }
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Instructor / Trainer Alura Cursos Online
Brazil Brazil

Comments and Discussions