BaseTest.cs :  » Persistence-Frameworks » iBATIS.NET » IBatisNet » Common » Test » NUnit » CommonTests » Transaction » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Persistence Frameworks » iBATIS.NET 
iBATIS.NET » IBatisNet » Common » Test » NUnit » CommonTests » Transaction » BaseTest.cs
using System;
using System.Collections;
using System.Data;
using System.IO;
using System.Reflection;
using System.Configuration;
using IBatisNet.DataMapper.Configuration;
using log4net;

using NUnit.Framework;

using IBatisNet.DataAccess;

using IBatisNet.Common; // DataSource definition
using IBatisNet.Common.Utilities; // ScriptRunner definition
using IBatisNet.DataMapper; // SqlMap API

using IBatisNet.Common.Test.Domain;

[assembly:log4net.Config.XmlConfigurator(Watch=true)]

namespace IBatisNet.Common.Test.NUnit.CommonTests.Transaction{
  /// <summary>
  /// Summary description for BaseTest.
  /// </summary>
  public abstract class BaseTest
  {
    /// <summary>
    /// The sqlMap
    /// </summary>
    protected static ISqlMapper sqlMap;
    /// <summary>
    /// A daoManager with a SimpledaoSession
    /// </summary>
    protected static IDaoManager daoManager = null;
    /// <summary>
    /// A daoManager with a sqlMapSession
    /// </summary>
    protected static IDaoManager daoManagerSqlMap = null;

    private static readonly ILog _logger = LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType );
    
    protected static string ScriptDirectory = null;

    /// <summary>
    /// Constructor
    /// </summary>
    static BaseTest()
    {

      ScriptDirectory = Path.Combine(
        Path.Combine(
        Path.Combine(
#if dotnet2
                Path.Combine(Resources.ApplicationBase, ".."), ".."), "Scripts"), ConfigurationManager.AppSettings["database"]) + Path.DirectorySeparatorChar;
#else
        Path.Combine(Resources.ApplicationBase, ".."), ".."), "Scripts"), ConfigurationSettings.AppSettings["database"]) + Path.DirectorySeparatorChar;
#endif    
        }

    /// <summary>
    /// Initialize an sqlMap
    /// </summary>
    protected static void InitSqlMap()
    {
      //DateTime start = DateTime.Now;

      ConfigureHandler handler = new ConfigureHandler( Configure );
      DomSqlMapBuilder builder = new DomSqlMapBuilder();
#if dotnet2
            sqlMap = builder.ConfigureAndWatch("sqlmap" + "_" + ConfigurationManager.AppSettings["database"] + "_"
                + ConfigurationManager.AppSettings["providerType"] + ".config", handler);
#else
      sqlMap = builder.ConfigureAndWatch( "sqlmap"+ "_" +  ConfigurationSettings.AppSettings["database"] + "_"
        + ConfigurationSettings.AppSettings["providerType"] +".config", handler );
#endif

            //string loadTime = DateTime.Now.Subtract(start).ToString();
            //Console.WriteLine("Loading configuration time :"+loadTime);
    }

    /// <summary>
    /// Configure the SqlMap
    /// </summary>
    /// <remarks>
    /// Must verify ConfigureHandler signature.
    /// </remarks>
    /// <param name="obj">
    /// The reconfigured sqlMap.
    /// </param>
    protected static void Configure(object obj)
    {
      sqlMap = (ISqlMapper)obj;
    }

    /// <summary>
    /// Run a sql batch for the datasource.
    /// </summary>
    /// <param name="datasource">The datasource.</param>
    /// <param name="script">The sql batch</param>
    protected static void InitScript(IDataSource datasource, string script)
    {
      InitScript(datasource, script, true);
    }

    /// <summary>
    /// Run a sql batch for the datasource.
    /// </summary>
    /// <param name="datasource">The datasource.</param>
    /// <param name="script">The sql batch</param>
    /// <param name="doParse">parse out the statements in the sql script file.</param>
        protected static void InitScript(IDataSource datasource, string script, bool doParse)
        {
      ScriptRunner runner = new ScriptRunner();

      runner.RunScript(datasource, script, doParse);
    }

    /// <summary>
    /// Create a new account with id = 6
    /// </summary>
    /// <returns>An account</returns>
    protected Account NewAccount6() 
    {
      Account account = new Account();
      account.Id = 6;
      account.FirstName = "Calamity";
      account.LastName = "Jane";
      account.EmailAddress = "no_email@provided.com";
      return account;
    }

    /// <summary>
    /// Verify that the input account is equal to the account(id=1).
    /// </summary>
    /// <param name="account">An account object</param>
    protected void AssertAccount1(Account account) 
    {
      Assert.AreEqual(1, account.Id, "account.Id");
      Assert.AreEqual("Joe", account.FirstName, "account.FirstName");
      Assert.AreEqual("Dalton", account.LastName, "account.LastName");
      Assert.AreEqual("Joe.Dalton@somewhere.com", account.EmailAddress, "account.EmailAddress");
    }

    /// <summary>
    /// Verify that the input account is equal to the account(id=1).
    /// </summary>
    /// <param name="account">An account as hashtable</param>
    protected void AssertAccount1AsHashtable(Hashtable account) 
    {
      Assert.AreEqual(1, (int)account["Id"], "account.Id");
      Assert.AreEqual("Joe", (string)account["FirstName"], "account.FirstName");
      Assert.AreEqual("Dalton", (string)account["LastName"], "account.LastName");
      Assert.AreEqual("Joe.Dalton@somewhere.com", (string)account["EmailAddress"], "account.EmailAddress");
    }

    /// <summary>
    /// Verify that the input account is equal to the account(id=6).
    /// </summary>
    /// <param name="account">An account object</param>
    protected void AssertAccount6(Account account) 
    {
      Assert.AreEqual(6, account.Id, "account.Id");
      Assert.AreEqual("Calamity", account.FirstName, "account.FirstName");
      Assert.AreEqual("Jane", account.LastName, "account.LastName");
      Assert.IsNull(account.EmailAddress, "account.EmailAddress");
    }



  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.