You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by gb...@apache.org on 2006/02/09 20:18:33 UTC
svn commit: r376394 - in /ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test:
./ NUnit/SqlMapTests/ NUnit/SqlMapTests/Generics/
NUnit/SqlMapTests/MSSQL/Generics/
Author: gbayon
Date: Thu Feb 9 11:18:31 2006
New Revision: 376394
URL: http://svn.apache.org/viewcvs?rev=376394&view=rev
Log:
- Cleaning test project
Added:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.ResultClassTest.cs (with props)
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.StatementTest.cs (with props)
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/Generics/
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/Generics/Generics.StatementTest.cs (with props)
Removed:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics.ResultClassTest.cs
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics.StatementTest.cs
Modified:
ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
Modified: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj?rev=376394&r1=376393&r2=376394&view=diff
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj (original)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/IBatisNet.DataMapper.Test.2005.csproj Thu Feb 9 11:18:31 2006
@@ -205,18 +205,18 @@
<Compile Include="NUnit\SqlMapTests\ConfigureTest.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="NUnit\SqlMapTests\Generics.ResultClassTest.cs" />
<Compile Include="NUnit\SqlMapTests\DynamicPrependTest.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="NUnit\SqlMapTests\DynamicTest.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="NUnit\SqlMapTests\Generics.StatementTest.cs" />
+ <Compile Include="NUnit\SqlMapTests\Generics\Generics.ResultClassTest.cs" />
+ <Compile Include="NUnit\SqlMapTests\Generics\Generics.StatementTest.cs" />
<Compile Include="NUnit\SqlMapTests\InheritanceTest.cs">
<SubType>Code</SubType>
</Compile>
- <Compile Include="NUnit\SqlMapTests\MSSQL\Generics.StatementTest.cs" />
+ <Compile Include="NUnit\SqlMapTests\MSSQL\Generics\Generics.StatementTest.cs" />
<Compile Include="NUnit\SqlMapTests\MSSQL\ProcedureTest.cs">
<SubType>Code</SubType>
</Compile>
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.ResultClassTest.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.ResultClassTest.cs?rev=376394&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.ResultClassTest.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.ResultClassTest.cs Thu Feb 9 11:18:31 2006
@@ -0,0 +1,178 @@
+#if dotnet2
+using System;
+
+using NUnit.Framework;
+
+using IBatisNet.DataMapper.Test.Domain;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.Generics
+{
+ /// <summary>
+ /// Summary description for ResultClassTest.
+ /// </summary>
+ [TestFixture]
+ public class ResultClassTest : BaseTest
+ {
+ #region SetUp & TearDown
+
+ /// <summary>
+ /// SetUp
+ /// </summary>
+ [SetUp]
+ public void Init()
+ {
+ }
+
+ /// <summary>
+ /// TearDown
+ /// </summary>
+ [TearDown]
+ public void Dispose()
+ { /* ... */ }
+
+ #endregion
+
+ #region Specific statement test
+
+ /// <summary>
+ /// Test a boolean resultClass
+ /// </summary>
+ [Test]
+ public void TestBoolean()
+ {
+ bool bit = sqlMap.QueryForObject<bool>("GetBoolean", 1);
+
+ Assert.AreEqual(true, bit);
+ }
+
+ /// <summary>
+ /// Test a byte resultClass
+ /// </summary>
+ [Test]
+ public void TestByte()
+ {
+ byte letter = sqlMap.QueryForObject<byte>("GetByte", 1);
+
+ Assert.AreEqual(155, letter);
+ }
+
+ /// <summary>
+ /// Test a char resultClass
+ /// </summary>
+ [Test]
+ public void TestChar()
+ {
+ char letter = sqlMap.QueryForObject<char>("GetChar", 1);
+
+ Assert.AreEqual('a', letter);
+ }
+
+ /// <summary>
+ /// Test a DateTime resultClass
+ /// </summary>
+ [Test]
+ public void TestDateTime()
+ {
+ DateTime orderDate = sqlMap.QueryForObject<DateTime>("GetDate", 1);
+
+ System.DateTime date = new DateTime(2003, 2, 15, 8, 15, 00);
+
+ Assert.AreEqual(date.ToString(), orderDate.ToString());
+ }
+
+ /// <summary>
+ /// Test a decimal resultClass
+ /// </summary>
+ [Test]
+ public void TestDecimal()
+ {
+ decimal price = sqlMap.QueryForObject<decimal>("GetDecimal", 1);
+
+ Assert.AreEqual((decimal)1.56, price);
+ }
+
+ /// <summary>
+ /// Test a double resultClass
+ /// </summary>
+ [Test]
+ public void TestDouble()
+ {
+ double price = sqlMap.QueryForObject<double>("GetDouble", 1);
+
+ Assert.AreEqual(99.5f, price);
+ }
+
+ /// <summary>
+ /// IBATISNET-25 Error applying ResultMap when using 'Guid' in resultClass
+ /// </summary>
+ [Test]
+ public void TestGuid()
+ {
+ Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4");
+
+ Guid guid = sqlMap.QueryForObject<Guid>("GetGuid", 1);
+
+ Assert.AreEqual(newGuid, guid);
+ }
+
+ /// <summary>
+ /// Test a int16 resultClass
+ /// </summary>
+ [Test]
+ public void TestInt16()
+ {
+ short integer = sqlMap.QueryForObject<short>("GetInt16", 1);
+
+ Assert.AreEqual(32111, integer);
+ }
+
+ /// <summary>
+ /// Test a int 32 resultClass
+ /// </summary>
+ [Test]
+
+ public void TestInt32()
+ {
+ int integer = sqlMap.QueryForObject<int>("GetInt32", 1);
+
+ Assert.AreEqual(999999, integer);
+ }
+
+ /// <summary>
+ /// Test a int64 resultClass
+ /// </summary>
+ [Test]
+ public void TestInt64()
+ {
+ long bigInt = sqlMap.QueryForObject<long>("GetInt64", 1);
+
+ Assert.AreEqual(9223372036854775800, bigInt);
+ }
+
+ /// <summary>
+ /// Test a single/float resultClass
+ /// </summary>
+ [Test]
+ public void TestSingle()
+ {
+ float price = sqlMap.QueryForObject<float>("GetSingle", 1);
+
+ Assert.AreEqual(92233.5, price);
+ }
+
+ /// <summary>
+ /// Test a string resultClass
+ /// </summary>
+ [Test]
+ public void TestString()
+ {
+ string cardType = sqlMap.QueryForObject<string>("GetString", 1);
+
+ Assert.AreEqual("VISA", cardType);
+ }
+
+
+ #endregion
+ }
+}
+#endif
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.ResultClassTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.ResultClassTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.StatementTest.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.StatementTest.cs?rev=376394&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.StatementTest.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.StatementTest.cs Thu Feb 9 11:18:31 2006
@@ -0,0 +1,507 @@
+#region Apache Notice
+/*****************************************************************************
+ * $Revision: $
+ * $LastChangedDate$
+ * $LastChangedBy$
+ *
+ * iBATIS.NET Data Mapper
+ * Copyright (C) 2005, 2006 The Apache Software Foundation
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ********************************************************************************/
+#endregion
+
+#if dotnet2
+
+using System;
+using System.Collections;
+using IBatisNet.Common;
+using IBatisNet.Common.Exceptions;
+using IBatisNet.Common.Utilities;
+using IBatisNet.DataMapper.MappedStatements;
+using IBatisNet.DataMapper.Test.Domain;
+using System.Collections.Generic;
+using NUnit.Framework;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.Generics
+{
+ [TestFixture]
+ public class StatementTest : BaseTest
+ {
+ #region SetUp & TearDown
+
+ /// <summary>
+ /// SetUp
+ /// </summary>
+ [SetUp]
+ public void Init()
+ {
+ InitScript(sqlMap.DataSource, ScriptDirectory + "account-init.sql");
+ InitScript(sqlMap.DataSource, ScriptDirectory + "order-init.sql");
+ InitScript(sqlMap.DataSource, ScriptDirectory + "line-item-init.sql");
+ InitScript(sqlMap.DataSource, ScriptDirectory + "enumeration-init.sql");
+ InitScript(sqlMap.DataSource, ScriptDirectory + "other-init.sql");
+ }
+
+ /// <summary>
+ /// TearDown
+ /// </summary>
+ [TearDown]
+ public void Dispose()
+ { /* ... */
+ }
+
+ #endregion
+
+ #region Object Query tests
+
+ /// <summary>
+ /// Test Open connection with a connection string
+ /// </summary>
+ [Test]
+ public void TestOpenConnection()
+ {
+ sqlMap.OpenConnection(sqlMap.DataSource.ConnectionString);
+ Account account = sqlMap.QueryForObject<Account>("SelectWithProperty", null);
+ sqlMap.CloseConnection();
+
+ AssertAccount1(account);
+ }
+
+ /// <summary>
+ /// Test use a statement with property subtitution
+ /// (JIRA 22)
+ /// </summary>
+ [Test]
+ public void TestSelectWithProperty()
+ {
+ Account account = sqlMap.QueryForObject<Account>("SelectWithProperty", null);
+ AssertAccount1(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject Via ColumnName
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectViaColumnName()
+ {
+ Account account = sqlMap.QueryForObject<Account>("GetAccountViaColumnName", 1);
+ AssertAccount1(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject Via ColumnIndex
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectViaColumnIndex()
+ {
+ Account account = sqlMap.QueryForObject<Account>("GetAccountViaColumnIndex", 1);
+ AssertAccount1(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject Via ResultClass
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectViaResultClass()
+ {
+ Account account = sqlMap.QueryForObject<Account>("GetAccountViaResultClass", 1);
+ AssertAccount1(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject With simple ResultClass : string
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectWithSimpleResultClass()
+ {
+ string email = sqlMap.QueryForObject<string>("GetEmailAddressViaResultClass", 1);
+ Assert.AreEqual("Joe.Dalton@somewhere.com", email);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject With simple ResultMap : string
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectWithSimpleResultMap()
+ {
+ string email = sqlMap.QueryForObject<string>("GetEmailAddressViaResultMap", 1);
+ Assert.AreEqual("Joe.Dalton@somewhere.com", email);
+ }
+
+ /// <summary>
+ /// Test Primitive ReturnValue : System.DateTime
+ /// </summary>
+ [Test]
+ public void TestPrimitiveReturnValue()
+ {
+ DateTime CardExpiry = sqlMap.QueryForObject<DateTime>("GetOrderCardExpiryViaResultClass", 1);
+ Assert.AreEqual(new DateTime(2003, 02, 15, 8, 15, 00), CardExpiry);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject with result object : Account
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectWithResultObject()
+ {
+ Account account = new Account();
+ Account testAccount = sqlMap.QueryForObject<Account>("GetAccountViaColumnName", 1, account);
+ AssertAccount1(account);
+ Assert.IsTrue(account == testAccount);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject as Hashtable
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectAsHashtable()
+ {
+ Hashtable account = sqlMap.QueryForObject<Hashtable>("GetAccountAsHashtable", 1);
+ AssertAccount1AsHashtable(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject as Hashtable ResultClass
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectAsHashtableResultClass()
+ {
+ Hashtable account = sqlMap.QueryForObject<Hashtable>("GetAccountAsHashtableResultClass", 1);
+ AssertAccount1AsHashtableForResultClass(account);
+ }
+
+ /// <summary>
+ /// Test ExecuteQueryForObject via Hashtable
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectViaHashtable()
+ {
+ Hashtable param = new Hashtable();
+ param.Add("LineItem_ID", 2);
+ param.Add("Order_ID", 9);
+
+ LineItem testItem = sqlMap.QueryForObject<LineItem>("GetSpecificLineItem", param);
+
+ Assert.IsNotNull(testItem);
+ Assert.AreEqual("TSM-12", testItem.Code);
+ }
+
+ /// <summary>
+ /// Test Query Dynamic Sql Element
+ /// </summary>
+ [Test]
+ public void TestQueryDynamicSqlElement()
+ {
+ //IList list = sqlMap.QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_ID");
+ IList<string> list = sqlMap.QueryForList<string>("GetDynamicOrderedEmailAddressesViaResultMap", "Account_ID");
+
+ Assert.AreEqual("Joe.Dalton@somewhere.com", list[0]);
+
+ //list = sqlMap.QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_FirstName");
+ list = sqlMap.QueryForList<string>("GetDynamicOrderedEmailAddressesViaResultMap", "Account_FirstName");
+
+ Assert.AreEqual("Averel.Dalton@somewhere.com", list[0]);
+
+ }
+
+ /// <summary>
+ /// Test Execute QueryForList With ResultMap With Dynamic Element
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForListWithResultMapWithDynamicElement()
+ {
+ //IList list = sqlMap.QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "LIKE");
+ IList<Account> list = sqlMap.QueryForList<Account>("GetAllAccountsViaResultMapWithDynamicElement", "LIKE");
+
+ AssertAccount1(list[0]);
+ Assert.AreEqual(3, list.Count);
+ Assert.AreEqual(1, list[0].Id);
+ Assert.AreEqual(2, list[1].Id);
+ Assert.AreEqual(4, list[2].Id);
+
+ //list = sqlMap.QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "=");
+ list = sqlMap.QueryForList<Account>("GetAllAccountsViaResultMapWithDynamicElement", "=");
+
+ Assert.AreEqual(0, list.Count);
+ }
+
+ /// <summary>
+ /// Test Simple Dynamic Substitution
+ /// </summary>
+ [Test]
+ [Ignore("No longer supported.")]
+ public void TestSimpleDynamicSubstitution()
+ {
+ string statement = "select" + " Account_ID as Id," + " Account_FirstName as FirstName," + " Account_LastName as LastName," + " Account_Email as EmailAddress" + " from Accounts" + " WHERE Account_ID = #id#";
+
+ Hashtable param = new Hashtable();
+ param.Add("id", 1);
+ param.Add("statement", statement);
+
+
+ IList list = sqlMap.QueryForList("SimpleDynamicSubstitution", param);
+ AssertAccount1((Account)list[0]);
+ Assert.AreEqual(1, list.Count);
+ }
+
+ /// <summary>
+ /// Test Get Account Via Inline Parameters
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectViaInlineParameters()
+ {
+ Account account = new Account();
+ account.Id = 1;
+
+ Account testAccount = sqlMap.QueryForObject<Account>("GetAccountViaInlineParameters", account);
+
+ AssertAccount1(testAccount);
+ }
+
+ /// <summary>
+ /// Test ExecuteQuery For Object With Enum property
+ /// </summary>
+ [Test]
+ public void TestExecuteQueryForObjectWithEnum()
+ {
+ Enumeration enumClass = sqlMap.QueryForObject<Enumeration>("GetEnumeration", 1);
+
+ Assert.AreEqual(enumClass.Day, Days.Sat);
+ Assert.AreEqual(enumClass.Color, Colors.Red);
+ Assert.AreEqual(enumClass.Month, Months.August);
+
+ enumClass = sqlMap.QueryForObject("GetEnumeration", 3) as Enumeration;
+
+ Assert.AreEqual(enumClass.Day, Days.Mon);
+ Assert.AreEqual(enumClass.Color, Colors.Blue);
+ Assert.AreEqual(enumClass.Month, Months.September);
+ }
+
+ #endregion
+
+ #region List Query tests
+
+ /// <summary>
+ /// Test QueryForList with Hashtable ResultMap
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithHashtableResultMap()
+ {
+ IList<Hashtable> list = sqlMap.QueryForList<Hashtable>("GetAllAccountsAsHashMapViaResultMap", null);
+
+ AssertAccount1AsHashtable(list[0]);
+ Assert.AreEqual(5, list.Count);
+
+ Assert.AreEqual(1, list[0]["Id"]);
+ Assert.AreEqual(2, list[1]["Id"]);
+ Assert.AreEqual(3, list[2]["Id"]);
+ Assert.AreEqual(4, list[3]["Id"]);
+ Assert.AreEqual(5, list[4]["Id"]);
+ }
+
+ /// <summary>
+ /// Test QueryForList with Hashtable ResultClass
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithHashtableResultClass()
+ {
+ IList<Hashtable> list = sqlMap.QueryForList<Hashtable>("GetAllAccountsAsHashtableViaResultClass", null);
+
+ AssertAccount1AsHashtableForResultClass(list[0]);
+ Assert.AreEqual(5, list.Count);
+
+ Assert.AreEqual(1, list[0][BaseTest.ConvertKey("Id")]);
+ Assert.AreEqual(2, list[1][BaseTest.ConvertKey("Id")]);
+ Assert.AreEqual(3, list[2][BaseTest.ConvertKey("Id")]);
+ Assert.AreEqual(4, list[3][BaseTest.ConvertKey("Id")]);
+ Assert.AreEqual(5, list[4][BaseTest.ConvertKey("Id")]);
+ }
+
+ /// <summary>
+ /// Test QueryForList with IList ResultClass
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithIListResultClass()
+ {
+ IList<IList> list = sqlMap.QueryForList<IList>("GetAllAccountsAsArrayListViaResultClass", null);
+
+ IList listAccount = list[0];
+ Assert.AreEqual(1, listAccount[0]);
+ Assert.AreEqual("Joe", listAccount[1]);
+ Assert.AreEqual("Dalton", listAccount[2]);
+ Assert.AreEqual("Joe.Dalton@somewhere.com", listAccount[3]);
+
+ Assert.AreEqual(5, list.Count);
+
+ listAccount = (IList)list[0];
+ Assert.AreEqual(1, listAccount[0]);
+ listAccount = (IList)list[1];
+ Assert.AreEqual(2, listAccount[0]);
+ listAccount = (IList)list[2];
+ Assert.AreEqual(3, listAccount[0]);
+ listAccount = (IList)list[3];
+ Assert.AreEqual(4, listAccount[0]);
+ listAccount = (IList)list[4];
+ Assert.AreEqual(5, listAccount[0]);
+ }
+
+ /// <summary>
+ /// Test QueryForList With ResultMap, result collection as ArrayList
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithResultMap()
+ {
+ IList<Account> list = sqlMap.QueryForList<Account>("GetAllAccountsViaResultMap", null);
+
+ AssertAccount1(list[0]);
+ Assert.AreEqual(5, list.Count);
+ Assert.AreEqual(1, list[0].Id);
+ Assert.AreEqual(2, list[1].Id);
+ Assert.AreEqual(3, list[2].Id);
+ Assert.AreEqual(4, list[3].Id);
+ Assert.AreEqual(5, list[4].Id);
+ }
+
+ /// <summary>
+ /// Test QueryForList with ResultObject :
+ /// AccountCollection strongly typed collection
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithResultObject()
+ {
+ IList<Account> accounts = new List<Account>();
+
+ sqlMap.QueryForList("GetAllAccountsViaResultMap", null, accounts);
+
+ AssertAccount1(accounts[0]);
+ Assert.AreEqual(5, accounts.Count);
+ Assert.AreEqual(1, accounts[0].Id);
+ Assert.AreEqual(2, accounts[1].Id);
+ Assert.AreEqual(3, accounts[2].Id);
+ Assert.AreEqual(4, accounts[3].Id);
+ Assert.AreEqual(5, accounts[4].Id);
+ }
+
+
+ /// <summary>
+ /// Test QueryForList with no result.
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithNoResult()
+ {
+ IList<Account> list = sqlMap.QueryForList<Account>("GetNoAccountsViaResultMap", null);
+
+ Assert.AreEqual(0, list.Count);
+ }
+
+ /// <summary>
+ /// Test QueryForList with ResultClass : Account.
+ /// </summary>
+ [Test]
+ public void TestQueryForListResultClass()
+ {
+ IList<Account> list = sqlMap.QueryForList<Account>("GetAllAccountsViaResultClass", null);
+
+ AssertAccount1(list[0]);
+ Assert.AreEqual(5, list.Count);
+ Assert.AreEqual(1, list[0].Id);
+ Assert.AreEqual(2, list[1].Id);
+ Assert.AreEqual(3, list[2].Id);
+ Assert.AreEqual(4, list[3].Id);
+ Assert.AreEqual(5, list[4].Id);
+ }
+
+ /// <summary>
+ /// Test QueryForList with simple resultClass : string
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithSimpleResultClass()
+ {
+ IList<string> list = sqlMap.QueryForList<string>("GetAllEmailAddressesViaResultClass", null);
+
+ Assert.AreEqual("Joe.Dalton@somewhere.com", list[0]);
+ Assert.AreEqual("Averel.Dalton@somewhere.com", list[1]);
+ Assert.IsNull(list[2]);
+ Assert.AreEqual("Jack.Dalton@somewhere.com", list[3]);
+ Assert.IsNull(list[4]);
+ }
+
+ /// <summary>
+ /// Test QueryForList with simple ResultMap : string
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithSimpleResultMap()
+ {
+ IList<string> list = sqlMap.QueryForList<string>("GetAllEmailAddressesViaResultMap", null);
+
+ Assert.AreEqual("Joe.Dalton@somewhere.com", list[0]);
+ Assert.AreEqual("Averel.Dalton@somewhere.com", list[1]);
+ Assert.IsNull(list[2]);
+ Assert.AreEqual("Jack.Dalton@somewhere.com", list[3]);
+ Assert.IsNull(list[4]);
+ }
+
+ /// <summary>
+ /// Test QueryForListWithSkipAndMax
+ /// </summary>
+ [Test]
+ public void TestQueryForListWithSkipAndMax()
+ {
+ IList<Account> list = sqlMap.QueryForList<Account>("GetAllAccountsViaResultMap", null, 2, 2);
+
+ Assert.AreEqual(2, list.Count);
+ Assert.AreEqual(3, list[0].Id);
+ Assert.AreEqual(4, list[1].Id);
+ }
+
+
+ [Test]
+ public void TestQueryWithRowDelegate()
+ {
+ SqlMapper.RowDelegate<Account> handler = new SqlMapper.RowDelegate<Account>(this.RowHandler);
+
+ IList<Account> list = sqlMap.QueryWithRowDelegate<Account>("GetAllAccountsViaResultMap", null, handler);
+
+ Assert.AreEqual(5, _index);
+ Assert.AreEqual(5, list.Count);
+ AssertAccount1( list[0]);
+ Assert.AreEqual(1, list[0].Id);
+ Assert.AreEqual(2, list[1].Id);
+ Assert.AreEqual(3, list[2].Id);
+ Assert.AreEqual(4, list[3].Id);
+ Assert.AreEqual(5, list[4].Id);
+
+ }
+
+ #endregion
+
+ #region Row delegate
+
+ private int _index = 0;
+
+ public void RowHandler(object obj, object paramterObject, IList<Account> list)
+ {
+ _index++;
+
+ Assert.AreEqual(_index, ((Account)obj).Id);
+ list.Add(((Account)obj));
+ }
+
+ #endregion
+ }
+}
+
+#endif
\ No newline at end of file
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.StatementTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/Generics/Generics.StatementTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy
Added: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/Generics/Generics.StatementTest.cs
URL: http://svn.apache.org/viewcvs/ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/Generics/Generics.StatementTest.cs?rev=376394&view=auto
==============================================================================
--- ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/Generics/Generics.StatementTest.cs (added)
+++ ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/Generics/Generics.StatementTest.cs Thu Feb 9 11:18:31 2006
@@ -0,0 +1,175 @@
+#if dotnet2
+using System;
+using System.Collections;
+using System.Collections.Generic;
+
+using NUnit.Framework;
+
+using IBatisNet.DataMapper.Test.NUnit;
+using IBatisNet.DataMapper.Test.Domain;
+
+namespace IBatisNet.DataMapper.Test.NUnit.SqlMapTests.MSSQL.Generics
+{
+ /// <summary>
+ /// Summary description for StatementTest.
+ /// </summary>
+ [TestFixture]
+ [Category("MSSQL")]
+ public class StatementTest : BaseTest
+ {
+
+ #region SetUp & TearDown
+
+ /// <summary>
+ /// SetUp
+ /// </summary>
+ [SetUp]
+ public void Init()
+ {
+ InitScript( sqlMap.DataSource, ScriptDirectory + "account-init.sql" );
+ InitScript( sqlMap.DataSource, ScriptDirectory + "account-procedure.sql", false );
+ InitScript( sqlMap.DataSource, ScriptDirectory + "ps_SelectAccount.sql", false );
+ InitScript( sqlMap.DataSource, ScriptDirectory + "category-init.sql" );
+ InitScript( sqlMap.DataSource, ScriptDirectory + "order-init.sql" );
+ }
+
+ /// <summary>
+ /// TearDown
+ /// </summary>
+ [TearDown]
+ public void Dispose()
+ { /* ... */ }
+
+ #endregion
+
+ #region Specific statement test for sql server
+
+ /// <summary>
+ /// Test Insert Account via store procedure
+ /// </summary>
+ [Test]
+ public void GenericTestInsertAccountViaStoreProcedure()
+ {
+ Account account = new Account();
+
+ account.Id = 99;
+ account.FirstName = "Achille";
+ account.LastName = "Talon";
+ account.EmailAddress = "Achille.Talon@somewhere.com";
+
+ sqlMap.Insert("InsertAccountViaStoreProcedure", account);
+
+ Account testAccount = sqlMap.QueryForObject<Account>("GetAccountViaColumnName", 99);
+
+ Assert.IsNotNull(testAccount);
+ Assert.AreEqual(99, testAccount.Id);
+ }
+
+ /// <summary>
+ /// Test statement with properties subtitutions
+ /// (Test for IBATISNET-21 : Property substitutions do not occur inside selectKey statement)
+ /// </summary>
+ [Test]
+ public void GenericTestInsertCategoryWithProperties()
+ {
+ Category category = new Category();
+ category.Guid = Guid.NewGuid();
+
+ int key = (int)sqlMap.Insert("InsertCategoryWithProperties", category);
+
+ Category categoryTest = sqlMap.QueryForObject<Category>("GetCategory", key);
+ Assert.AreEqual(key, categoryTest.Id);
+ Assert.AreEqual("Film", categoryTest.Name);
+ Assert.AreEqual(category.Guid, categoryTest.Guid);
+ }
+
+ /// <summary>
+ /// Test guid column/field.
+ /// </summary>
+ [Test]
+ public void GenericTestGuidColumn()
+ {
+ Category category = new Category();
+ category.Name = "toto";
+ category.Guid = Guid.NewGuid();
+
+ int key = (int)sqlMap.Insert("InsertCategory", category);
+
+ Category categoryTest = sqlMap.QueryForObject<Category>("GetCategory", key);
+ Assert.AreEqual(key, categoryTest.Id);
+ Assert.AreEqual(category.Name, categoryTest.Name);
+ Assert.AreEqual(category.Guid, categoryTest.Guid);
+ }
+
+ /// <summary>
+ /// Test guid column/field through parameterClass.
+ /// </summary>
+ [Test]
+ public void GenericTestGuidColumnParameterClass()
+ {
+ Guid newGuid = Guid.NewGuid();
+ int key = (int)sqlMap.Insert("InsertCategoryGuidParameterClass", newGuid);
+
+ Category categoryTest = sqlMap.QueryForObject<Category>("GetCategory", key);
+ Assert.AreEqual(key, categoryTest.Id);
+ Assert.AreEqual("toto", categoryTest.Name);
+ Assert.AreEqual(newGuid, categoryTest.Guid);
+ }
+
+ /// <summary>
+ /// Test guid column/field through parameterClass without specifiyng dbType
+ /// </summary>
+ [Test]
+ public void GenericTestGuidColumnParameterClassJIRA20()
+ {
+ Guid newGuid = Guid.NewGuid();
+ int key = (int)sqlMap.Insert("InsertCategoryGuidParameterClassJIRA20", newGuid);
+
+ Category categoryTest = sqlMap.QueryForObject<Category>("GetCategory", key);
+ Assert.AreEqual(key, categoryTest.Id);
+ Assert.AreEqual("toto", categoryTest.Name);
+ Assert.AreEqual(newGuid, categoryTest.Guid);
+ }
+
+ /// <summary>
+ /// Test Update Category with Extended ParameterMap
+ /// </summary>
+ [Test]
+ public void GenericTestUpdateCategoryWithExtendParameterMap()
+ {
+ Category category = new Category();
+ category.Name = "Cat";
+ category.Guid = Guid.NewGuid();
+
+ int key = (int)sqlMap.Insert("InsertCategoryViaParameterMap", category);
+ category.Id = key;
+
+ category.Name = "Dog";
+ category.Guid = Guid.NewGuid();
+
+ sqlMap.Update("UpdateCategoryViaParameterMap", category);
+
+ Category categoryRead = null;
+ categoryRead = sqlMap.QueryForObject<Category>("GetCategory", key);
+
+ Assert.AreEqual(category.Id, categoryRead.Id);
+ Assert.AreEqual(category.Name, categoryRead.Name);
+ Assert.AreEqual(category.Guid.ToString(), categoryRead.Guid.ToString());
+ }
+
+ /// <summary>
+ /// Test select via store procedure
+ /// </summary>
+ [Test]
+ public void GenericTestSelect()
+ {
+ Order order = sqlMap.QueryForObject<Order>("GetOrderWithAccountViaSP", 1);
+ AssertOrder1(order);
+ AssertAccount1(order.Account);
+ }
+ #endregion
+
+
+ }
+}
+#endif
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/Generics/Generics.StatementTest.cs
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: ibatis/trunk/cs/mapper/IBatisNet.DataMapper.Test/NUnit/SqlMapTests/MSSQL/Generics/Generics.StatementTest.cs
------------------------------------------------------------------------------
svn:keywords = Id LastChangedDate LastChangedBy