5 // Copyright (c) 2007-2008 Jiri Moudry, Pascal Craponne
\r
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
\r
8 // of this software and associated documentation files (the "Software"), to deal
\r
9 // in the Software without restriction, including without limitation the rights
\r
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
11 // copies of the Software, and to permit persons to whom the Software is
\r
12 // furnished to do so, subject to the following conditions:
\r
14 // The above copyright notice and this permission notice shall be included in
\r
15 // all copies or substantial portions of the Software.
\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
31 using System.Reflection;
\r
32 using NUnit.Framework;
\r
37 using System.Diagnostics;
\r
38 public static class Profiler
\r
40 private static Stopwatch timer = new Stopwatch();
\r
42 [Conditional("DEBUG")]
\r
43 public static void Start()
\r
48 [Conditional("DEBUG")]
\r
49 public static void At(string format, params object[] args)
\r
52 Console.Write("#AT({0:D12}) ", timer.ElapsedTicks);
\r
53 Console.WriteLine(format, args);
\r
57 [Conditional("DEBUG")]
\r
58 public static void Stop()
\r
67 namespace Test_NUnit
\r
70 /// base class for ReadTest and WriteTest.
\r
71 /// Provides CreateDB(), Conn, and stringComparisonType.
\r
73 public abstract partial class TestBase
\r
76 public void BaseSetUp()
\r
79 Profiler.At("BaseSetUp()");
\r
83 public void BaseTearDown()
\r
85 Profiler.At("BaseTearDown()");
\r
89 public string DbServer
\r
93 return Environment.GetEnvironmentVariable("DbLinqServer") ?? "localhost";
\r
96 public string connStr
\r
100 var xConnectionStringsDoc = new XmlDocument();
\r
101 xConnectionStringsDoc.Load("../tests/ConnectionStrings.xml");
\r
102 XmlNode currentAssemblyNode = xConnectionStringsDoc.SelectSingleNode(string.Format("//Connection[@assembly=\"{0}\"]", Assembly.GetCallingAssembly().GetName().Name));
\r
103 string stringConnection = currentAssemblyNode.FirstChild.Value.Replace(@"\\", @"\");
\r
104 if (stringConnection.Contains("{0}"))
\r
105 stringConnection = string.Format(stringConnection, DbServer);
\r
106 return stringConnection;
\r
109 IDbConnection _conn;
\r
110 public IDbConnection Conn
\r
114 if (_conn == null) { _conn = CreateConnection(connStr); _conn.Open(); }
\r
119 //public Northwind CreateDB()
\r
121 // return CreateDB(System.Data.ConnectionState.Closed);
\r
124 static partial void CheckRecreateSqlite ();
\r
126 public Northwind CreateDB()
\r
128 return CreateDB(System.Data.ConnectionState.Closed);
\r
131 public Northwind CreateDB(System.Data.ConnectionState state)
\r
133 CheckRecreateSqlite();
\r
134 var conn = CreateConnection(connStr);
\r
135 if (state == System.Data.ConnectionState.Open)
\r
137 var db = new Northwind(conn) { Log = Console.Out };
\r
142 /// execute a sql statement, return an Int64.
\r
144 public long ExecuteScalar(string sql)
\r
146 using (var cmd = CreateCommand(sql, Conn))
\r
148 object oResult = cmd.ExecuteScalar();
\r
149 Assert.IsNotNull("Expecting result, instead got null. (sql=" + sql + ")");
\r
150 Assert.IsInstanceOfType(typeof(long), oResult, "Expecting 'long' result from query " + sql + ", instead got type " + oResult.GetType());
\r
151 return (long)oResult;
\r
156 /// execute a sql statement
\r
158 public void ExecuteNonQuery(string sql)
\r
160 using (var cmd = CreateCommand(sql, Conn))
\r
162 int iResult = cmd.ExecuteNonQuery();
\r
166 public static Product NewProduct(string productName)
\r
168 var p = new Product
\r
170 ProductName = productName,
\r
173 QuantityPerUnit = "11",
\r
174 #if ORACLE || FIREBIRD
\r
175 UnitPrice = 11, //type "int?"
\r