fixing data.integration tests
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
|
||||
<!-- TODO select form system db all errors that have 'incorrect syntax' at the start of the error string-->
|
||||
<property name="ErrorCodes.BadSqlGrammarCodes">
|
||||
<value>156,170,207,208</value>
|
||||
<value>102,156,170,207,208</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.PermissionDeniedCodes">
|
||||
<value>229</value>
|
||||
@@ -71,7 +71,7 @@
|
||||
|
||||
<!-- TODO select form system db all errors that have 'incorrect syntax' at the start of the error string-->
|
||||
<property name="ErrorCodes.BadSqlGrammarCodes">
|
||||
<value>156,170,207,208</value>
|
||||
<value>102,156,170,207,208</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.PermissionDeniedCodes">
|
||||
<value>229</value>
|
||||
@@ -112,7 +112,7 @@
|
||||
|
||||
<!-- TODO select form system db all errors that have 'incorrect syntax' at the start of the error string-->
|
||||
<property name="ErrorCodes.BadSqlGrammarCodes">
|
||||
<value>156,170,207,208</value>
|
||||
<value>102,156,170,207,208</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.PermissionDeniedCodes">
|
||||
<value>229</value>
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Spring.Data
|
||||
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[Ignore("Sanity-Check tests intended for verification of base-class behavior only")]
|
||||
[Test]
|
||||
public void SimpleCreate()
|
||||
{
|
||||
@@ -68,7 +68,7 @@ namespace Spring.Data
|
||||
dao.Create("John", 44);
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[Ignore("Sanity-Check tests intended for verification of base-class behavior only")]
|
||||
[Test]
|
||||
public void SimpleDao()
|
||||
{
|
||||
@@ -87,7 +87,7 @@ namespace Spring.Data
|
||||
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[Ignore("Sanity-Check tests intended for verification of base-class behavior only")]
|
||||
[Test]
|
||||
public void SimpleDao2()
|
||||
{
|
||||
@@ -99,7 +99,7 @@ namespace Spring.Data
|
||||
Assert.AreEqual(1, dao.GetCountByDelegate());
|
||||
}
|
||||
|
||||
[Ignore]
|
||||
[Ignore("Sanity-Check tests intended for verification of base-class behavior only")]
|
||||
[Test]
|
||||
public void DaoOperations()
|
||||
{
|
||||
|
||||
@@ -9,13 +9,13 @@
|
||||
|
||||
<object id="DbProvider" type="Spring.Data.Support.SqlProvider, Spring.Data">
|
||||
<property name="ConnectionString"
|
||||
value="Data Source=NYCSUMPOLLL;Initial Catalog=Credits;Integrated Security=True"/>
|
||||
value="Data Source=SPRINGQA;Initial Catalog=Credits;Integrated Security=false;User Id=springqa;Password=springqa"/>
|
||||
</object>
|
||||
|
||||
|
||||
<object id="DebitDbProvider" type="Spring.Data.Support.SqlProvider, Spring.Data">
|
||||
<property name="ConnectionString"
|
||||
value="Data Source=NYCSUMPOLLL;Initial Catalog=Debits;Integrated Security=True"/>
|
||||
value="Data Source=SPRINGQA;Initial Catalog=Debits;Integrated Security=false;User Id=springqa;Password=springqa"/>
|
||||
</object>
|
||||
|
||||
|
||||
|
||||
@@ -11,16 +11,16 @@
|
||||
|
||||
<d:provider id="DebitDbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=MARKT60\SQL2005;Initial Catalog=Debits;Persist Security Info=True;User ID=springqa;Password=springqa"/>
|
||||
connectionString="Data Source=SPRINGQA;Initial Catalog=Debits;Persist Security Info=True;User ID=springqa;Password=springqa"/>
|
||||
<!--
|
||||
connectionString="Data Source=NYCSUMPOLLL\SQLEXPRESS;Initial Catalog=Debits;Integrated Security=True;Pooling=False"/>
|
||||
connectionString="Data Source=SPRINGQA\SQLEXPRESS;Initial Catalog=Debits;Integrated Security=True;Pooling=False"/>
|
||||
-->
|
||||
|
||||
<d:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=MARKT60\SQL2005;Initial Catalog=Credits;Persist Security Info=True;User ID=springqa;Password=springqa"/>
|
||||
connectionString="Data Source=SPRINGQA;Initial Catalog=Credits;Persist Security Info=True;User ID=springqa;Password=springqa"/>
|
||||
<!--
|
||||
connectionString="Data Source=NYCSUMPOLLL\SQLEXPRESS;Initial Catalog=Credits;Integrated Security=True;Pooling=False"/>
|
||||
connectionString="Data Source=SPRINGQA\SQLEXPRESS;Initial Catalog=Credits;Integrated Security=True;Pooling=False"/>
|
||||
-->
|
||||
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
<!-- Database Providers -->
|
||||
<d:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=NYCSUMPOLLL\SQLEXPRESS;Initial Catalog=Credits;Integrated Security=True;Pooling=False"/>
|
||||
connectionString="Data Source=SPRINGQA;Initial Catalog=Credits;Integrated Security=false;User Id=springqa;Password=springqa;Pooling=False"/>
|
||||
|
||||
<d:provider id="DbProvider"
|
||||
<d:provider id="DebitDbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=NYCSUMPOLLL\SQLEXPRESS;Initial Catalog=Debits;Integrated Security=True;Pooling=False"/>
|
||||
connectionString="Data Source=SPRINGQA;Initial Catalog=Debits;Integrated Security=false;User Id=springqa;Password=springqa;Pooling=False"/>
|
||||
|
||||
|
||||
<!-- Transaction Manager -->
|
||||
|
||||
@@ -44,41 +44,63 @@ namespace Spring.Data.Generic
|
||||
"assembly://Spring.Data.Integration.Tests/Spring.Data.Generic/GenericAdoTemplateTests.xml");
|
||||
|
||||
adoTemplate = ctx["adoTemplate"] as AdoTemplate;
|
||||
|
||||
RemoveTestData();
|
||||
PopulateTestData();
|
||||
}
|
||||
|
||||
private void PopulateTestData()
|
||||
{
|
||||
adoTemplate.ExecuteScalar(CommandType.Text, "insert into TestObjects values (10, 'Jack')");
|
||||
adoTemplate.ExecuteScalar(CommandType.Text, "insert into TestObjects values (20, 'Jill')");
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
RemoveTestData();
|
||||
}
|
||||
|
||||
private void RemoveTestData()
|
||||
{
|
||||
adoTemplate.ExecuteNonQuery(CommandType.Text, "delete TestObjects");
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CommandDelegateUsage()
|
||||
{
|
||||
string postalCode = "1010";
|
||||
string name = "Jack";
|
||||
int count = adoTemplate.Execute<int>(delegate(DbCommand command)
|
||||
{
|
||||
command.CommandText =
|
||||
"select count(*) from Customers where PostalCode = @PostalCode";
|
||||
"select count(*) from TestObjects where Name = @Name";
|
||||
|
||||
DbParameter p = command.CreateParameter();
|
||||
p.ParameterName = "@PostalCode";
|
||||
p.Value = postalCode;
|
||||
p.ParameterName = "@Name";
|
||||
p.Value = name;
|
||||
command.Parameters.Add(p);
|
||||
|
||||
return (int) command.ExecuteScalar();
|
||||
});
|
||||
Assert.AreEqual(3, count);
|
||||
Assert.AreEqual(1, count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CommandDelegateUsageDownCast()
|
||||
{
|
||||
string postalCode = "1010";
|
||||
string name = "Jack";
|
||||
int count = adoTemplate.Execute<int>(delegate(DbCommand command)
|
||||
{
|
||||
SqlCommand sqlCommand = command as SqlCommand;
|
||||
command.CommandText =
|
||||
"select count(*) from Customers where PostalCode = @PostalCode";
|
||||
"select count(*) from TestObjects where Name = @Name";
|
||||
|
||||
sqlCommand.Parameters.AddWithValue("@PostalCode", postalCode);
|
||||
sqlCommand.Parameters.AddWithValue("@Name", name);
|
||||
|
||||
return (int) command.ExecuteScalar();
|
||||
});
|
||||
Assert.AreEqual(3, count);
|
||||
Assert.AreEqual(1, count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<db:provider id="dbProvider"
|
||||
provider="SqlServer-1.1"
|
||||
connectionString="Data Source=MARKT60\SQL2005;Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>
|
||||
connectionString="Data Source=SPRINGQA;Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>
|
||||
|
||||
<object id="transactionManager" type="Spring.Data.Core.AdoPlatformTransactionManager, Spring.Data">
|
||||
<property name="DbProvider" ref="dbProvider"/>
|
||||
|
||||
@@ -7,5 +7,7 @@ namespace Spring.Data
|
||||
void SaveTwoTestObjects(TestObject to1, TestObject to2);
|
||||
|
||||
void DeleteTwoTestObjects(string name1, string name2);
|
||||
|
||||
void DeleteAllTestObjects();
|
||||
}
|
||||
}
|
||||
@@ -27,73 +27,97 @@ using NUnit.Framework;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Data.Common;
|
||||
using Spring.Objects;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Test a MappingAdoQuery implementation
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack (.NET)</author>
|
||||
[TestFixture]
|
||||
public class MappingAdoQueryTests
|
||||
{
|
||||
#region Fields
|
||||
IDbProvider dbProvider;
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// Test a MappingAdoQuery implementation
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack (.NET)</author>
|
||||
[TestFixture]
|
||||
public class MappingAdoQueryTests
|
||||
{
|
||||
#region Fields
|
||||
IDbProvider dbProvider;
|
||||
#endregion
|
||||
|
||||
#region Constants
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// The shared ILog instance for this class (and derived classes).
|
||||
/// </summary>
|
||||
protected static readonly ILog log =
|
||||
LogManager.GetLogger(typeof (MappingAdoQueryTests));
|
||||
/// <summary>
|
||||
/// The shared ILog instance for this class (and derived classes).
|
||||
/// </summary>
|
||||
protected static readonly ILog log =
|
||||
LogManager.GetLogger(typeof(MappingAdoQueryTests));
|
||||
|
||||
#endregion
|
||||
private IApplicationContext ctx;
|
||||
|
||||
#region Constructor (s)
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MappingAdoQueryTests"/> class.
|
||||
/// </summary>
|
||||
public MappingAdoQueryTests()
|
||||
{
|
||||
#endregion
|
||||
|
||||
}
|
||||
#region Constructor (s)
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MappingAdoQueryTests"/> class.
|
||||
/// </summary>
|
||||
public MappingAdoQueryTests()
|
||||
{
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#region Properties
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
#region Properties
|
||||
|
||||
#region Methods
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
[SetUp]
|
||||
public void CreateDbProvider()
|
||||
{
|
||||
IApplicationContext ctx =
|
||||
new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/adoTemplateTests.xml");
|
||||
ctx = new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/adoTemplateTests.xml");
|
||||
Assert.IsNotNull(ctx);
|
||||
dbProvider = ctx["DbProvider"] as IDbProvider;
|
||||
Assert.IsNotNull(dbProvider);
|
||||
|
||||
DeleteTestData();
|
||||
PopulateTestData();
|
||||
}
|
||||
|
||||
private void PopulateTestData()
|
||||
{
|
||||
ITestObjectManager testObjectManager = ctx["testObjectManager"] as ITestObjectManager;
|
||||
testObjectManager.SaveTwoTestObjects(new TestObject("Jack", 10), new TestObject("Jill", 20));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void _TestTearDown()
|
||||
{
|
||||
DeleteTestData();
|
||||
}
|
||||
|
||||
private void DeleteTestData()
|
||||
{
|
||||
ITestObjectManager testObjectManager = ctx["testObjectManager"] as ITestObjectManager;
|
||||
testObjectManager.DeleteAllTestObjects();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void MappingAdoQuery()
|
||||
{
|
||||
TestObjectQuery testObjectQuery = new TestObjectQuery(dbProvider);
|
||||
IDictionary inParams = new Hashtable();
|
||||
inParams.Add("@Name", "Jack");
|
||||
IList testObjectList = testObjectQuery.QueryByNamedParam(inParams);
|
||||
Assert.AreEqual(1, testObjectList.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MappingAdoQuery()
|
||||
{
|
||||
TestObjectQuery testObjectQuery = new TestObjectQuery(dbProvider);
|
||||
IDictionary inParams = new Hashtable();
|
||||
inParams.Add("UName", "George");
|
||||
IList testObjectList = testObjectQuery.QueryByNamedParam(inParams);
|
||||
Assert.AreEqual(2, testObjectList.Count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ using Spring.Context.Support;
|
||||
|
||||
namespace Spring.Data
|
||||
{
|
||||
[TestFixture]
|
||||
public class NativeAdoTests
|
||||
{
|
||||
[Test]
|
||||
[TestFixture]
|
||||
public class NativeAdoTests
|
||||
{
|
||||
[Test]
|
||||
public void SimpleUsage()
|
||||
{
|
||||
IApplicationContext ctx =
|
||||
@@ -45,21 +45,18 @@ namespace Spring.Data
|
||||
dao.Create("John", 45);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Helloworld()
|
||||
{
|
||||
string connString =
|
||||
@"Data Source=MARKT60\SQL2005;Initial Catalog=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False";
|
||||
[Test]
|
||||
public void Helloworld()
|
||||
{
|
||||
string connString =
|
||||
@"Data Source=SPRINGQA;Initial Catalog=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False";
|
||||
|
||||
SqlConnection conn = new SqlConnection(connString);
|
||||
conn.Open();
|
||||
SqlConnection conn = new SqlConnection(connString);
|
||||
conn.Open();
|
||||
//conn.BeginTransaction(IsolationLevel.Unspecified);
|
||||
SqlTransaction trans = conn.BeginTransaction();
|
||||
Console.WriteLine(trans.IsolationLevel);
|
||||
//conn.BeginTransaction(IsolationLevel.Unspecified);
|
||||
SqlTransaction trans = conn.BeginTransaction();
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Assert.That(trans.IsolationLevel, Is.EqualTo(IsolationLevel.ReadCommitted));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ namespace Spring.Data
|
||||
public void TxTemplate()
|
||||
{
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("System.Data.SqlClient");
|
||||
dbProvider.ConnectionString = @"Data Source=MARKT60\SQL2005;Initial Catalog=CreditsAndDebits;User ID=springqa; Password=springqa";
|
||||
dbProvider.ConnectionString = @"Data Source=SPRINGQA;Initial Catalog=CreditsAndDebits;User ID=springqa; Password=springqa";
|
||||
//IPlatformTransactionManager tm = new ServiceDomainPlatformTransactionManager();
|
||||
//IPlatformTransactionManager tm = new TxScopeTransactionManager();
|
||||
IPlatformTransactionManager tm = new AdoPlatformTransactionManager(dbProvider);
|
||||
@@ -95,7 +95,7 @@ namespace Spring.Data
|
||||
using (SqlConnection cn2005 = new SqlConnection())
|
||||
{
|
||||
cn2005.ConnectionString =
|
||||
@"Data Source=MARKT60\SQL2005;Initial Catalog=CreditsAndDebits;User ID=springqa; Password=springqa";
|
||||
@"Data Source=SPRINGQA;Initial Catalog=CreditsAndDebits;User ID=springqa; Password=springqa";
|
||||
SqlCommand cmd = new SqlCommand(updateSql1, cn2005);
|
||||
cn2005.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
@@ -118,7 +118,7 @@ namespace Spring.Data
|
||||
System.Transactions.Transaction.Current.TransactionInformation.LocalIdentifier);
|
||||
using (SqlConnection cn2005 = new SqlConnection())
|
||||
{
|
||||
cn2005.ConnectionString = @"Data Source=MARKT60\SQL2005;Initial Catalog=CreditsAndDebits;User ID=springqa; Password=springqa";
|
||||
cn2005.ConnectionString = @"Data Source=SPRINGQA;Initial Catalog=CreditsAndDebits;User ID=springqa; Password=springqa";
|
||||
SqlCommand cmd = new SqlCommand(updateSql2, cn2005);
|
||||
cn2005.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
@@ -153,7 +153,7 @@ namespace Spring.Data
|
||||
|
||||
using (SqlConnection cn2005 = new SqlConnection())
|
||||
{
|
||||
cn2005.ConnectionString = @"Data Source=MARKT60\SQL2005;Initial Catalog=CreditsAndDebits;User ID=springqa; Password=springqa";
|
||||
cn2005.ConnectionString = @"Data Source=SPRINGQA;Initial Catalog=CreditsAndDebits;User ID=springqa; Password=springqa";
|
||||
SqlCommand cmd = new SqlCommand(updateSql2, cn2005);
|
||||
cn2005.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace Spring.Data.Northwind
|
||||
|
||||
public Shipper Create(string name, string phone)
|
||||
{
|
||||
string connectionString = "Data Source=NYCSUMPOLLL;Initial Catalog=Northwind;Persist Security Info=True;User ID=springqa";
|
||||
string connectionString = "Data Source=SPRINGQA;Initial Catalog=Northwind;Persist Security Info=True;User ID=springqa;Password=springqa";
|
||||
int id = 0;
|
||||
using (SqlConnection connection = new SqlConnection(connectionString))
|
||||
{
|
||||
@@ -66,7 +66,7 @@ namespace Spring.Data.Northwind
|
||||
|
||||
public Shipper CreateShorter(string name, string phone)
|
||||
{
|
||||
string connectionString = "Data Source=NYCSUMPOLLL;Initial Catalog=Northwind;Persist Security Info=True;User ID=springqa";
|
||||
string connectionString = "Data Source=SPRINGQA;Initial Catalog=Northwind;Persist Security Info=True;User ID=springqa";
|
||||
int id = 0;
|
||||
using (SqlConnection connection = new SqlConnection(connectionString))
|
||||
{
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Reflection;
|
||||
using NUnit.Framework;
|
||||
using Spring.Data.Common;
|
||||
@@ -41,11 +42,64 @@ namespace Spring.Data.Objects.Generic
|
||||
[TestFixture]
|
||||
public class StoredProcedureTests
|
||||
{
|
||||
private IDbProvider _dbProvider;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_dbProvider = DbProviderFactory.GetDbProvider("System.Data.SqlClient");
|
||||
_dbProvider.ConnectionString =
|
||||
@"Data Source=SPRINGQA;Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False";
|
||||
|
||||
IDbCommand command = _dbProvider.CreateCommand();
|
||||
command.Connection = _dbProvider.CreateConnection();
|
||||
|
||||
ClearTestData(command);
|
||||
CreateTestData(command);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
IDbCommand command = _dbProvider.CreateCommand();
|
||||
command.Connection = _dbProvider.CreateConnection();
|
||||
|
||||
ClearTestData(command);
|
||||
}
|
||||
|
||||
private void CreateTestData(IDbCommand command)
|
||||
{
|
||||
command.Connection.Open();
|
||||
|
||||
command.CommandText = "insert into TestObjects(Name,Age) values ('Jack', 10)";
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.CommandText = "insert into TestObjects(Name,Age) values ('Jill', 20)";
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.CommandText = "insert into Vacations(FirstName,LastName,EmployeeId,StartDate,EndDate) values ('Jack', 'Doe', 200, '1/1/2010', '1/15/2010')";
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.CommandText = "insert into Vacations(FirstName,LastName,EmployeeId,StartDate,EndDate) values ('Jack', 'Doe', 200, '2/1/2010', '2/15/2010')";
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.Connection.Close();
|
||||
}
|
||||
|
||||
private void ClearTestData(IDbCommand command)
|
||||
{
|
||||
command.Connection.Open();
|
||||
|
||||
command.CommandText = "truncate table TestObjects";
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.CommandText = "truncate table Vacations";
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
command.Connection.Close();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void TestReflection()
|
||||
{
|
||||
@@ -102,36 +156,38 @@ namespace Spring.Data.Objects.Generic
|
||||
MethodInfo methodInfo = rowMapperclosedType.GetMethod("MapRow", BINDING_FLAGS);
|
||||
|
||||
//MethodInfo genMethodInfo = methodInfo.MakeGenericMethod(genericArgumentType);
|
||||
object retVal = methodInfo.Invoke(rowmapper, new object[] { null, null});
|
||||
object retVal = methodInfo.Invoke(rowmapper, new object[] { null, null });
|
||||
Console.WriteLine("return val = " + retVal);
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test()
|
||||
public void SingleTableStoredProcedure_ReturnsResult()
|
||||
{
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("System.Data.SqlClient");
|
||||
dbProvider.ConnectionString =
|
||||
@"Data Source=MARKT60\SQL2005;Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False";
|
||||
TestObjectStoredProc sp = new TestObjectStoredProc(_dbProvider);
|
||||
IList<TestObject> testObjectList = sp.GetByName("Jack");
|
||||
|
||||
TestObjectStoredProc sp = new TestObjectStoredProc(dbProvider);
|
||||
IList<TestObject> testObjectList = sp.GetByName("George");
|
||||
|
||||
Assert.IsNotNull(testObjectList);
|
||||
|
||||
TestObjectandVacationStoredProc vsp = new TestObjectandVacationStoredProc(dbProvider);
|
||||
|
||||
System.Collections.IDictionary outParams = vsp.ExecStoreProc("George");
|
||||
Assert.That(testObjectList, Is.Not.Null);
|
||||
Assert.That(testObjectList, Has.Count.EqualTo(1));
|
||||
}
|
||||
|
||||
|
||||
testObjectList = outParams["testObjectRowMapper"] as IList<TestObject>;
|
||||
[Test]
|
||||
public void MultipleTableStoredProcedure_ReturnsResult()
|
||||
{
|
||||
TestObjectandVacationStoredProc vsp = new TestObjectandVacationStoredProc(_dbProvider);
|
||||
|
||||
IDictionary outParams = vsp.ExecStoreProc("Jack");
|
||||
|
||||
IList<TestObject> testObjectList = testObjectList = outParams["testObjectRowMapper"] as IList<TestObject>;
|
||||
Assert.IsNotNull(testObjectList);
|
||||
Assert.AreEqual(1, testObjectList.Count);
|
||||
|
||||
IList<Vacation> vacationList = outParams["vacationRowMapper"] as IList<Vacation>;
|
||||
Assert.IsNotNull(vacationList);
|
||||
Assert.AreEqual(2, vacationList.Count);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -153,14 +209,14 @@ namespace Spring.Data.Objects.Generic
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class TestObjectStoredProc : StoredProcedure
|
||||
{
|
||||
public TestObjectStoredProc(IDbProvider dbProvider)
|
||||
: base(dbProvider, "SelectByName")
|
||||
{
|
||||
{
|
||||
DeriveParameters();
|
||||
AddRowMapper("testObjectRowMapper", new TestObjectRowMapper() );
|
||||
AddRowMapper("testObjectRowMapper", new TestObjectRowMapper());
|
||||
Compile();
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ namespace Spring.Data
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack (.NET)</author>
|
||||
[TestFixture]
|
||||
[Ignore("ORACLE-dependent tests disabled for integration runs")]
|
||||
public class OracleAdoTemplateTests
|
||||
{
|
||||
#region Setup/Teardown
|
||||
|
||||
@@ -53,43 +53,45 @@ namespace Spring.Data
|
||||
public void SqlServerTest()
|
||||
{
|
||||
string errorCode = "544";
|
||||
string[] errorCodes = new string[4] {"544", "2627", "8114", "8115"};
|
||||
string[] errorCodes = new string[4] { "544", "2627", "8114", "8115" };
|
||||
//Array.IndexOf()
|
||||
//Array.Sort(errorCodes);
|
||||
foreach (string code in errorCodes)
|
||||
{
|
||||
Console.WriteLine(code);
|
||||
}
|
||||
//if (Array.BinarySearch(errorCodes, errorCode) >= 0)
|
||||
//if (Array.BinarySearch(errorCodes, errorCode) >= 0)
|
||||
if (Array.IndexOf(errorCodes, errorCode) >= 0)
|
||||
{
|
||||
Console.WriteLine("yes");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail("did not find error code");
|
||||
}
|
||||
{
|
||||
Console.WriteLine("yes");
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Fail("did not find error code");
|
||||
}
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("System.Data.SqlClient");
|
||||
dbProvider.ConnectionString =
|
||||
@"Data Source=MARKT60\SQL2005;Initial Catalog=Spring;Persist Security Info=True;User ID=springqa;Password=springqa";
|
||||
@"Data Source=SPRINGQA;Initial Catalog=Spring;Persist Security Info=True;User ID=springqa;Password=springqa";
|
||||
AdoTemplate adoTemplate = new AdoTemplate(dbProvider);
|
||||
try
|
||||
{
|
||||
adoTemplate.ExecuteNonQuery(CommandType.Text, "insert into Vacation (id) values (1)");
|
||||
} catch (Exception e)
|
||||
adoTemplate.ExecuteNonQuery(CommandType.Text, "insert into Vacations (FirstName,LastName) values ('Jack','Doe')");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.Write(e);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
[Ignore("ORACLE-dependent tests disabled for integration runs")]
|
||||
public void OracleTest()
|
||||
{
|
||||
//Data Source=XE;User ID=hr;Unicode=True
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("System.Data.OracleClient");
|
||||
dbProvider.ConnectionString = "Data Source=XE;User ID=hr;Password=hr;Unicode=True";
|
||||
AdoTemplate adoTemplate = new AdoTemplate(dbProvider);
|
||||
decimal count = (decimal) adoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from emp");
|
||||
decimal count = (decimal)adoTemplate.ExecuteScalar(CommandType.Text, "select count(*) from emp");
|
||||
Assert.AreEqual(14, count);
|
||||
|
||||
EmpProc empProc = new EmpProc(dbProvider);
|
||||
@@ -107,6 +109,7 @@ namespace Spring.Data
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("ODBC-dependent tests disabled for integration runs")]
|
||||
public void Test()
|
||||
{
|
||||
//IDbProvider dbProvider = DbProviderFactory.GetDbProvider("SybaseAse1.15");
|
||||
@@ -127,52 +130,53 @@ namespace Spring.Data
|
||||
}
|
||||
Assert.IsTrue(authorList.Count > 0);
|
||||
}
|
||||
/*
|
||||
[Test]
|
||||
public void StoredProc()
|
||||
{
|
||||
//IDbProvider dbProvider = DbProviderFactory.GetDbProvider("SybaseAse1.15");
|
||||
//dbProvider.ConnectionString = "Data Source='MARKT60';Port='5000';UID='sa';PWD='';Database='pubs2';";
|
||||
|
||||
|
||||
//IDbProvider dbProvider = DbProviderFactory.GetDbProvider("Odbc-2.0");
|
||||
//dbProvider.ConnectionString =
|
||||
// "Driver={Adaptive Server Enterprise};server=MARKT60;port=5000;Database=pubs2;uid=sa;pwd=;";
|
||||
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("SybaseAse-15");
|
||||
dbProvider.ConnectionString = "Data Source='MARKT60';Port='5000';UID='sa';PWD='';Database='pubs2';";
|
||||
HelloProc proc = new HelloProc(dbProvider);
|
||||
IDictionary dict = proc.GetResults();
|
||||
|
||||
Assert.AreEqual("Go Sybase", dict["@inoutParam"]);
|
||||
Assert.AreEqual("Hello mango", dict["@outParam"]);
|
||||
Assert.AreEqual(101, (int) dict["RETURN_VALUE"]);
|
||||
foreach (DictionaryEntry entry in dict)
|
||||
{
|
||||
Console.WriteLine("Key = " + entry.Key + ", Value = " + entry.Value);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StordProcAdoTemplate()
|
||||
{
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("SybaseAse-15");
|
||||
dbProvider.ConnectionString = "Data Source='MARKT60';Port='5000';UID='sa';PWD='';Database='pubs2';";
|
||||
AdoTemplate adoTemplate = new AdoTemplate(dbProvider);
|
||||
IDbParameters parameters = new DbParameters(dbProvider);
|
||||
parameters.Add("inParam", AseDbType.VarChar, 32).Value = "mango";
|
||||
parameters.AddInOut("inoutParam", AseDbType.VarChar, 64).Value = "Sybase";
|
||||
parameters.AddOut("outParam", AseDbType.VarChar, 64);
|
||||
parameters.AddReturn("retValue", AseDbType.Integer);
|
||||
adoTemplate.ExecuteNonQuery(CommandType.StoredProcedure, "sp_hello", parameters);
|
||||
|
||||
|
||||
Assert.AreEqual("Go Sybase", parameters["@inoutParam"].Value);
|
||||
Assert.AreEqual("Hello mango", parameters[2].Value);
|
||||
Assert.AreEqual(101, (int) parameters[3].Value);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
[Test]
|
||||
public void StoredProc()
|
||||
{
|
||||
//IDbProvider dbProvider = DbProviderFactory.GetDbProvider("SybaseAse1.15");
|
||||
//dbProvider.ConnectionString = "Data Source='MARKT60';Port='5000';UID='sa';PWD='';Database='pubs2';";
|
||||
|
||||
|
||||
//IDbProvider dbProvider = DbProviderFactory.GetDbProvider("Odbc-2.0");
|
||||
//dbProvider.ConnectionString =
|
||||
// "Driver={Adaptive Server Enterprise};server=MARKT60;port=5000;Database=pubs2;uid=sa;pwd=;";
|
||||
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("SybaseAse-15");
|
||||
dbProvider.ConnectionString = "Data Source='MARKT60';Port='5000';UID='sa';PWD='';Database='pubs2';";
|
||||
HelloProc proc = new HelloProc(dbProvider);
|
||||
IDictionary dict = proc.GetResults();
|
||||
|
||||
Assert.AreEqual("Go Sybase", dict["@inoutParam"]);
|
||||
Assert.AreEqual("Hello mango", dict["@outParam"]);
|
||||
Assert.AreEqual(101, (int) dict["RETURN_VALUE"]);
|
||||
foreach (DictionaryEntry entry in dict)
|
||||
{
|
||||
Console.WriteLine("Key = " + entry.Key + ", Value = " + entry.Value);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StordProcAdoTemplate()
|
||||
{
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("SybaseAse-15");
|
||||
dbProvider.ConnectionString = "Data Source='MARKT60';Port='5000';UID='sa';PWD='';Database='pubs2';";
|
||||
AdoTemplate adoTemplate = new AdoTemplate(dbProvider);
|
||||
IDbParameters parameters = new DbParameters(dbProvider);
|
||||
parameters.Add("inParam", AseDbType.VarChar, 32).Value = "mango";
|
||||
parameters.AddInOut("inoutParam", AseDbType.VarChar, 64).Value = "Sybase";
|
||||
parameters.AddOut("outParam", AseDbType.VarChar, 64);
|
||||
parameters.AddReturn("retValue", AseDbType.Integer);
|
||||
adoTemplate.ExecuteNonQuery(CommandType.StoredProcedure, "sp_hello", parameters);
|
||||
|
||||
|
||||
Assert.AreEqual("Go Sybase", parameters["@inoutParam"].Value);
|
||||
Assert.AreEqual("Hello mango", parameters[2].Value);
|
||||
Assert.AreEqual(101, (int) parameters[3].Value);
|
||||
}
|
||||
*/
|
||||
[Test]
|
||||
[Ignore("SYBASE-ASE-dependent tests disabled for integration runs")]
|
||||
public void DeriveParams()
|
||||
{
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("SybaseAse-15");
|
||||
@@ -190,25 +194,26 @@ namespace Spring.Data
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
[Test]
|
||||
public void RawDeriveParams()
|
||||
{
|
||||
using (
|
||||
AseConnection conn =
|
||||
new AseConnection("Data Source='MARKT60';Port='5000';UID='sa';PWD='';Database='pubs2';"))
|
||||
{
|
||||
using (AseCommand cmd = new AseCommand("@sp_hello", conn))
|
||||
/*
|
||||
[Test]
|
||||
public void RawDeriveParams()
|
||||
{
|
||||
conn.Open();
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
AseCommandBuilder.DeriveParameters(cmd);
|
||||
Console.WriteLine("Number of parameters = " + cmd.Parameters.Count);
|
||||
using (
|
||||
AseConnection conn =
|
||||
new AseConnection("Data Source='MARKT60';Port='5000';UID='sa';PWD='';Database='pubs2';"))
|
||||
{
|
||||
using (AseCommand cmd = new AseCommand("@sp_hello", conn))
|
||||
{
|
||||
conn.Open();
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
AseCommandBuilder.DeriveParameters(cmd);
|
||||
Console.WriteLine("Number of parameters = " + cmd.Parameters.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
*/
|
||||
[Test]
|
||||
[Ignore("SYBASE-ASE-dependent tests disabled for integration runs")]
|
||||
public void QueryWithMapper()
|
||||
{
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("SybaseAse-15");
|
||||
@@ -219,6 +224,7 @@ namespace Spring.Data
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("ODBC-dependent tests disabled for integration runs")]
|
||||
public void QueryWithMapperODBC()
|
||||
{
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("Odbc-2.0");
|
||||
@@ -230,6 +236,7 @@ namespace Spring.Data
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("SYBASE-ASE-dependent tests disabled for integration runs")]
|
||||
public void QueryRawODBC()
|
||||
{
|
||||
using (
|
||||
@@ -267,17 +274,17 @@ namespace Spring.Data
|
||||
{
|
||||
return AdoTemplate.QueryWithRowMapperDelegate<Sale>(CommandType.StoredProcedure, "history_proc",
|
||||
delegate(IDataReader dataReader, int rowNum)
|
||||
{
|
||||
Sale sale = new Sale();
|
||||
sale.Date = dataReader.GetDateTime(0);
|
||||
sale.OrderNumber = dataReader.GetString(1);
|
||||
sale.Quantity = dataReader.GetInt32(2);
|
||||
sale.Title = dataReader.GetString(3);
|
||||
sale.Discount = dataReader.GetFloat(4);
|
||||
sale.Price = dataReader.GetFloat(5);
|
||||
sale.Total = dataReader.GetFloat(6);
|
||||
return sale;
|
||||
}, "stor_id",
|
||||
{
|
||||
Sale sale = new Sale();
|
||||
sale.Date = dataReader.GetDateTime(0);
|
||||
sale.OrderNumber = dataReader.GetString(1);
|
||||
sale.Quantity = dataReader.GetInt32(2);
|
||||
sale.Title = dataReader.GetString(3);
|
||||
sale.Discount = dataReader.GetFloat(4);
|
||||
sale.Price = dataReader.GetFloat(5);
|
||||
sale.Total = dataReader.GetFloat(6);
|
||||
return sale;
|
||||
}, "stor_id",
|
||||
DbType.String, 0, storeId);
|
||||
}
|
||||
}
|
||||
@@ -335,27 +342,28 @@ namespace Spring.Data
|
||||
set { total = value; }
|
||||
}
|
||||
}
|
||||
/*
|
||||
public class HelloProc : StoredProcedure
|
||||
{
|
||||
public HelloProc(IDbProvider provider) : base(provider, "sp_hello")
|
||||
/*
|
||||
public class HelloProc : StoredProcedure
|
||||
{
|
||||
DeclaredParameters.Add("inParam", AseDbType.VarChar, 32).Value = "mango";
|
||||
DeclaredParameters.AddInOut("inoutParam", AseDbType.VarChar, 64).Value = "Sybase";
|
||||
DeclaredParameters.AddOut("outParam", AseDbType.VarChar, 64);
|
||||
DeclaredParameters.AddReturn("retValue", AseDbType.Integer);
|
||||
Compile();
|
||||
}
|
||||
public HelloProc(IDbProvider provider) : base(provider, "sp_hello")
|
||||
{
|
||||
DeclaredParameters.Add("inParam", AseDbType.VarChar, 32).Value = "mango";
|
||||
DeclaredParameters.AddInOut("inoutParam", AseDbType.VarChar, 64).Value = "Sybase";
|
||||
DeclaredParameters.AddOut("outParam", AseDbType.VarChar, 64);
|
||||
DeclaredParameters.AddReturn("retValue", AseDbType.Integer);
|
||||
Compile();
|
||||
}
|
||||
|
||||
public IDictionary GetResults()
|
||||
{
|
||||
return Query("mango", "Sybase");
|
||||
public IDictionary GetResults()
|
||||
{
|
||||
return Query("mango", "Sybase");
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
*/
|
||||
public class EmpProc : StoredProcedure
|
||||
{
|
||||
public EmpProc(IDbProvider provider) : base(provider, "TEST.Get1CurOut")
|
||||
public EmpProc(IDbProvider provider)
|
||||
: base(provider, "TEST.Get1CurOut")
|
||||
{
|
||||
//DeriveParameters();
|
||||
DeclaredParameters.AddOut("P_CURSOR1", OracleType.Cursor);
|
||||
@@ -365,7 +373,7 @@ namespace Spring.Data
|
||||
|
||||
public IDictionary GetEmployees()
|
||||
{
|
||||
for (int i=0; i< DeclaredParameters.Count; i++)
|
||||
for (int i = 0; i < DeclaredParameters.Count; i++)
|
||||
{
|
||||
Console.WriteLine("decarled parameter name = " + DeclaredParameters[i].ParameterName + ", type = " + DeclaredParameters[i].DbType);
|
||||
}
|
||||
|
||||
@@ -33,58 +33,60 @@ using Spring.Data.Core;
|
||||
|
||||
namespace Spring.Data.Support
|
||||
{
|
||||
[TestFixture]
|
||||
public class SimpleExceptionTranslationTests
|
||||
{
|
||||
#region Fields
|
||||
private IDbProvider dbProvider;
|
||||
private IAdoOperations adoOperations;
|
||||
#endregion
|
||||
[TestFixture]
|
||||
public class SimpleExceptionTranslationTests
|
||||
{
|
||||
#region Fields
|
||||
private IDbProvider dbProvider;
|
||||
private IAdoOperations adoOperations;
|
||||
#endregion
|
||||
|
||||
#region Constants
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// The shared ILog instance for this class (and derived classes).
|
||||
/// </summary>
|
||||
protected static readonly ILog log =
|
||||
LogManager.GetLogger(typeof (SimpleExceptionTranslationTests));
|
||||
/// <summary>
|
||||
/// The shared ILog instance for this class (and derived classes).
|
||||
/// </summary>
|
||||
protected static readonly ILog log =
|
||||
LogManager.GetLogger(typeof(SimpleExceptionTranslationTests));
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
#region Methods
|
||||
|
||||
[SetUp]
|
||||
[SetUp]
|
||||
public void CreateAdoTemplate()
|
||||
{
|
||||
IApplicationContext ctx =
|
||||
IApplicationContext ctx =
|
||||
new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/adoTemplateTests.xml");
|
||||
Assert.IsNotNull(ctx);
|
||||
dbProvider = ctx["DbProvider"] as IDbProvider;
|
||||
Assert.IsNotNull(dbProvider);
|
||||
adoOperations = new AdoTemplate(dbProvider);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ExecuteNonQueryText()
|
||||
{
|
||||
|
||||
|
||||
string badSql = "insert into TestObjects(Age, Name) VALS (33, 'foo')";
|
||||
try
|
||||
{
|
||||
adoOperations.ExecuteNonQuery(CommandType.Text, badSql);
|
||||
} catch (BadSqlGrammarException e)
|
||||
}
|
||||
catch (BadSqlGrammarException e)
|
||||
{
|
||||
|
||||
|
||||
log.Error("caught correct exception", e);
|
||||
} catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
log.Error("caught incorrect exception ", e);
|
||||
|
||||
Assert.Fail("did not throw exception of type BadSqlGrammerException");
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using Common.Logging;
|
||||
using Spring.Objects;
|
||||
using Spring.Transaction.Interceptor;
|
||||
@@ -82,7 +83,20 @@ namespace Spring.Data
|
||||
testObjectDao.Delete(name2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
public void DeleteAllTestObjects()
|
||||
{
|
||||
IList objects = testObjectDao.FindAll();
|
||||
|
||||
foreach (object testObject in objects)
|
||||
{
|
||||
if (testObject is ITestObject)
|
||||
{
|
||||
testObjectDao.Delete(((ITestObject)testObject).Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Spring.Data
|
||||
/// <author>Mark Pollack (.NET)</author>
|
||||
public class TestObjectQuery : MappingAdoQuery
|
||||
{
|
||||
private static string sql = "select TestObjectNo, Age, Name from TestObjects where Name = @UName";
|
||||
private static string sql = "select TestObjectNo, Age, Name from TestObjects where Name = @Name";
|
||||
|
||||
public TestObjectQuery(IDbProvider dbProvider)
|
||||
: base(dbProvider, sql)
|
||||
@@ -44,7 +44,7 @@ namespace Spring.Data
|
||||
//DeclaredParameters = new DbParameters(dbProvider);
|
||||
try
|
||||
{
|
||||
DeclaredParameters.Add("UName", SqlDbType.VarChar, 50);
|
||||
DeclaredParameters.Add("Name", SqlDbType.VarChar, 50);
|
||||
} catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<db:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=MARKT60\SQL2005;Initial Catalog=Spring;Persist Security Info=True;User ID=springqa;Password=springqa"/>
|
||||
connectionString="Data Source=SPRINGQA;Initial Catalog=Spring;Persist Security Info=True;User ID=springqa;Password=springqa"/>
|
||||
|
||||
|
||||
<object id="adoTemplate" type="Spring.Data.Core.AdoTemplate, Spring.Data">
|
||||
|
||||
@@ -80,7 +80,7 @@ namespace Spring.Data
|
||||
using (SqlConnection cn2005 = new SqlConnection())
|
||||
{
|
||||
cn2005.ConnectionString =
|
||||
@"Data Source=MARKT60\SQL2005;Initial Catalog=CreditsAndDebits;User ID=springqa; Password=springqa";
|
||||
@"Data Source=SPRINGQA;Initial Catalog=CreditsAndDebits;User ID=springqa; Password=springqa";
|
||||
SqlCommand cmd = new SqlCommand(updateSql2, cn2005);
|
||||
cn2005.Open();
|
||||
Console.WriteLine("Isolation level = " + System.Transactions.Transaction.Current.IsolationLevel);
|
||||
|
||||
@@ -35,21 +35,21 @@ using Spring.Transaction.Support;
|
||||
|
||||
namespace Spring.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Integration tests for transaction template functionality
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
[TestFixture]
|
||||
public class TransactionTemplateTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Integration tests for transaction template functionality
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
[TestFixture]
|
||||
public class TransactionTemplateTests
|
||||
{
|
||||
|
||||
private IDbProvider dbProvider;
|
||||
|
||||
private IPlatformTransactionManager transactionManager;
|
||||
|
||||
private IApplicationContext ctx;
|
||||
|
||||
private IAdoOperations adoOperations;
|
||||
|
||||
private IAdoOperations adoOperations;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
@@ -57,9 +57,20 @@ namespace Spring.Data
|
||||
ctx =
|
||||
new XmlApplicationContext("assembly://Spring.Data.Integration.Tests/Spring.Data/templateTests.xml");
|
||||
dbProvider = ctx["DbProvider"] as IDbProvider;
|
||||
transactionManager = ctx["adoTransactionManager"] as IPlatformTransactionManager;
|
||||
transactionManager = ctx["transactionManager"] as IPlatformTransactionManager;
|
||||
adoOperations = ctx["adoTemplate"] as IAdoOperations;
|
||||
|
||||
|
||||
ITestObjectManager testObjectManager = ctx["testObjectManager"] as ITestObjectManager;
|
||||
testObjectManager.DeleteAllTestObjects();
|
||||
testObjectManager.SaveTwoTestObjects(new TestObject("Jack", 10), new TestObject("Jill", 20));
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
ITestObjectManager testObjectManager = ctx["testObjectManager"] as ITestObjectManager;
|
||||
testObjectManager.DeleteTwoTestObjects("Jack", "Jill");
|
||||
testObjectManager.DeleteAllTestObjects();
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +84,7 @@ namespace Spring.Data
|
||||
[Test]
|
||||
public void DeclarativeViaAutoProxyCreator()
|
||||
{
|
||||
ITestObjectManager mgr = ctx["testObjectManager"] as ITestObjectManager;
|
||||
ITestObjectManager mgr = ctx["testObjectManager"] as ITestObjectManager;
|
||||
TestObjectDao dao = (TestObjectDao)ctx["testObjectDao"];
|
||||
PerformOperations(mgr, dao);
|
||||
}
|
||||
@@ -88,7 +99,7 @@ namespace Spring.Data
|
||||
[Test]
|
||||
public void DeclarativeViaTransactionProxyFactoryObject()
|
||||
{
|
||||
ITestObjectManager mgr = ctx["testObjectManagerTP"] as ITestObjectManager;
|
||||
ITestObjectManager mgr = ctx["testObjectManagerTP"] as ITestObjectManager;
|
||||
ITestObjectDao dao = (ITestObjectDao)ctx["testObjectDao"];
|
||||
PerformOperations(mgr, dao);
|
||||
}
|
||||
@@ -102,7 +113,7 @@ namespace Spring.Data
|
||||
public void DeclarativeViaProxyFactoryObject()
|
||||
{
|
||||
ITestObjectManager mgr = ctx["testObjectManagerPF"] as ITestObjectManager;
|
||||
TestObjectDao dao = (TestObjectDao)ctx["testObjectDao"];
|
||||
TestObjectDao dao = (TestObjectDao)ctx["testObjectDao"];
|
||||
PerformOperations(mgr, dao);
|
||||
|
||||
}
|
||||
@@ -121,35 +132,35 @@ namespace Spring.Data
|
||||
coordinator.TestObjectManager.DeleteTwoTestObjects("Jack", "Jill");
|
||||
}
|
||||
|
||||
public static void PerformOperations(ITestObjectManager mgr,
|
||||
public static void PerformOperations(ITestObjectManager mgr,
|
||||
ITestObjectDao dao)
|
||||
{
|
||||
Assert.IsNotNull(mgr);
|
||||
TestObject to1 = new TestObject();
|
||||
to1.Name = "Jack";
|
||||
to1.Age = 7;
|
||||
TestObject to2 = new TestObject();
|
||||
to2.Name = "Jill";
|
||||
to2.Age = 8;
|
||||
mgr.SaveTwoTestObjects(to1, to2);
|
||||
|
||||
TestObject to = dao.FindByName("Jack");
|
||||
Assert.IsNotNull(to);
|
||||
|
||||
to = dao.FindByName("Jill");
|
||||
Assert.IsNotNull(to);
|
||||
Assert.AreEqual("Jill", to.Name);
|
||||
|
||||
mgr.DeleteTwoTestObjects("Jack", "Jill");
|
||||
|
||||
to = dao.FindByName("Jack");
|
||||
Assert.IsNull(to);
|
||||
|
||||
to = dao.FindByName("Jill");
|
||||
Assert.IsNull(to);
|
||||
}
|
||||
{
|
||||
Assert.IsNotNull(mgr);
|
||||
TestObject to1 = new TestObject();
|
||||
to1.Name = "Jack";
|
||||
to1.Age = 7;
|
||||
TestObject to2 = new TestObject();
|
||||
to2.Name = "Jill";
|
||||
to2.Age = 8;
|
||||
mgr.SaveTwoTestObjects(to1, to2);
|
||||
|
||||
[Test]
|
||||
TestObject to = dao.FindByName("Jack");
|
||||
Assert.IsNotNull(to);
|
||||
|
||||
to = dao.FindByName("Jill");
|
||||
Assert.IsNotNull(to);
|
||||
Assert.AreEqual("Jill", to.Name);
|
||||
|
||||
mgr.DeleteTwoTestObjects("Jack", "Jill");
|
||||
|
||||
to = dao.FindByName("Jack");
|
||||
Assert.IsNull(to);
|
||||
|
||||
to = dao.FindByName("Jill");
|
||||
Assert.IsNull(to);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteTemplate()
|
||||
{
|
||||
TransactionTemplate tt = new TransactionTemplate(transactionManager);
|
||||
@@ -164,7 +175,7 @@ namespace Spring.Data
|
||||
def.PropagationBehavior = TransactionPropagation.Required;
|
||||
|
||||
ITransactionStatus status = transactionManager.GetTransaction(def);
|
||||
|
||||
|
||||
int iCount = 0;
|
||||
try
|
||||
{
|
||||
@@ -176,7 +187,8 @@ namespace Spring.Data
|
||||
*/
|
||||
|
||||
//other AdoCommands can be executed within same tx.
|
||||
} catch (Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
transactionManager.Rollback(status);
|
||||
throw e;
|
||||
@@ -186,12 +198,12 @@ namespace Spring.Data
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class SimpleTransactionCallback : ITransactionCallback
|
||||
{
|
||||
private IDbProvider dbProvider;
|
||||
|
||||
public SimpleTransactionCallback(IDbProvider dbp)
|
||||
public SimpleTransactionCallback(IDbProvider dbp)
|
||||
{
|
||||
dbProvider = dbp;
|
||||
}
|
||||
@@ -207,10 +219,10 @@ namespace Spring.Data
|
||||
return adoTemplate.Execute(new TestCommandCallback());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private class TestCommandCallback : ICommandCallback
|
||||
{
|
||||
|
||||
|
||||
public Object DoInCommand(IDbCommand cmd)
|
||||
{
|
||||
cmd.CommandText = "SELECT COUNT(*) FROM TestObjects";
|
||||
@@ -223,5 +235,5 @@ namespace Spring.Data
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,17 +3,25 @@
|
||||
xmlns:db="http://www.springframework.net/database">
|
||||
|
||||
|
||||
|
||||
<db:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
|
||||
<db:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=SPRINGQA;Database=Spring;Trusted_Connection=False;User ID=springqa;Password=springqa"/>
|
||||
|
||||
<!-- connectionString="Data Source=MARKT60\SQL2005;Initial Catalog=Spring;Persist Security Info=True;User ID=springqa;Password=springqa"/> -->
|
||||
|
||||
|
||||
<object id="adoTemplate" type="Spring.Data.Core.AdoTemplate, Spring.Data">
|
||||
<property name="DbProvider" ref="DbProvider"/>
|
||||
</object>
|
||||
|
||||
<object id="testObjectDao"
|
||||
type="Spring.Data.TestObjectDao, Spring.Data.Integration.Tests">
|
||||
|
||||
<property name="AdoTemplate" ref="adoTemplate"/>
|
||||
</object>
|
||||
|
||||
<object id="testObjectManager"
|
||||
type="Spring.Data.TestObjectManager, Spring.Data.Integration.Tests">
|
||||
|
||||
<property name="TestObjectDao" ref="testObjectDao"/>
|
||||
</object>
|
||||
|
||||
</objects>
|
||||
@@ -7,12 +7,12 @@
|
||||
<!--
|
||||
<d:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=MARKT60\SQL2005;Initial Catalog=Spring;Persist Security Info=True;User ID=springqa;Password=springqa"/>
|
||||
connectionString="Data Source=SPRINGQA;Initial Catalog=Spring;Persist Security Info=True;User ID=springqa;Password=springqa"/>
|
||||
-->
|
||||
|
||||
<db:provider id="DbProvider"
|
||||
provider="SqlServer-1.1"
|
||||
connectionString="Data Source=MARKT60\SQL2005;Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>
|
||||
connectionString="Data Source=SPRINGQA;Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>
|
||||
<object id="adoTransactionManager"
|
||||
type="Spring.Data.Core.AdoPlatformTransactionManager, Spring.Data">
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<db:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=MARKT60\SQL2005;Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>
|
||||
connectionString="Data Source=SPRINGQA;Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>
|
||||
|
||||
<object id="adoTemplate" type="Spring.Data.Core.AdoTemplate, Spring.Data">
|
||||
<property name="DbProvider" ref="DbProvider"/>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
<object id="testObjectDao"
|
||||
type="Spring.Data.NativeAdoTestObjectDao, Spring.Data.Integration.Tests">
|
||||
<property name="ConnectionString" value="Data Source=MARKT60\SQL2005;Initial Catalog=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>
|
||||
<property name="ConnectionString" value="Data Source=SPRINGQA;Initial Catalog=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>
|
||||
</object>
|
||||
|
||||
</objects>
|
||||
@@ -177,7 +177,9 @@
|
||||
<EmbeddedResource Include="Data\declarativeServices.xml" />
|
||||
<EmbeddedResource Include="Data\DTCAppContext.xml" />
|
||||
<EmbeddedResource Include="Data\autoDeclarativeServices.xml" />
|
||||
<EmbeddedResource Include="Data\DTCAppContextNoInterfaces.xml" />
|
||||
<EmbeddedResource Include="Data\DTCAppContextNoInterfaces.xml">
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Data\Generic\GenericAdoTemplateTests.xml" />
|
||||
<EmbeddedResource Include="Data\nativeAdoTests.xml" />
|
||||
<EmbeddedResource Include="Data\oracleAdoTemplateTests.xml" />
|
||||
|
||||
Reference in New Issue
Block a user