Click here to Skip to main content
15,893,663 members
Articles / Programming Languages / C# 4.0

Building Integration Test Queries

Rate me:
Please Sign up or sign in to vote.
3.67/5 (2 votes)
14 Jan 2013CPOL2 min read 12.6K   27   2  
Reduces line of code by writing builder methods to construct integration test queries.
namespace BuildingQueriesDemo.SQL
{
    internal class EmployeesSql
    {
        #region EmployeeQueries
        internal const string GetEmployeesFromCountryUk = @"Select * from Employees where Country='UK'";

        internal const string GetEmployeesFromCityLondon = @"Select * from Employees where Country='UK' AND City='London'";
        #endregion

        #region Query Builder Method

        internal static string GetEmployees(string country, string optionalCity=null, string optionalTitleOfCourtesy=null)
        {
            var query = string.Format("Select * from Employees Where Country='{0}'",country);
            if (!string.IsNullOrEmpty(optionalCity))
                query = string.Format("{0} AND City= {1}", query, optionalCity);
            if (!string.IsNullOrEmpty((optionalTitleOfCourtesy)))
                query = string.Format("{0} AND titleOfCourtesy={1}", query, optionalTitleOfCourtesy);
            return query;
        }

        #endregion

    }
}

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
Technical Lead iGATE Global Solutions
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions