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 description for BaseTest. /// public abstract class BaseTest { /// /// The sqlMap /// protected static ISqlMapper sqlMap; /// /// A daoManager with a SimpledaoSession /// protected static IDaoManager daoManager = null; /// /// A daoManager with a sqlMapSession /// protected static IDaoManager daoManagerSqlMap = null; private static readonly ILog _logger = LogManager.GetLogger( System.Reflection.MethodBase.GetCurrentMethod().DeclaringType ); protected static string ScriptDirectory = null; /// /// Constructor /// 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 } /// /// Initialize an sqlMap /// 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); } /// /// Configure the SqlMap /// /// /// Must verify ConfigureHandler signature. /// /// /// The reconfigured sqlMap. /// protected static void Configure(object obj) { sqlMap = (ISqlMapper)obj; } /// /// Run a sql batch for the datasource. /// /// The datasource. /// The sql batch protected static void InitScript(IDataSource datasource, string script) { InitScript(datasource, script, true); } /// /// Run a sql batch for the datasource. /// /// The datasource. /// The sql batch /// parse out the statements in the sql script file. protected static void InitScript(IDataSource datasource, string script, bool doParse) { ScriptRunner runner = new ScriptRunner(); runner.RunScript(datasource, script, doParse); } /// /// Create a new account with id = 6 /// /// An account protected Account NewAccount6() { Account account = new Account(); account.Id = 6; account.FirstName = "Calamity"; account.LastName = "Jane"; account.EmailAddress = "no_email@provided.com"; return account; } /// /// Verify that the input account is equal to the account(id=1). /// /// An account object 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"); } /// /// Verify that the input account is equal to the account(id=1). /// /// An account as hashtable 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"); } /// /// Verify that the input account is equal to the account(id=6). /// /// An account object 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"); } } }