Initial import!
This commit is contained in:
10
test/Spring/Spring.Data.Tests/AssemblyInfo.cs
Normal file
10
test/Spring/Spring.Data.Tests/AssemblyInfo.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
//
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
//
|
||||
[assembly: AssemblyTitle("Spring.Data Tests")]
|
||||
[assembly: AssemblyDescription("Unit tests for Spring.Data assembly")]
|
||||
@@ -0,0 +1,15 @@
|
||||
using NUnit.Framework;
|
||||
namespace Spring.Dao
|
||||
{
|
||||
[TestFixture]
|
||||
public class IncorrectResultSizeDataAccessExceptionTests
|
||||
{
|
||||
[Test]
|
||||
public void SizeGetter( )
|
||||
{
|
||||
IncorrectResultSizeDataAccessException ex = new IncorrectResultSizeDataAccessException( 1, 4 );
|
||||
Assert.AreEqual( 1, ex.ExpectedSize );
|
||||
Assert.AreEqual( 4, ex.ActualSize );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using NUnit.Framework;
|
||||
namespace Spring.Dao
|
||||
{
|
||||
[TestFixture]
|
||||
public class IncorrectUpdateSemanticsDataAccessExceptionTests
|
||||
{
|
||||
[Serializable]
|
||||
public class SampleException : IncorrectUpdateSemanticsDataAccessException
|
||||
{
|
||||
public SampleException() : base() {}
|
||||
public SampleException( string message ) : base( message ) {}
|
||||
public SampleException( string message, Exception inner ) : base( message, inner ) {}
|
||||
protected SampleException( SerializationInfo info, StreamingContext context ) : base( info, context ) {}
|
||||
public override bool DataWasUpdated
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using NUnit.Framework;
|
||||
namespace Spring.Dao
|
||||
{
|
||||
[TestFixture]
|
||||
public class UncategorizedDataAccessExceptionTests
|
||||
{
|
||||
[Serializable]
|
||||
public class SampleException : UncategorizedDataAccessException
|
||||
{
|
||||
public SampleException() : base() {}
|
||||
public SampleException( string message ) : base( message ) {}
|
||||
public SampleException( string message, Exception inner ) : base( message, inner ) {}
|
||||
protected SampleException( SerializationInfo info, StreamingContext context ) : base( info, context ) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
95
test/Spring/Spring.Data.Tests/Data/AutoDeclarativeTxTests.cs
Normal file
95
test/Spring/Spring.Data.Tests/Data/AutoDeclarativeTxTests.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2005 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using NUnit.Framework;
|
||||
using Spring.Aop.Framework;
|
||||
using Spring.Aop.Framework.DynamicProxy;
|
||||
using Spring.Aop.Support;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Common.Logging;
|
||||
using Common.Logging.Simple;
|
||||
using Spring.Objects;
|
||||
using Spring.Transaction;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Test case that uses the approach of automatically creating
|
||||
/// declarative transaction interceptors for objects identified via means
|
||||
/// of transaction attributes.
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack (.NET)</author>
|
||||
/// <version>$Id: AutoDeclarativeTxTests.cs,v 1.4 2007/08/21 19:26:04 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class AutoDeclarativeTxTests
|
||||
{
|
||||
private IApplicationContext ctx;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
//LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter();
|
||||
ctx =
|
||||
new XmlApplicationContext("assembly://Spring.Data.Tests/Spring.Data/AutoDeclarativeTxTests.xml");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void CoordinatorDeclarativeWithAttributes()
|
||||
{
|
||||
ITestCoord coord = ctx["testCoordinator"] as ITestCoord;
|
||||
Assert.IsNotNull(coord);
|
||||
CallCountingTransactionManager ccm = ctx["transactionManager"] as CallCountingTransactionManager;
|
||||
Assert.IsNotNull(ccm);
|
||||
LoggingAroundAdvice advice = (LoggingAroundAdvice)ctx["consoleLoggingAroundAdvice"];
|
||||
Assert.IsNotNull(advice);
|
||||
|
||||
ITestObjectMgr testObjectMgr = ctx["testObjectManager"] as ITestObjectMgr;
|
||||
Assert.IsNotNull(testObjectMgr);
|
||||
//Proxied due to NameMatchMethodPointcutAdvisor
|
||||
Assert.IsTrue(AopUtils.IsAopProxy(coord));
|
||||
|
||||
//Proxied due to DefaultAdvisorAutoProxyCreator
|
||||
Assert.IsTrue(AopUtils.IsAopProxy(testObjectMgr));
|
||||
|
||||
|
||||
TestObject to1 = new TestObject("Jack", 7);
|
||||
TestObject to2 = new TestObject("Jill", 6);
|
||||
|
||||
Assert.AreEqual(0, ccm.begun);
|
||||
Assert.AreEqual(0, ccm.commits);
|
||||
Assert.AreEqual(0, advice.numInvoked);
|
||||
|
||||
coord.WorkOn(to1,to2);
|
||||
|
||||
Assert.AreEqual(1, ccm.begun);
|
||||
Assert.AreEqual(1, ccm.commits);
|
||||
Assert.AreEqual(1, advice.numInvoked);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns='http://www.springframework.net'
|
||||
xmlns:d="http://www.springframework.net/database">
|
||||
|
||||
|
||||
|
||||
<object id="transactionManager" type="Spring.Transaction.CallCountingTransactionManager, Spring.Data.Tests">
|
||||
|
||||
</object>
|
||||
|
||||
|
||||
<!-- declarative [Transaction] attributes applies here -->
|
||||
<object id="testObjectManager" type="Spring.Data.TestObjectMgr, Spring.Data.Tests">
|
||||
|
||||
</object>
|
||||
|
||||
|
||||
<object id="consoleLoggingAroundAdvice" type="Spring.Data.LoggingAroundAdvice, Spring.Data.Tests"/>
|
||||
|
||||
|
||||
<object id="testCoordinator" type="Spring.Data.TestCoord, Spring.Data.Tests">
|
||||
<property name="TestObjectMgr" ref="testObjectManager"/>
|
||||
</object>
|
||||
|
||||
|
||||
|
||||
<object id="aroundAdvisor" type="Spring.Aop.Support.NameMatchMethodPointcutAdvisor, Spring.Aop">
|
||||
<property name="Advice" ref="consoleLoggingAroundAdvice"/>
|
||||
<property name="MappedNames">
|
||||
<list>
|
||||
<value>WorkOn</value>
|
||||
</list>
|
||||
</property>
|
||||
</object>
|
||||
|
||||
<!--
|
||||
<object id="testObjManagerProxy" type="Spring.Aop.Framework.ProxyFactoryObject, Spring.Aop">
|
||||
<property name="target" ref="testObjectManager"/>
|
||||
<property name="InterceptorNames">
|
||||
<list>
|
||||
<value>aroundAdvisor</value>
|
||||
</list>
|
||||
</property>
|
||||
</object>
|
||||
-->
|
||||
|
||||
<!-- The rest of the config file is common no matter how many objects you add -->
|
||||
<!-- that you would like to have declarative tx management applied to -->
|
||||
|
||||
<object id="autoProxyCreator"
|
||||
type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator, Spring.Aop">
|
||||
</object>
|
||||
|
||||
<object id="transactionAdvisor"
|
||||
type="Spring.Transaction.Interceptor.TransactionAttributeSourceAdvisor, Spring.Data"
|
||||
autowire="constructor">
|
||||
</object>
|
||||
|
||||
|
||||
<object id="transactionInterceptor"
|
||||
type="Spring.Transaction.Interceptor.TransactionInterceptor, Spring.Data" autowire="byType">
|
||||
</object>
|
||||
|
||||
<object id="attributeTransactionAttributeSource"
|
||||
type="Spring.Transaction.Interceptor.AttributesTransactionAttributeSource, Spring.Data">
|
||||
</object>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</objects>
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns='http://www.springframework.net'>
|
||||
|
||||
<object id="Test-SqlServer-2.0" type="Spring.Data.Common.DbProvider, Spring.Data" singleton="false">
|
||||
<constructor-arg name="dbMetaData">
|
||||
<object type="Spring.Data.Common.DbMetadata">
|
||||
<constructor-arg name="productName" value="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0" />
|
||||
<constructor-arg name="assemblyName" value="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="connectionType" value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="commandType" value="System.Data.SqlClient.SqlCommand, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="parameterType" value="System.Data.SqlClient.SqlParameter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="dataAdapterType" value="System.Data.SqlClient.SqlDataAdapter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="commandBuilderType" value="System.Data.SqlClient.SqlCommandBuilder, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="commandBuilderDeriveParametersMethod" value="DeriveParameters"/>
|
||||
<constructor-arg name="parameterDbType" value="System.Data.SqlDbType, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="parameterDbTypeProperty" value="SqlDbType"/>
|
||||
<constructor-arg name="parameterIsNullableProperty" value="IsNullable"/>
|
||||
<constructor-arg name="parameterNamePrefix" value="@"/>
|
||||
<constructor-arg name="exceptionType" value="System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="useParameterNamePrefixInParameterCollection" value="true"/>
|
||||
<constructor-arg name="useParameterPrefixInSql" value="true"/>
|
||||
<constructor-arg name="bindByName" value="true"/>
|
||||
<!-- this is only true for .net 1.1 kept it here just in case we want to revert back to this strategy for
|
||||
obtaining error codes-->
|
||||
<constructor-arg name="errorCodeExceptionExpression" value="Errors[0].Number.ToString()"/>
|
||||
|
||||
<!-- 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>
|
||||
</property>
|
||||
<property name="ErrorCodes.PermissionDeniedCodes">
|
||||
<value>229</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.DataIntegrityViolationCodes">
|
||||
<value>544,2627,8114,8115</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.DeadlockLoserCodes">
|
||||
<value>1205</value>
|
||||
</property>
|
||||
</object>
|
||||
</constructor-arg>
|
||||
|
||||
</object>
|
||||
|
||||
<object id="Test-SqlServer-2.0-BadErrorCodeExpression" type="Spring.Data.Common.DbProvider, Spring.Data" singleton="false">
|
||||
<constructor-arg name="dbMetaData">
|
||||
<object type="Spring.Data.Common.DbMetadata">
|
||||
<constructor-arg name="productName" value="Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0" />
|
||||
<constructor-arg name="assemblyName" value="System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="connectionType" value="System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="commandType" value="System.Data.SqlClient.SqlCommand, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="parameterType" value="System.Data.SqlClient.SqlParameter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="dataAdapterType" value="System.Data.SqlClient.SqlDataAdapter, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="commandBuilderType" value="System.Data.SqlClient.SqlCommandBuilder, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="commandBuilderDeriveParametersMethod" value="DeriveParameters"/>
|
||||
<constructor-arg name="parameterDbType" value="System.Data.SqlDbType, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="parameterDbTypeProperty" value="SqlDbType"/>
|
||||
<constructor-arg name="parameterIsNullableProperty" value="IsNullable"/>
|
||||
<constructor-arg name="parameterNamePrefix" value="@"/>
|
||||
<constructor-arg name="exceptionType" value="System.Data.SqlClient.SqlException, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
|
||||
<constructor-arg name="useParameterNamePrefixInParameterCollection" value="true"/>
|
||||
<constructor-arg name="useParameterPrefixInSql" value="true"/>
|
||||
<constructor-arg name="bindByName" value="true"/>
|
||||
<!-- this is only true for .net 1.1 kept it here just in case we want to revert back to this strategy for
|
||||
obtaining error codes-->
|
||||
<constructor-arg name="errorCodeExceptionExpression" value="156"/>
|
||||
|
||||
<!-- 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>
|
||||
</property>
|
||||
<property name="ErrorCodes.PermissionDeniedCodes">
|
||||
<value>229</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.DataIntegrityViolationCodes">
|
||||
<value>544,2627,8114,8115</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.DeadlockLoserCodes">
|
||||
<value>1205</value>
|
||||
</property>
|
||||
</object>
|
||||
</constructor-arg>
|
||||
|
||||
</object>
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns='http://www.springframework.net'>
|
||||
<object id="MySqlPersonal" type="Spring.Data.Common.DbProvider, Spring.Data" lazy-init="true">
|
||||
<constructor-arg name="dbMetaData">
|
||||
<object type="Spring.Data.Common.DbMetadata">
|
||||
<constructor-arg name="productName" value="MySQL, MySQL provider 1.0.7.30072" />
|
||||
<constructor-arg name="assemblyName" value="MySql.Data, Version=1.0.7.30072, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
|
||||
<constructor-arg name="connectionType" value="MySql.Data.MySqlClient.MySqlConnection"/>
|
||||
<constructor-arg name="commandType" value="MySql.Data.MySqlClient.MySqlCommand"/>
|
||||
<constructor-arg name="parameterType" value="MySql.Data.MySqlClient.MySqlParameter"/>
|
||||
<constructor-arg name="dataAdapterType" value="MySql.Data.MySqlClient.MySqlDataAdapter"/>
|
||||
<constructor-arg name="commandBuilderType" value="MySql.Data.MySqlClient.MySqlCommandBuilder"/>
|
||||
<constructor-arg name="commandBuilderDeriveParametersMethod" value="DeriveParameters"/>
|
||||
<constructor-arg name="parameterDbType" value="MySql.Data.MySqlClient.MySqlDbType"/>
|
||||
<constructor-arg name="parameterDbTypeProperty" value="MySqlDbType"/>
|
||||
<constructor-arg name="parameterIsNullableProperty" value="IsNullable"/>
|
||||
<constructor-arg name="parameterNamePrefix" value="?"/>
|
||||
<constructor-arg name="exceptionType" value="MySql.Data.MySqlClient.MySqlException"/>
|
||||
<constructor-arg name="useParameterNamePrefixInParameterCollection" value="true"/>
|
||||
<constructor-arg name="bindByName" value="true"/>
|
||||
<!-- this is only true for .net 1.1 kept it here just in case we want to revert back to this strategy for
|
||||
obtaining error codes-->
|
||||
<constructor-arg name="errorCodeExceptionExpression" value="Number.ToString()"/>
|
||||
|
||||
<property name="ErrorCodes.badSqlGrammarCodes">
|
||||
<value>1054,1064,1146</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.DataAccessResourceFailureCodes">
|
||||
<value>1</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.DataIntegrityViolationCodes">
|
||||
<value>1062</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.CannotAcquireLockCodes">
|
||||
<value>1205</value>
|
||||
</property>
|
||||
<property name="ErrorCodes.DeadlockLoserCodes">
|
||||
<value>1213</value>
|
||||
</property>
|
||||
</object>
|
||||
</constructor-arg>
|
||||
</object>
|
||||
</objects>
|
||||
@@ -0,0 +1,79 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 the original author or authors.
|
||||
*
|
||||
* 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 (NET_2_0)
|
||||
#region Imports
|
||||
|
||||
using System.Data;
|
||||
using System.Data.OracleClient;
|
||||
using NUnit.Framework;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Data.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains tests for DbParameters
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: DbParametersTests.cs,v 1.3 2007/12/06 06:58:54 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class DbParametersTests
|
||||
{
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OracleClient()
|
||||
{
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("System.Data.OracleClient");
|
||||
DbParameters dbParameters = new DbParameters(dbProvider);
|
||||
dbParameters.Add("p1", DbType.String);
|
||||
IDataParameter parameter = dbParameters[0];
|
||||
Assert.AreEqual("p1", parameter.ParameterName);
|
||||
dbParameters.SetValue("p1", "foo");
|
||||
IDbDataParameter springParameter = dbParameters.GetValue("p1") as IDbDataParameter;
|
||||
Assert.IsNotNull(springParameter);
|
||||
Assert.AreEqual("foo", springParameter.Value);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SqlClient()
|
||||
{
|
||||
IDbProvider dbProvider = DbProviderFactory.GetDbProvider("System.Data.SqlClient");
|
||||
DbParameters dbParameters = new DbParameters(dbProvider);
|
||||
dbParameters.Add("p1", DbType.String);
|
||||
IDataParameter parameter = dbParameters[0];
|
||||
Assert.AreEqual("@p1", parameter.ParameterName);
|
||||
dbParameters.SetValue("p1", "foo");
|
||||
IDbDataParameter springParameter = dbParameters.GetValue("p1") as IDbDataParameter;
|
||||
Assert.IsNotNull(springParameter);
|
||||
Assert.AreEqual("foo", springParameter.Value);
|
||||
}
|
||||
|
||||
private static void TestParameterNaming(DbParameters dbParameters)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,250 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2006 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context;
|
||||
using Spring.Core.IO;
|
||||
using Spring.Threading;
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Data.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Test for loading of DbProviders
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack (.NET)</author>
|
||||
/// <version>$Id: DbProviderFactoryTests.cs,v 1.13 2008/04/02 19:37:20 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class DbProviderFactoryTests
|
||||
{
|
||||
#region Helper classes for threading tests
|
||||
|
||||
public class AsyncTestDbProviderFactory : AsyncTestTask
|
||||
{
|
||||
private string providerName;
|
||||
|
||||
public AsyncTestDbProviderFactory(int iterations, string providerName)
|
||||
: base(iterations)
|
||||
{
|
||||
this.providerName = providerName;
|
||||
}
|
||||
|
||||
public override void DoExecute()
|
||||
{
|
||||
object result = DbProviderFactory.GetDbProvider(providerName);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private static string altConfig = "assembly://Spring.Data.Tests/Spring.Data.Common/AdditionalProviders.xml";
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
DbProviderFactory.DBPROVIDER_ADDITIONAL_RESOURCE_NAME = altConfig;
|
||||
}
|
||||
|
||||
#if NET_2_0
|
||||
|
||||
[Test]
|
||||
public void ThreadSafety()
|
||||
{
|
||||
AsyncTestTask t1 = new AsyncTestDbProviderFactory(1000, "SqlServer-2.0").Start();
|
||||
AsyncTestTask t2 = new AsyncTestDbProviderFactory(1000, "SqlServer-2.0").Start();
|
||||
AsyncTestTask t3 = new AsyncTestDbProviderFactory(1000, "SqlServer-2.0").Start();
|
||||
AsyncTestTask t4 = new AsyncTestDbProviderFactory(1000, "SqlServer-2.0").Start();
|
||||
|
||||
t1.AssertNoException();
|
||||
t2.AssertNoException();
|
||||
t3.AssertNoException();
|
||||
t4.AssertNoException();
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Can't guarantee test order")]
|
||||
public void AdditionalResourceName()
|
||||
{
|
||||
|
||||
IDbProvider provider = DbProviderFactory.GetDbProvider("Test-SqlServer-2.0");
|
||||
Assert.IsNotNull(provider);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Can't guarantee test order")]
|
||||
public void BadErrorExpression()
|
||||
{
|
||||
|
||||
IDbProvider provider = DbProviderFactory.GetDbProvider("Test-SqlServer-2.0-BadErrorCodeExpression");
|
||||
Assert.IsNotNull(provider);
|
||||
string errorCode = provider.ExtractError(new Exception("foo"));
|
||||
Assert.AreEqual("156",errorCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DefaultInstanceWithSqlServer2005()
|
||||
{
|
||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US", false);
|
||||
IApplicationContext ctx = DbProviderFactory.ApplicationContext;
|
||||
Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR", false);
|
||||
IDbProvider provider = DbProviderFactory.GetDbProvider("SqlServer-2.0");
|
||||
AssertIsSqlServer2005(provider);
|
||||
provider = DbProviderFactory.GetDbProvider("System.Data.SqlClient");
|
||||
AssertIsSqlServer2005(provider);
|
||||
Assert.IsNull(provider.ConnectionString);
|
||||
Assert.IsNotNull(provider.CreateCommand());
|
||||
Assert.IsNotNull(provider.CreateCommandBuilder());
|
||||
Assert.IsNotNull(provider.CreateConnection());
|
||||
Assert.IsNotNull(provider.CreateDataAdapter());
|
||||
Assert.IsNotNull(provider.CreateParameter());
|
||||
Assert.AreEqual("@Foo", provider.CreateParameterName("Foo"));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void DefaultInstanceWithOleDb20()
|
||||
{
|
||||
IDbProvider provider = DbProviderFactory.GetDbProvider("OleDb-2.0");
|
||||
Assert.AreEqual("OleDb, provider V2.0.0.0 in framework .NET V2", provider.DbMetadata.ProductName);
|
||||
Assert.IsNotNull(provider.CreateCommand());
|
||||
Assert.IsNotNull(provider.CreateCommandBuilder());
|
||||
Assert.IsNotNull(provider.CreateConnection());
|
||||
Assert.IsNotNull(provider.CreateDataAdapter());
|
||||
Assert.IsNotNull(provider.CreateParameter());
|
||||
Assert.AreEqual("?", provider.CreateParameterName("Foo"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DefaultInstanceWithMicrsoftOracleClient20()
|
||||
{
|
||||
IDbProvider provider = DbProviderFactory.GetDbProvider("OracleClient-2.0");
|
||||
Assert.AreEqual("Oracle, Microsoft provider V2.0.0.0", provider.DbMetadata.ProductName);
|
||||
Assert.IsNotNull(provider.CreateCommand());
|
||||
Assert.IsNotNull(provider.CreateCommandBuilder());
|
||||
Assert.IsNotNull(provider.CreateConnection());
|
||||
Assert.IsNotNull(provider.CreateDataAdapter());
|
||||
Assert.IsNotNull(provider.CreateParameter());
|
||||
Assert.AreEqual(":Foo", provider.CreateParameterName("Foo"));
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
[Ignore("until find out if can add oracle.dll to cvs repository")]
|
||||
public void DefaultInstanceWithOracleClient20()
|
||||
{
|
||||
IDbProvider provider = DbProviderFactory.GetDbProvider("OracleODP-2.0");
|
||||
Assert.AreEqual("Oracle, Oracle provider V2.102.2.20", provider.DbMetadata.ProductName);
|
||||
Assert.IsNotNull(provider.CreateCommand());
|
||||
Assert.IsNotNull(provider.CreateCommandBuilder());
|
||||
Assert.IsNotNull(provider.CreateConnection());
|
||||
Assert.IsNotNull(provider.CreateDataAdapter());
|
||||
Assert.IsNotNull(provider.CreateParameter());
|
||||
Assert.AreEqual(":Foo", provider.CreateParameterName("Foo"));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
[Test]
|
||||
public void DefaultInstanceWithMySql()
|
||||
{
|
||||
DbProviderFactory.DBPROVIDER_ADDITIONAL_RESOURCE_NAME =
|
||||
"assembly://Spring.Data.Tests/Spring.Data.Common/AdditonalProviders.xml";
|
||||
IDbProvider provider = DbProviderFactory.GetDbProvider("MySqlPersonal");
|
||||
Assert.AreEqual("MySQL, MySQL provider 1.0.7.30072", provider.DbMetadata.ProductName);
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
[Test]
|
||||
public void TestDb2()
|
||||
{
|
||||
IApplicationContext ctx = DbProviderFactory.ApplicationContext;
|
||||
string[] dbProviderNames = ctx.GetObjectNamesForType(typeof(IDbProvider));
|
||||
Console.WriteLine(
|
||||
String.Format("{0} DbProviders Available. [{1}]", dbProviderNames.Length,
|
||||
StringUtils.ArrayToCommaDelimitedString(dbProviderNames)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if NET_1_1
|
||||
|
||||
[Test]
|
||||
public void DefaultInstanceWithOleDb11()
|
||||
{
|
||||
IDbProvider provider = DbProviderFactory.GetDbProvider("OleDb-1.1");
|
||||
Assert.AreEqual("OleDb, provider V1.0.5000.0 in framework .NET V1.1", provider.DbMetadata.ProductName);
|
||||
Assert.IsNotNull(provider.CreateCommand());
|
||||
Assert.IsNotNull(provider.CreateCommandBuilder());
|
||||
Assert.IsNotNull(provider.CreateConnection());
|
||||
Assert.IsNotNull(provider.CreateDataAdapter());
|
||||
Assert.IsNotNull(provider.CreateParameter());
|
||||
Assert.AreEqual("?", provider.CreateParameterName("Foo"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DefaultInstanceWithSqlServer2000()
|
||||
{
|
||||
IDbProvider provider = DbProviderFactory.GetDbProvider("SqlServer-1.1");
|
||||
AssertIsSqlServer2000(provider);
|
||||
Assert.IsNull(provider.ConnectionString);
|
||||
Assert.IsNotNull(provider.CreateCommand());
|
||||
Assert.IsNotNull(provider.CreateCommandBuilder());
|
||||
Assert.IsNotNull(provider.CreateConnection());
|
||||
Assert.IsNotNull(provider.CreateDataAdapter());
|
||||
Assert.IsNotNull(provider.CreateParameter());
|
||||
Assert.AreEqual("@Foo", provider.CreateParameterName("Foo"));
|
||||
}
|
||||
|
||||
private void AssertIsSqlServer2000(IDbProvider provider)
|
||||
{
|
||||
Assert.AreEqual("Microsoft SQL Server, provider V1.0.5000.0 in framework .NET V1.1",
|
||||
provider.DbMetadata.ProductName);
|
||||
AssertCommonSqlServerErrorCodes(provider);
|
||||
}
|
||||
#endif
|
||||
private void AssertIsSqlServer2005(IDbProvider provider)
|
||||
{
|
||||
Assert.AreEqual("Microsoft SQL Server, provider V2.0.0.0 in framework .NET V2.0",
|
||||
provider.DbMetadata.ProductName);
|
||||
AssertCommonSqlServerErrorCodes(provider);
|
||||
}
|
||||
|
||||
private static void AssertCommonSqlServerErrorCodes(IDbProvider provider)
|
||||
{
|
||||
ErrorCodes codes = provider.DbMetadata.ErrorCodes;
|
||||
Assert.IsTrue(codes.BadSqlGrammarCodes.Length > 0);
|
||||
Assert.IsTrue(codes.DataIntegrityViolationCodes.Length > 0);
|
||||
// This had better be a Bad SQL Grammar code
|
||||
Assert.IsTrue(Array.IndexOf(codes.BadSqlGrammarCodes, "156") >= 0);
|
||||
// This had better NOT be
|
||||
Assert.IsFalse(Array.IndexOf(codes.BadSqlGrammarCodes, "1xx56") >= 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2008 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.Data;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Data.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains tests for UserCredentialsDbProvider
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: UserCredentialsDbProviderTests.cs,v 1.1 2008/01/29 18:17:48 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class UserCredentialsDbProviderTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StaticCredentials()
|
||||
{
|
||||
IDbProvider dbProvider = (IDbProvider)mocks.CreateMock(typeof(IDbProvider));
|
||||
IDbConnection connection = (IDbConnection)mocks.CreateMock(typeof(IDbConnection));
|
||||
using (mocks.Ordered())
|
||||
{
|
||||
Expect.Call(dbProvider.CreateConnection()).Return(connection);
|
||||
Expect.Call(dbProvider.ConnectionString).Return(
|
||||
@"Data Source=MARKT60\SQL2005;Database=Spring;Trusted_Connection=False");
|
||||
Expect.Call(connection.ConnectionString = @"Data Source=MARKT60\SQL2005;Database=Spring;Trusted_Connection=False;User ID=springqa;Password=springqa");
|
||||
}
|
||||
|
||||
mocks.ReplayAll();
|
||||
|
||||
UserCredentialsDbProvider provider = new UserCredentialsDbProvider();
|
||||
provider.TargetDbProvider = dbProvider;
|
||||
provider.Username = "User ID=springqa";
|
||||
provider.Password = "Password=springqa";
|
||||
Assert.AreEqual(connection, provider.CreateConnection());
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoCredentials()
|
||||
{
|
||||
IDbProvider dbProvider = (IDbProvider)mocks.CreateMock(typeof(IDbProvider));
|
||||
IDbConnection connection = (IDbConnection)mocks.CreateMock(typeof(IDbConnection));
|
||||
using (mocks.Ordered())
|
||||
{
|
||||
Expect.Call(dbProvider.CreateConnection()).Return(connection);
|
||||
}
|
||||
|
||||
mocks.ReplayAll();
|
||||
|
||||
UserCredentialsDbProvider provider = new UserCredentialsDbProvider();
|
||||
provider.TargetDbProvider = dbProvider;
|
||||
Assert.AreEqual(connection, provider.CreateConnection());
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ThreadBoundCredentials()
|
||||
{
|
||||
IDbProvider dbProvider = (IDbProvider)mocks.CreateMock(typeof(IDbProvider));
|
||||
IDbConnection connection = (IDbConnection)mocks.CreateMock(typeof(IDbConnection));
|
||||
using (mocks.Ordered())
|
||||
{
|
||||
Expect.Call(dbProvider.CreateConnection()).Return(connection);
|
||||
Expect.Call(dbProvider.ConnectionString).Return(
|
||||
@"Data Source=MARKT60\SQL2005;Database=Spring;Trusted_Connection=False");
|
||||
Expect.Call(connection.ConnectionString = @"Data Source=MARKT60\SQL2005;Database=Spring;Trusted_Connection=False;User ID=springqa;Password=springqa");
|
||||
}
|
||||
|
||||
mocks.ReplayAll();
|
||||
|
||||
UserCredentialsDbProvider provider = new UserCredentialsDbProvider();
|
||||
provider.TargetDbProvider = dbProvider;
|
||||
provider.SetCredentialsForCurrentThread("User ID=springqa", "Password=springqa");
|
||||
Assert.AreEqual(connection, provider.CreateConnection());
|
||||
|
||||
mocks.VerifyAll();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,274 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 the original author or authors.
|
||||
*
|
||||
* 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 (!NET_1_0)
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.EnterpriseServices;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Data.Support;
|
||||
using Spring.Transaction;
|
||||
using Spring.Transaction.Support;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Data.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains tests for ServiceDomainTransactionManager
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: ServiceDomainTransactionManagerTests.cs,v 1.5 2007/12/07 07:31:05 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class ServiceDomainTransactionManagerTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TransactionCommit()
|
||||
{
|
||||
#region Mock Setup
|
||||
IServiceDomainAdapter txAdapter = (IServiceDomainAdapter) mocks.CreateMock(typeof (IServiceDomainAdapter));
|
||||
using (mocks.Ordered())
|
||||
{
|
||||
Expect.Call(txAdapter.IsInTransaction).Return(false);
|
||||
SimpleServiceConfig serviceConfig = new SimpleServiceConfig();
|
||||
ConfigureServiceConfig(serviceConfig, true);
|
||||
txAdapter.Enter(serviceConfig);
|
||||
|
||||
//ProcessCommit - status.GlobalRollbackOnly check
|
||||
Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
|
||||
//DoCommit - status.GlobalRollbackOnly check
|
||||
Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
|
||||
|
||||
Expect.Call(txAdapter.IsInTransaction).Return(true);
|
||||
//DoCommit - check to call SetComplete or SetAbort
|
||||
Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
|
||||
txAdapter.SetComplete();
|
||||
Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Commited);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
mocks.ReplayAll();
|
||||
|
||||
IPlatformTransactionManager tm = new ServiceDomainPlatformTransactionManager(txAdapter);
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
tt.Execute(new TransactionDelegate(TransactionCommitMethod));
|
||||
|
||||
Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
|
||||
mocks.VerifyAll();
|
||||
|
||||
}
|
||||
|
||||
private object TransactionCommitMethod(ITransactionStatus status)
|
||||
{
|
||||
Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
return null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TransactionRollback()
|
||||
{
|
||||
#region Mock Setup
|
||||
IServiceDomainAdapter txAdapter = (IServiceDomainAdapter)mocks.CreateMock(typeof(IServiceDomainAdapter));
|
||||
using (mocks.Ordered())
|
||||
{
|
||||
|
||||
Expect.Call(txAdapter.IsInTransaction).Return(false);
|
||||
SimpleServiceConfig serviceConfig = new SimpleServiceConfig();
|
||||
ConfigureServiceConfig(serviceConfig, true);
|
||||
txAdapter.Enter(serviceConfig);
|
||||
Expect.Call(txAdapter.IsInTransaction).Return(true);
|
||||
txAdapter.SetAbort();
|
||||
Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Commited);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
mocks.ReplayAll();
|
||||
|
||||
IPlatformTransactionManager tm = new ServiceDomainPlatformTransactionManager(txAdapter);
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
|
||||
Assert.IsTrue(!TransactionSynchronizationManager.SynchronizationActive, "Synchronizations not active");
|
||||
|
||||
Exception ex = new ArgumentException("test exception");
|
||||
try
|
||||
{
|
||||
tt.Execute(new TransactionRollbackTxCallback(ex));
|
||||
Assert.Fail("Should have thrown exception");
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
Assert.AreEqual(ex, e);
|
||||
}
|
||||
|
||||
Assert.IsTrue(!TransactionSynchronizationManager.SynchronizationActive, "Synchronizations not active");
|
||||
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void PropagationRequiresNewWithExistingTransaction()
|
||||
{
|
||||
#region Mock Setup
|
||||
IServiceDomainAdapter txAdapter = (IServiceDomainAdapter)mocks.CreateMock(typeof(IServiceDomainAdapter));
|
||||
using (mocks.Ordered())
|
||||
{
|
||||
|
||||
Expect.Call(txAdapter.IsInTransaction).Return(false);
|
||||
SimpleServiceConfig serviceConfig = new SimpleServiceConfig();
|
||||
ConfigureServiceConfig(serviceConfig, true);
|
||||
txAdapter.Enter(serviceConfig);
|
||||
|
||||
|
||||
Expect.Call(txAdapter.IsInTransaction).Return(true);
|
||||
// inner tx
|
||||
ConfigureServiceConfig(serviceConfig, false);
|
||||
serviceConfig.TransactionOption = TransactionOption.RequiresNew;
|
||||
serviceConfig.IsolationLevel = TransactionIsolationLevel.ReadCommitted;
|
||||
txAdapter.Enter(serviceConfig);
|
||||
Expect.Call(txAdapter.IsInTransaction).Return(true);
|
||||
txAdapter.SetAbort();
|
||||
Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Aborted);
|
||||
// innter tx aborted
|
||||
|
||||
|
||||
//ProcessCommit - status.GlobalRollbackOnly check
|
||||
Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
|
||||
//DoCommit - status.GlobalRollbackOnly check
|
||||
Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
|
||||
|
||||
Expect.Call(txAdapter.IsInTransaction).Return(true);
|
||||
//DoCommit - check to call SetComplete or SetAbort
|
||||
Expect.Call(txAdapter.MyTransactionVote).Return(TransactionVote.Commit);
|
||||
txAdapter.SetComplete();
|
||||
|
||||
Expect.Call(txAdapter.Leave()).Return(TransactionStatus.Commited);
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
mocks.ReplayAll();
|
||||
|
||||
IPlatformTransactionManager tm = new ServiceDomainPlatformTransactionManager(txAdapter);
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
tt.PropagationBehavior = TransactionPropagation.RequiresNew;
|
||||
tt.Execute(new PropagationRequiresNewWithExistingTransactionCallbackSD(tt));
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
#region Helper Methods
|
||||
private SimpleServiceConfig ConfigureServiceConfig(SimpleServiceConfig serviceConfig, bool standardIsolationAndProp)
|
||||
{
|
||||
serviceConfig.TransactionDescription = null;
|
||||
|
||||
serviceConfig.TrackingEnabled = true;
|
||||
serviceConfig.TrackingAppName = "Spring.NET";
|
||||
serviceConfig.TrackingComponentName = "ServiceDomainPlatformTransactionManager";
|
||||
if (standardIsolationAndProp)
|
||||
{
|
||||
serviceConfig.TransactionOption = TransactionOption.Required;
|
||||
serviceConfig.IsolationLevel = TransactionIsolationLevel.ReadCommitted;
|
||||
}
|
||||
return serviceConfig;
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region Supporting class for TransactionRollback test
|
||||
|
||||
internal class TransactionRollbackTxCallback : ITransactionCallback
|
||||
{
|
||||
private Exception exception;
|
||||
|
||||
public TransactionRollbackTxCallback(Exception exception)
|
||||
{
|
||||
this.exception = exception;
|
||||
}
|
||||
|
||||
public object DoInTransaction(ITransactionStatus status)
|
||||
{
|
||||
Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
|
||||
throw exception;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Supporting class for PropagationRequiresNewWithExistingTransactionCallback test
|
||||
internal class PropagationRequiresNewWithExistingTransactionCallbackSD : ITransactionCallback
|
||||
{
|
||||
private TransactionTemplate tt;
|
||||
|
||||
public PropagationRequiresNewWithExistingTransactionCallbackSD(TransactionTemplate tt)
|
||||
{
|
||||
this.tt = tt;
|
||||
}
|
||||
|
||||
public object DoInTransaction(ITransactionStatus status)
|
||||
{
|
||||
Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
|
||||
Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active");
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
|
||||
tt.Execute(new TransactionDelegate(TransactionMethod));
|
||||
Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
|
||||
return null;
|
||||
}
|
||||
|
||||
private object TransactionMethod(ITransactionStatus status)
|
||||
{
|
||||
Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active");
|
||||
Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
|
||||
status.RollbackOnly = true;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,150 @@
|
||||
#if NET_2_0
|
||||
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.Reflection;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Data.Core;
|
||||
using Spring.Objects;
|
||||
using Spring.Transaction;
|
||||
using Spring.Transaction.Support;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Data.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains tests for TxScopeTransactionManager and will directly a real TransactionScope object
|
||||
/// but does not access any database
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: TxScopeTransactionManagerIntegrationTests.cs,v 1.1 2007/11/30 18:38:59 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class TxScopeTransactionManagerIntegrationTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
Assert.IsTrue(TransactionSynchronizationManager.ResourceDictionary.Count == 0);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
Assert.AreEqual(System.Data.IsolationLevel.Unspecified, TransactionSynchronizationManager.CurrentTransactionIsolationLevel);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.ActualTransactionActive);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Commit()
|
||||
{
|
||||
TxScopeTransactionManager tm = new TxScopeTransactionManager();
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
|
||||
//tt.Name = "txName";
|
||||
|
||||
Assert.AreEqual(TransactionSynchronizationState.Always, tm.TransactionSynchronization);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
tt.Execute(CommitTxDelegate);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
}
|
||||
|
||||
public object CommitTxDelegate(ITransactionStatus status)
|
||||
{
|
||||
Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TransactionInformation()
|
||||
{
|
||||
TxScopeTransactionManager tm = new TxScopeTransactionManager();
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
tt.TransactionIsolationLevel = System.Data.IsolationLevel.ReadUncommitted;
|
||||
tt.Execute(TransactionInformationTxDelegate);
|
||||
}
|
||||
|
||||
public object TransactionInformationTxDelegate(ITransactionStatus status)
|
||||
{
|
||||
|
||||
Assert.AreEqual(System.Transactions.IsolationLevel.ReadUncommitted,
|
||||
System.Transactions.Transaction.Current.IsolationLevel);
|
||||
|
||||
Assert.AreEqual(System.Data.IsolationLevel.ReadUncommitted,
|
||||
TransactionSynchronizationManager.CurrentTransactionIsolationLevel);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void Rollback()
|
||||
{
|
||||
ITransactionSynchronization sync =
|
||||
(ITransactionSynchronization) mocks.DynamicMock(typeof (ITransactionSynchronization));
|
||||
sync.BeforeCompletion();
|
||||
LastCall.On(sync).Repeat.Once();
|
||||
sync.AfterCompletion(TransactionSynchronizationStatus.Rolledback);
|
||||
LastCall.On(sync).Repeat.Once();
|
||||
mocks.ReplayAll();
|
||||
|
||||
|
||||
TxScopeTransactionManager tm = new TxScopeTransactionManager();
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
tt.TransactionTimeout = 10;
|
||||
tt.Name = "txName";
|
||||
|
||||
Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsNull(TransactionSynchronizationManager.CurrentTransactionName);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
tt.Execute(delegate (ITransactionStatus status)
|
||||
{
|
||||
Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
|
||||
TransactionSynchronizationManager.RegisterSynchronization(sync);
|
||||
Assert.AreEqual("txName", TransactionSynchronizationManager.CurrentTransactionName);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
status.RollbackOnly = true;
|
||||
return null;
|
||||
}
|
||||
);
|
||||
|
||||
mocks.VerifyAll();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,190 @@
|
||||
#if NET_2_0
|
||||
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Transactions;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Data.Support;
|
||||
using Spring.Transaction;
|
||||
using Spring.Transaction.Support;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Data.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// This calss contains tests for
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: TxScopeTransactionManagerTests.cs,v 1.3 2007/12/07 07:31:05 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class TxScopeTransactionManagerTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
public void TransactionCommit()
|
||||
{
|
||||
ITransactionScopeAdapter txAdapter = (ITransactionScopeAdapter) mocks.CreateMock(typeof(ITransactionScopeAdapter));
|
||||
|
||||
using (mocks.Ordered())
|
||||
{
|
||||
Expect.Call(txAdapter.IsExistingTransaction).Return(false);
|
||||
TransactionOptions txOptions = new TransactionOptions();
|
||||
txOptions.IsolationLevel = IsolationLevel.ReadCommitted;
|
||||
txAdapter.CreateTransactionScope(TransactionScopeOption.Required, txOptions, EnterpriseServicesInteropOption.None);
|
||||
|
||||
Expect.Call(txAdapter.RollbackOnly).Return(false);
|
||||
txAdapter.Complete();
|
||||
txAdapter.Dispose();
|
||||
}
|
||||
mocks.ReplayAll();
|
||||
|
||||
IPlatformTransactionManager tm = new TxScopeTransactionManager(txAdapter);
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
tt.Execute(delegate(ITransactionStatus status)
|
||||
{
|
||||
Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
return null;
|
||||
});
|
||||
|
||||
Assert.IsFalse(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
|
||||
mocks.VerifyAll();
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TransactionRollback()
|
||||
{
|
||||
ITransactionScopeAdapter txAdapter = (ITransactionScopeAdapter)mocks.CreateMock(typeof(ITransactionScopeAdapter));
|
||||
|
||||
using (mocks.Ordered())
|
||||
{
|
||||
Expect.Call(txAdapter.IsExistingTransaction).Return(false);
|
||||
TransactionOptions txOptions = new TransactionOptions();
|
||||
txOptions.IsolationLevel = IsolationLevel.ReadCommitted;
|
||||
txAdapter.CreateTransactionScope(TransactionScopeOption.Required, txOptions, EnterpriseServicesInteropOption.None);
|
||||
txAdapter.Dispose();
|
||||
}
|
||||
mocks.ReplayAll();
|
||||
|
||||
IPlatformTransactionManager tm = new TxScopeTransactionManager(txAdapter);
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
|
||||
Assert.IsTrue(!TransactionSynchronizationManager.SynchronizationActive, "Synchronizations not active");
|
||||
|
||||
Exception ex = new ArgumentException("test exception");
|
||||
try
|
||||
{
|
||||
tt.Execute(delegate(ITransactionStatus status)
|
||||
{
|
||||
Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive);
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
|
||||
if (ex != null) throw ex;
|
||||
return null;
|
||||
});
|
||||
Assert.Fail("Should have thrown exception");
|
||||
}
|
||||
catch (ArgumentException e)
|
||||
{
|
||||
Assert.AreEqual(ex, e);
|
||||
}
|
||||
|
||||
Assert.IsTrue(!TransactionSynchronizationManager.SynchronizationActive, "Synchronizations not active");
|
||||
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PropagationRequiresNewWithExistingTransaction()
|
||||
{
|
||||
|
||||
ITransactionScopeAdapter txAdapter = (ITransactionScopeAdapter)mocks.CreateMock(typeof(ITransactionScopeAdapter));
|
||||
|
||||
using (mocks.Ordered())
|
||||
{
|
||||
Expect.Call(txAdapter.IsExistingTransaction).Return(false);
|
||||
TransactionOptions txOptions = new TransactionOptions();
|
||||
txOptions.IsolationLevel = IsolationLevel.ReadCommitted;
|
||||
txAdapter.CreateTransactionScope(TransactionScopeOption.RequiresNew, txOptions, EnterpriseServicesInteropOption.None);
|
||||
|
||||
//inner tx actions
|
||||
Expect.Call(txAdapter.IsExistingTransaction).Return(true);
|
||||
txAdapter.CreateTransactionScope(TransactionScopeOption.RequiresNew, txOptions, EnterpriseServicesInteropOption.None);
|
||||
txAdapter.Dispose();
|
||||
//end inner tx actions
|
||||
|
||||
Expect.Call(txAdapter.RollbackOnly).Return(false);
|
||||
txAdapter.Complete();
|
||||
txAdapter.Dispose();
|
||||
|
||||
}
|
||||
mocks.ReplayAll();
|
||||
|
||||
IPlatformTransactionManager tm = new TxScopeTransactionManager(txAdapter);
|
||||
TransactionTemplate tt = new TransactionTemplate(tm);
|
||||
tt.PropagationBehavior = TransactionPropagation.RequiresNew;
|
||||
tt.Execute(delegate(ITransactionStatus status)
|
||||
{
|
||||
Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
|
||||
Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active");
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
|
||||
|
||||
tt.Execute(delegate(ITransactionStatus status2)
|
||||
{
|
||||
Assert.IsTrue(TransactionSynchronizationManager.SynchronizationActive, "Synchronization active");
|
||||
Assert.IsTrue(status2.IsNewTransaction, "Is new transaction");
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
|
||||
status2.RollbackOnly = true;
|
||||
return null;
|
||||
});
|
||||
|
||||
|
||||
Assert.IsTrue(status.IsNewTransaction, "Is new transaction");
|
||||
Assert.IsFalse(TransactionSynchronizationManager.CurrentTransactionReadOnly);
|
||||
Assert.IsTrue(TransactionSynchronizationManager.ActualTransactionActive);
|
||||
return null;
|
||||
});
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
15
test/Spring/Spring.Data.Tests/Data/ITestCoord.cs
Normal file
15
test/Spring/Spring.Data.Tests/Data/ITestCoord.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
|
||||
using Spring.Objects;
|
||||
|
||||
namespace Spring.Data
|
||||
{
|
||||
public interface ITestCoord
|
||||
{
|
||||
ITestObjectMgr TestObjectMgr
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
void WorkOn(TestObject to1, TestObject to2);
|
||||
}
|
||||
}
|
||||
11
test/Spring/Spring.Data.Tests/Data/ITestObjectMgr.cs
Normal file
11
test/Spring/Spring.Data.Tests/Data/ITestObjectMgr.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Spring.Objects;
|
||||
|
||||
namespace Spring.Data
|
||||
{
|
||||
public interface ITestObjectMgr
|
||||
{
|
||||
void SaveTwoTestObjects(TestObject to1, TestObject to2);
|
||||
|
||||
void DeleteTwoTestObjects(string name1, string name2);
|
||||
}
|
||||
}
|
||||
25
test/Spring/Spring.Data.Tests/Data/LoggingAroundAdvice.cs
Normal file
25
test/Spring/Spring.Data.Tests/Data/LoggingAroundAdvice.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
using AopAlliance.Intercept;
|
||||
using Common.Logging;
|
||||
|
||||
namespace Spring.Data
|
||||
{
|
||||
public class LoggingAroundAdvice : IMethodInterceptor
|
||||
{
|
||||
public int numInvoked;
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(LoggingAroundAdvice));
|
||||
public object Invoke(IMethodInvocation invocation)
|
||||
{
|
||||
try
|
||||
{
|
||||
LOG.Debug("Advice executing; calling the advised method [" + invocation.Method.Name + "]");
|
||||
object returnValue = invocation.Proceed();
|
||||
LOG.Debug("Advice executed; advised method [" + invocation.Method.Name + "] returned " + returnValue);
|
||||
return returnValue;
|
||||
} finally
|
||||
{
|
||||
numInvoked++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
157
test/Spring/Spring.Data.Tests/Data/Objects/AdoQueryTests.cs
Normal file
157
test/Spring/Spring.Data.Tests/Data/Objects/AdoQueryTests.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using DotNetMock.Dynamic;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Data.Common;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Data.Objects
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains tests for AdoQuery subclasses
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: AdoQueryTests.cs,v 1.3 2007/07/25 08:25:34 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class AdoQueryTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
/*
|
||||
[Test]
|
||||
public void QueryWithoutContextRhino()
|
||||
{
|
||||
IDbProvider provider = (IDbProvider) mocks.DynamicMock(typeof (IDbProvider));
|
||||
|
||||
IDbConnection connection = (IDbConnection) mocks.DynamicMock(typeof (IDbConnection));
|
||||
|
||||
Expect.Call(provider.CreateConnection()).Return(connection);
|
||||
|
||||
IDbCommand command = (IDbCommand) mocks.DynamicMock(typeof (IDbCommand));
|
||||
|
||||
IDataReader reader = (IDataReader) mocks.DynamicMock(typeof (IDataReader));
|
||||
Expect.Call(reader.Read()).Return(true);
|
||||
Expect.Call(reader.GetInt32(0)).Return(1);
|
||||
Expect.Call(reader.Read()).Return(false);
|
||||
|
||||
Expect.Call(command.ExecuteReader()).Return(reader);
|
||||
Expect.Call(provider.CreateCommand()).Return(command);
|
||||
mocks.ReplayAll();
|
||||
|
||||
IntMappingQueryWithNoContext queryWithNoContext = new IntMappingQueryWithNoContext(provider);
|
||||
queryWithNoContext.Compile();
|
||||
IList list = queryWithNoContext.QueryByNamedParam(null, null);
|
||||
Assert.IsTrue(list.Count != 0);
|
||||
foreach (int count in list)
|
||||
{
|
||||
Assert.AreEqual(1, count);
|
||||
}
|
||||
|
||||
mocks.VerifyAll();
|
||||
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
[Test]
|
||||
public void QueryWithoutContext()
|
||||
{
|
||||
|
||||
//Prepare provider
|
||||
IDynamicMock mockProvider = new DynamicMock(typeof(IDbProvider));
|
||||
|
||||
//Prepare connection to return from provider
|
||||
IDynamicMock mockConnection = new DynamicMock(typeof(IDbConnection));
|
||||
IDbConnection connection = (IDbConnection) mockConnection.Object;
|
||||
mockProvider.ExpectAndReturn("CreateConnection", connection);
|
||||
|
||||
//Prepare command
|
||||
IDynamicMock mockCommand = new DynamicMock(typeof(IDbCommand));
|
||||
|
||||
//Prepare reader to return from command
|
||||
IDynamicMock mockReader = new DynamicMock(typeof (IDataReader));
|
||||
mockReader.ExpectAndReturn("Read", true);
|
||||
mockReader.ExpectAndReturn("GetInt32", 1, 0);
|
||||
mockReader.ExpectAndReturn("Read", false);
|
||||
IDataReader reader = (IDataReader) mockReader.Object;
|
||||
mockCommand.ExpectAndReturn("ExecuteReader", reader);
|
||||
|
||||
//Preppare command to return from provider
|
||||
IDbCommand command = (IDbCommand)mockCommand.Object;
|
||||
mockProvider.ExpectAndReturn("CreateCommand", command);
|
||||
|
||||
|
||||
IDbProvider dbProvider = (IDbProvider)mockProvider.Object;
|
||||
|
||||
|
||||
//Test MappingAdoQueryWithContext
|
||||
IntMappingQueryWithNoContext queryWithNoContext = new IntMappingQueryWithNoContext(dbProvider);
|
||||
queryWithNoContext.Compile();
|
||||
//IList list = queryWithNoContext.QueryByNamedParam(null, null);
|
||||
IList list = queryWithNoContext.Query();
|
||||
Assert.IsTrue(list.Count != 0);
|
||||
foreach (int count in list)
|
||||
{
|
||||
Assert.AreEqual(1, count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class IntMappingQueryWithNoContext : MappingAdoQueryWithContext
|
||||
{
|
||||
private static string sql = "select id from custmr";
|
||||
|
||||
public IntMappingQueryWithNoContext(IDbProvider dbProvider)
|
||||
: base(dbProvider, sql)
|
||||
{
|
||||
CommandType = CommandType.Text;
|
||||
}
|
||||
|
||||
|
||||
protected override object MapRow(IDataReader reader, int rowNum, IDictionary inParams,
|
||||
IDictionary callingContext)
|
||||
{
|
||||
Assert.IsNull(inParams);
|
||||
Assert.IsNull(callingContext);
|
||||
return reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
27
test/Spring/Spring.Data.Tests/Data/TestCoord.cs
Normal file
27
test/Spring/Spring.Data.Tests/Data/TestCoord.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
|
||||
using Spring.Objects;
|
||||
|
||||
namespace Spring.Data
|
||||
{
|
||||
public class TestCoord : ITestCoord
|
||||
{
|
||||
private ITestObjectMgr testObjectMgr;
|
||||
|
||||
|
||||
public ITestObjectMgr TestObjectMgr
|
||||
{
|
||||
get { return testObjectMgr; }
|
||||
set { testObjectMgr = value; }
|
||||
}
|
||||
|
||||
#region ITestCoordinator Members
|
||||
|
||||
public void WorkOn(TestObject to1, TestObject to2)
|
||||
{
|
||||
testObjectMgr.SaveTwoTestObjects(to1,to2);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
85
test/Spring/Spring.Data.Tests/Data/TestObjectMgr.cs
Normal file
85
test/Spring/Spring.Data.Tests/Data/TestObjectMgr.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2005 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using Common.Logging;
|
||||
using Spring.Objects;
|
||||
using Spring.Transaction;
|
||||
using Spring.Transaction.Interceptor;
|
||||
using Spring.Transaction.Support;
|
||||
using IsolationLevel=System.Data.IsolationLevel;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Group together multiple ITestObjectDao operations.
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack (.NET)</author>
|
||||
/// <version>$Id: TestObjectMgr.cs,v 1.3 2007/10/21 18:32:41 markpollack Exp $</version>
|
||||
public class TestObjectMgr : ITestObjectMgr
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private static readonly ILog LOG = LogManager.GetLogger(typeof(TestObjectMgr));
|
||||
#endregion
|
||||
|
||||
#region Constructor (s)
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TestObjectMgr"/> class.
|
||||
/// </summary>
|
||||
public TestObjectMgr()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region Methods
|
||||
|
||||
[Transaction()]
|
||||
public void SaveTwoTestObjects(TestObject to1, TestObject to2)
|
||||
{
|
||||
LOG.Debug("TransactionActive = " + TransactionSynchronizationManager.ActualTransactionActive);
|
||||
}
|
||||
#if !NET_1_0 && !NET_1_1
|
||||
[Transaction(TransactionPropagation.Required, IsolationLevel.Unspecified, Timeout = 50,
|
||||
RollbackFor = new Type[]{typeof(ArgumentNullException)},
|
||||
ReadOnly = false,
|
||||
EnterpriseServicesInteropOption = System.Transactions.EnterpriseServicesInteropOption.Automatic,
|
||||
NoRollbackFor = new Type[] { typeof(ArithmeticException), typeof(NotSupportedException) })]
|
||||
#else
|
||||
[Transaction(TransactionPropagation.Required, IsolationLevel.Unspecified, Timeout = 50,
|
||||
RollbackFor = new Type[]{typeof(ArgumentNullException)},
|
||||
ReadOnly = false,
|
||||
NoRollbackFor = new Type[] { typeof(ArithmeticException), typeof(NotSupportedException) })]
|
||||
#endif
|
||||
public void DeleteTwoTestObjects(string name1, string name2)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
46
test/Spring/Spring.Data.Tests/DataExceptionTests.cs
Normal file
46
test/Spring/Spring.Data.Tests/DataExceptionTests.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2004 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring
|
||||
{
|
||||
/// <summary>
|
||||
/// Unit tests for all of the exception classes in the Spring.Data library...
|
||||
/// </summary>
|
||||
/// <author>Rick Evans</author>
|
||||
/// <version>$Id: DataExceptionTests.cs,v 1.6 2006/05/18 21:37:53 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public sealed class DataExceptionTests : ExceptionsTest
|
||||
{
|
||||
[TestFixtureSetUp]
|
||||
public void FixtureSetUp ()
|
||||
{
|
||||
AssemblyToCheck = Assembly.GetAssembly (typeof (Spring.Transaction.CannotCreateTransactionException));
|
||||
}
|
||||
}
|
||||
}
|
||||
374
test/Spring/Spring.Data.Tests/Spring.Data.Tests.2003.csproj
Normal file
374
test/Spring/Spring.Data.Tests/Spring.Data.Tests.2003.csproj
Normal file
@@ -0,0 +1,374 @@
|
||||
<VisualStudioProject>
|
||||
<CSHARP
|
||||
ProjectType = "Local"
|
||||
ProductVersion = "7.10.6030"
|
||||
SchemaVersion = "2.0"
|
||||
ProjectGuid = "{C5585365-561C-4EC4-8956-87FFBD9AB1CD}"
|
||||
>
|
||||
<Build>
|
||||
<Settings
|
||||
ApplicationIcon = ""
|
||||
AssemblyKeyContainerName = ""
|
||||
AssemblyName = "Spring.Data.Tests"
|
||||
AssemblyOriginatorKeyFile = ""
|
||||
DefaultClientScript = "JScript"
|
||||
DefaultHTMLPageLayout = "Grid"
|
||||
DefaultTargetSchema = "IE50"
|
||||
DelaySign = "false"
|
||||
OutputType = "Library"
|
||||
PreBuildEvent = ""
|
||||
PostBuildEvent = ""
|
||||
RootNamespace = "Spring"
|
||||
RunPostBuildEvent = "OnBuildSuccess"
|
||||
StartupObject = ""
|
||||
>
|
||||
<Config
|
||||
Name = "Debug-1.1"
|
||||
AllowUnsafeBlocks = "false"
|
||||
BaseAddress = "285212672"
|
||||
CheckForOverflowUnderflow = "false"
|
||||
ConfigurationOverrideFile = ""
|
||||
DefineConstants = "DEBUG;TRACE;NET_1_1"
|
||||
DocumentationFile = ""
|
||||
DebugSymbols = "true"
|
||||
FileAlignment = "4096"
|
||||
IncrementalBuild = "false"
|
||||
NoStdLib = "false"
|
||||
NoWarn = "0618"
|
||||
Optimize = "false"
|
||||
OutputPath = "..\..\..\build\VS.Net.2003\Spring.Data.Tests\Debug-1.1\"
|
||||
RegisterForComInterop = "false"
|
||||
RemoveIntegerChecks = "false"
|
||||
TreatWarningsAsErrors = "false"
|
||||
WarningLevel = "4"
|
||||
/>
|
||||
<Config
|
||||
Name = "Release-1.1"
|
||||
AllowUnsafeBlocks = "false"
|
||||
BaseAddress = "285212672"
|
||||
CheckForOverflowUnderflow = "false"
|
||||
ConfigurationOverrideFile = ""
|
||||
DefineConstants = "TRACE,NET_1_1"
|
||||
DocumentationFile = ""
|
||||
DebugSymbols = "false"
|
||||
FileAlignment = "4096"
|
||||
IncrementalBuild = "false"
|
||||
NoStdLib = "false"
|
||||
NoWarn = ""
|
||||
Optimize = "true"
|
||||
OutputPath = "..\..\..\build\VS.Net.2003\Spring.Data.Tests\Release-1.1\"
|
||||
RegisterForComInterop = "false"
|
||||
RemoveIntegerChecks = "false"
|
||||
TreatWarningsAsErrors = "false"
|
||||
WarningLevel = "4"
|
||||
/>
|
||||
</Settings>
|
||||
<References>
|
||||
<Reference
|
||||
Name = "System"
|
||||
AssemblyName = "System"
|
||||
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "System.Data"
|
||||
AssemblyName = "System.Data"
|
||||
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "System.XML"
|
||||
AssemblyName = "System.Xml"
|
||||
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "System.Drawing"
|
||||
AssemblyName = "System.Drawing"
|
||||
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "System.Windows.Forms"
|
||||
AssemblyName = "System.Windows.Forms"
|
||||
HintPath = "..\..\..\..\..\WINNT\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "DotNetMock"
|
||||
AssemblyName = "DotNetMock"
|
||||
HintPath = "..\..\..\lib\Net\1.1\DotNetMock.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "nunit.framework"
|
||||
AssemblyName = "nunit.framework"
|
||||
HintPath = "..\..\..\lib\Net\1.1\nunit.framework.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Spring.Aop.2003"
|
||||
Project = "{3A3A4E65-45A6-4B20-B460-0BEDC302C02C}"
|
||||
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Spring.Core.2003"
|
||||
Project = "{710961A3-0DF4-49E4-A26E-F5B9C044AC84}"
|
||||
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Spring.Core.Tests.2003"
|
||||
Project = "{44B16BAA-6DF8-447C-9D7F-3AD3D854D904}"
|
||||
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Spring.Data.2003"
|
||||
Project = "{E10A3BED-795F-41CB-A4A8-8C4B342ACDDF}"
|
||||
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Common.Logging"
|
||||
AssemblyName = "Common.Logging"
|
||||
HintPath = "..\..\..\lib\Net\1.1\Common.Logging.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "Rhino.Mocks"
|
||||
AssemblyName = "Rhino.Mocks"
|
||||
HintPath = "..\..\..\lib\Net\1.1\Rhino.Mocks.dll"
|
||||
/>
|
||||
<Reference
|
||||
Name = "System.EnterpriseServices"
|
||||
AssemblyName = "System.EnterpriseServices"
|
||||
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.EnterpriseServices.dll"
|
||||
/>
|
||||
</References>
|
||||
</Build>
|
||||
<Files>
|
||||
<Include>
|
||||
<File
|
||||
RelPath = "AssemblyInfo.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "DataExceptionTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Spring.Data.Tests.build"
|
||||
BuildAction = "None"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Spring.Data.Tests.dll.config"
|
||||
BuildAction = "None"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Dao\IncorrectResultSizeDataAccessExceptionTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Dao\IncorrectUpdateSemanticsDataAccessExceptionTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Dao\UncategorizedDataAccessExceptionTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\AdoPlatformTransactionManagerTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\AutoDeclarativeTxTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\AutoDeclarativeTxTests.xml"
|
||||
BuildAction = "EmbeddedResource"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\ITestCoord.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\ITestObjectMgr.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\LoggingAroundAdvice.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\TestCoord.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\TestObjectMgr.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\Common\AdditonalProviders.xml"
|
||||
BuildAction = "EmbeddedResource"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\Common\DbProviderFactoryTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\Core\ServiceDomainTransactionManagerTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Data\Objects\AdoQueryTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Support\ErrorCodeExceptionTranslatorTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Support\TestDbProvider.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Support\TestSqlException.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\CallCountingTransactionManager.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\CommonTypes.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\HeuristicCompletionExceptionTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\InvalidTimeoutExceptionTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Config\TxNamespaceParserTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Config\TxNamespaceParserTests.xml"
|
||||
BuildAction = "EmbeddedResource"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\AbstractTransactionAspectTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\DefaultTransactionAttributeTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\MatchAlwaysTransactionAttributeSourceTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\MatchAlwaysTransactionAttributeSourceTests.xml"
|
||||
BuildAction = "EmbeddedResource"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\NoRollbackRuleAttributeTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\RollbackRuleAttributeTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\RuleBasedTransactionAttributeTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\TransactionAttributeEditorTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\TransactionAttributeSourceAdvisorTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\TransactionAttributeSourceEditorTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\TransactionAttributeSourceTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Interceptor\TransactionInterceptorTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Support\AbstractPlatformTransactionManagerTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Support\DefaultTransactionDefinitionTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Support\DefaultTransactionStatusTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Support\ResourceHolderSupportTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Support\TransactionSynchronizationAdapterTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Support\TransactionSynchronizationManagerTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
<File
|
||||
RelPath = "Transaction\Support\TransactionTemplateTests.cs"
|
||||
SubType = "Code"
|
||||
BuildAction = "Compile"
|
||||
/>
|
||||
</Include>
|
||||
</Files>
|
||||
</CSHARP>
|
||||
</VisualStudioProject>
|
||||
|
||||
190
test/Spring/Spring.Data.Tests/Spring.Data.Tests.2005.csproj
Normal file
190
test/Spring/Spring.Data.Tests/Spring.Data.Tests.2005.csproj
Normal file
@@ -0,0 +1,190 @@
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectType>Local</ProjectType>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{ACD39D47-1811-40FA-9E7E-5DEA5B9CE6C0}</ProjectGuid>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ApplicationIcon>
|
||||
</ApplicationIcon>
|
||||
<AssemblyKeyContainerName>
|
||||
</AssemblyKeyContainerName>
|
||||
<AssemblyName>Spring.Data.Tests</AssemblyName>
|
||||
<AssemblyOriginatorKeyFile>
|
||||
</AssemblyOriginatorKeyFile>
|
||||
<DefaultClientScript>JScript</DefaultClientScript>
|
||||
<DefaultHTMLPageLayout>Grid</DefaultHTMLPageLayout>
|
||||
<DefaultTargetSchema>IE50</DefaultTargetSchema>
|
||||
<DelaySign>false</DelaySign>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>Spring</RootNamespace>
|
||||
<RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<OutputPath>..\..\..\build\VS.Net.2005\Spring.Data.Tests\Debug\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;DEBUG;NET_2_0</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn>67, 618</NoWarn>
|
||||
<Optimize>false</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>full</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<UseVSHostingProcess>true</UseVSHostingProcess>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<OutputPath>..\..\..\build\VS.Net.2005\Spring.Data.Tests\Release\</OutputPath>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
<BaseAddress>285212672</BaseAddress>
|
||||
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
|
||||
<ConfigurationOverrideFile>
|
||||
</ConfigurationOverrideFile>
|
||||
<DefineConstants>TRACE;NET_2_0</DefineConstants>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<FileAlignment>4096</FileAlignment>
|
||||
<NoStdLib>false</NoStdLib>
|
||||
<NoWarn>618</NoWarn>
|
||||
<Optimize>true</Optimize>
|
||||
<RegisterForComInterop>false</RegisterForComInterop>
|
||||
<RemoveIntegerChecks>false</RemoveIntegerChecks>
|
||||
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DebugType>none</DebugType>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Common.Logging, Version=2.1.0.0, Culture=neutral, PublicKeyToken=65e474d141e25e07, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\Common.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="DotNetMock, Version=0.7.4.0, Culture=neutral, PublicKeyToken=805ea88df19095f6">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\DotNetMock.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nunit.framework, Version=2.2.5.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Rhino.Mocks, Version=2.9.6.40380, Culture=neutral, PublicKeyToken=0b3305902db7183f">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\lib\Net\2.0\Rhino.Mocks.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System">
|
||||
<Name>System</Name>
|
||||
</Reference>
|
||||
<Reference Include="System.configuration" />
|
||||
<Reference Include="System.Data">
|
||||
<Name>System.Data</Name>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.OracleClient" />
|
||||
<Reference Include="System.Drawing">
|
||||
<Name>System.Drawing</Name>
|
||||
</Reference>
|
||||
<Reference Include="System.EnterpriseServices" />
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Xml">
|
||||
<Name>System.XML</Name>
|
||||
</Reference>
|
||||
<ProjectReference Include="..\..\..\src\Spring\Spring.Aop\Spring.Aop.2005.csproj">
|
||||
<Project>{3A3A4E65-45A6-4B20-B460-0BEDC302C02C}</Project>
|
||||
<Name>Spring.Aop.2005</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\src\Spring\Spring.Core\Spring.Core.2005.csproj">
|
||||
<Project>{710961A3-0DF4-49E4-A26E-F5B9C044AC84}</Project>
|
||||
<Name>Spring.Core.2005</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\..\src\Spring\Spring.Data\Spring.Data.2005.csproj">
|
||||
<Project>{AE00E5AB-C39A-436F-86D2-33BFE33E2E40}</Project>
|
||||
<Name>Spring.Data.2005</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Spring.Core.Tests\Spring.Core.Tests.2005.csproj">
|
||||
<Project>{44B16BAA-6DF8-447C-9D7F-3AD3D854D904}</Project>
|
||||
<Name>Spring.Core.Tests.2005</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\CommonAssemblyInfo.cs">
|
||||
<Link>CommonAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Dao\IncorrectResultSizeDataAccessExceptionTests.cs" />
|
||||
<Compile Include="Dao\IncorrectUpdateSemanticsDataAccessExceptionTests.cs" />
|
||||
<Compile Include="Dao\UncategorizedDataAccessExceptionTests.cs" />
|
||||
<Compile Include="DataExceptionTests.cs" />
|
||||
<Compile Include="Data\AdoPlatformTransactionManagerTests.cs" />
|
||||
<Compile Include="Data\AutoDeclarativeTxTests.cs" />
|
||||
<Compile Include="Data\Common\DbProviderFactoryTests.cs" />
|
||||
<Compile Include="Data\LoggingAroundAdvice.cs" />
|
||||
<Compile Include="Data\ITestCoord.cs" />
|
||||
<Compile Include="Data\ITestObjectMgr.cs" />
|
||||
<Compile Include="Data\Objects\AdoQueryTests.cs" />
|
||||
<Compile Include="Data\TestCoord.cs" />
|
||||
<Compile Include="Data\TestObjectMgr.cs" />
|
||||
<Compile Include="Support\ErrorCodeExceptionTranslatorTests.cs" />
|
||||
<Compile Include="Support\TestDbProvider.cs" />
|
||||
<Compile Include="Support\TestSqlException.cs" />
|
||||
<Compile Include="Transaction\CallCountingTransactionManager.cs" />
|
||||
<Compile Include="Transaction\CommonTypes.cs" />
|
||||
<Compile Include="Transaction\Config\TxNamespaceParserTests.cs" />
|
||||
<Compile Include="Transaction\HeuristicCompletionExceptionTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\DefaultTransactionAttributeTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\MatchAlwaysTransactionAttributeSourceTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\NoRollbackRuleAttributeTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\RollbackRuleAttributeTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\RuleBasedTransactionAttributeTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\TransactionAttributeEditorTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\TransactionAttributeSourceAdvisorTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\TransactionAttributeSourceEditorTests.cs" />
|
||||
<Compile Include="Transaction\InvalidTimeoutExceptionTests.cs" />
|
||||
<Compile Include="Transaction\Support\AbstractPlatformTransactionManagerTests.cs" />
|
||||
<Compile Include="Transaction\Support\DefaultTransactionDefinitionTests.cs" />
|
||||
<Compile Include="Transaction\Support\DefaultTransactionStatusTests.cs" />
|
||||
<Compile Include="Transaction\Support\ResourceHolderSupportTests.cs" />
|
||||
<Compile Include="Transaction\Support\TransactionSynchronizationAdapterTests.cs" />
|
||||
<Compile Include="Transaction\Support\TransactionSynchronizationManagerTests.cs" />
|
||||
<Compile Include="Transaction\Support\TransactionTemplateTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Data\AutoDeclarativeTxTests.xml" />
|
||||
<EmbeddedResource Include="Data\Common\AdditionalProviders.xml" />
|
||||
<Content Include="Spring.Data.Tests.dll.config" />
|
||||
<EmbeddedResource Include="Transaction\Interceptor\MatchAlwaysTransactionAttributeSourceTests.xml" />
|
||||
<EmbeddedResource Include="Transaction\Config\TxNamespaceParserTests.xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Data\Common\DbParametersTests.cs" />
|
||||
<Compile Include="Data\Common\UserCredentialsDbProviderTests.cs" />
|
||||
<Compile Include="Data\Core\ServiceDomainTransactionManagerTests.cs" />
|
||||
<Compile Include="Data\Core\TxScopeTransactionManagerIntegrationTests.cs" />
|
||||
<Compile Include="Data\Core\TxScopeTransactionManagerTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\AbstractTransactionAspectTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\TransactionAttributeSourceTests.cs" />
|
||||
<Compile Include="Transaction\Interceptor\TransactionInterceptorTests.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PreBuildEvent>
|
||||
</PreBuildEvent>
|
||||
<PostBuildEvent>echo "Copying .xml files for tests"
|
||||
xcopy "$(ProjectDir)Data" ..\..\..\..\build\VS.Net.2005\Spring.Data.Tests\$(ConfigurationName)\ /y /s /q /d
|
||||
xcopy "$(ProjectDir)$(TargetFileName).config" ..\..\..\..\build\VS.Net.2005\Spring.Data.Tests\$(ConfigurationName)\ /y /s /q</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
44
test/Spring/Spring.Data.Tests/Spring.Data.Tests.build
Normal file
44
test/Spring/Spring.Data.Tests/Spring.Data.Tests.build
Normal file
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" ?>
|
||||
<project name="Spring.Data.Tests" default="test" xmlns="http://nant.sf.net/schemas/nant.xsd">
|
||||
<!--
|
||||
Required properties:
|
||||
* current.bin.dir - (path) root level to build to
|
||||
* current.build.debug - (true|false) debug build?
|
||||
* current.build.defines.csc - framework-specific build defines for C# compiler
|
||||
-->
|
||||
<target name="build">
|
||||
<!-- build Spring.Data.Tests -->
|
||||
<csc target="library" define="${current.build.defines.csc}"
|
||||
warnaserror="true"
|
||||
debug="${current.build.debug}"
|
||||
output="${current.bin.dir}/${project::get-name()}.dll"
|
||||
doc="${current.bin.dir}/${project::get-name()}.xml">
|
||||
<nowarn>
|
||||
<warning number="${nowarn.numbers.test}" />
|
||||
</nowarn>
|
||||
<sources failonempty="true">
|
||||
<include name="**/*.cs" />
|
||||
<include name="../CommonAssemblyInfo.cs" />
|
||||
</sources>
|
||||
<resources prefix="Spring" dynamicprefix="true" failonempty="true">
|
||||
<include name="**/*.xml" />
|
||||
</resources>
|
||||
<references basedir="${current.bin.dir}">
|
||||
<include name="*.dll" />
|
||||
<exclude name="${project::get-name()}.dll" />
|
||||
<exclude name="CloverRuntime.dll" />
|
||||
</references>
|
||||
</csc>
|
||||
|
||||
<copy file="${project::get-base-directory()}/${project::get-name()}.dll.config"
|
||||
tofile="${current.bin.dir}/${project::get-name()}.dll.config"/>
|
||||
</target>
|
||||
<target name="test" depends="build">
|
||||
<nunit2outproc>
|
||||
<formatter type="Plain" />
|
||||
<formatter type="Xml" usefile="true" extension=".xml"
|
||||
outputdir="${current.bin.dir}/results" />
|
||||
<test assemblyname="${current.bin.dir}/${project::get-name()}.dll" />
|
||||
</nunit2outproc>
|
||||
</target>
|
||||
</project>
|
||||
80
test/Spring/Spring.Data.Tests/Spring.Data.Tests.dll.config
Normal file
80
test/Spring/Spring.Data.Tests/Spring.Data.Tests.dll.config
Normal file
@@ -0,0 +1,80 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!--
|
||||
Copyright 2002-2005 the original author or authors.
|
||||
|
||||
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.
|
||||
-->
|
||||
<configuration>
|
||||
|
||||
<configSections>
|
||||
|
||||
<sectionGroup name="common">
|
||||
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
|
||||
</sectionGroup>
|
||||
|
||||
<sectionGroup name='spring'>
|
||||
<section name='context' type='Spring.Context.Support.ContextHandler, Spring.Core'/>
|
||||
<section name='objects' type='Spring.Context.Support.DefaultSectionHandler, Spring.Core' />
|
||||
</sectionGroup>
|
||||
|
||||
<!--
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
|
||||
-->
|
||||
<section name="DatabaseConfiguration" type="System.Configuration.NameValueSectionHandler"/>
|
||||
|
||||
</configSections>
|
||||
|
||||
<common>
|
||||
<logging>
|
||||
<factoryAdapter type="Common.Logging.Simple.NoOpLoggerFactoryAdapter, Common.Logging"/>
|
||||
</logging>
|
||||
</common>
|
||||
|
||||
<spring>
|
||||
|
||||
<context>
|
||||
<resource uri="config://spring/objects"/>
|
||||
</context>
|
||||
|
||||
<!-- parent context's objects -->
|
||||
<objects xmlns='http://www.springframework.net'>
|
||||
|
||||
</objects>
|
||||
|
||||
</spring>
|
||||
|
||||
|
||||
<DatabaseConfiguration>
|
||||
<add key="connection.string" value="dsn=MyDSN;uid=sa;pwd=myPassword;"/>
|
||||
</DatabaseConfiguration>
|
||||
|
||||
<!--
|
||||
<log4net>
|
||||
<appender name="NullAppender" type="Spring.Objects.Factory.Xml.NullAppender, Spring.Core.Tests"/>
|
||||
<root>
|
||||
<level value="ALL" />
|
||||
<appender-ref ref="NullAppender" />
|
||||
</root>
|
||||
</log4net>
|
||||
-->
|
||||
<!--
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="Neutral" />
|
||||
<bindingRedirect oldVersion="2.0.6.0" newVersion="2.4.1.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
-->
|
||||
</configuration>
|
||||
@@ -0,0 +1,111 @@
|
||||
#if !NET_1_0
|
||||
#region Licence
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2005 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Spring.Dao;
|
||||
using Spring.Data;
|
||||
using Spring.Data.Common;
|
||||
using Spring.Data.Support;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Support
|
||||
{
|
||||
/// <summary>
|
||||
/// Test the database exception translation.
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack (.NET)</author>
|
||||
/// <version>$Id: ErrorCodeExceptionTranslatorTests.cs,v 1.8 2007/12/06 20:14:39 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class ErrorCodeExceptionTranslatorTests
|
||||
{
|
||||
#region Fields
|
||||
private static ErrorCodes ERROR_CODES = new ErrorCodes();
|
||||
|
||||
private IDbProvider dbProvider = new TestDbProvider();
|
||||
#endregion
|
||||
|
||||
|
||||
#region Constructor (s)
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ErrorCodeExceptionTranslatorTests"/> class.
|
||||
/// </summary>
|
||||
public ErrorCodeExceptionTranslatorTests()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
ERROR_CODES.BadSqlGrammarCodes = (new String[] { "1", "2" });
|
||||
ERROR_CODES.InvalidResultSetAccessCodes = (new String[] { "3", "4" });
|
||||
ERROR_CODES.DataAccessResourceFailureCodes = (new String[] { "5" });
|
||||
ERROR_CODES.DataIntegrityViolationCodes = (new String[] { "544", "2627", "8114", "8115" });
|
||||
ERROR_CODES.CannotAcquireLockCodes = (new String[] { "7" });
|
||||
ERROR_CODES.DeadlockLoserCodes = (new String[] { "8" });
|
||||
ERROR_CODES.CannotSerializeTransactionCodes = (new String[] { "9" });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ErrorCodeTransation()
|
||||
{
|
||||
IAdoExceptionTranslator exceptionTranslator = new ErrorCodeExceptionTranslator(dbProvider, ERROR_CODES);
|
||||
TestSqlException badSqlEx = new TestSqlException("", "1");
|
||||
|
||||
BadSqlGrammarException bsgex = (BadSqlGrammarException)exceptionTranslator.Translate("task","SQL", badSqlEx);
|
||||
Assert.AreEqual("SQL", bsgex.Sql);
|
||||
Assert.AreEqual(badSqlEx, bsgex.InnerException);
|
||||
|
||||
TestSqlException invResEx = new TestSqlException("", "4");
|
||||
InvalidResultSetAccessException irsex = (InvalidResultSetAccessException) exceptionTranslator.Translate("task", "SQL", invResEx);
|
||||
Assert.AreEqual("SQL", irsex.Sql);
|
||||
Assert.AreEqual(invResEx, irsex.InnerException);
|
||||
|
||||
CheckTranslation(exceptionTranslator, "5", typeof(DataAccessResourceFailureException));
|
||||
CheckTranslation(exceptionTranslator, "544", typeof(DataIntegrityViolationException));
|
||||
CheckTranslation(exceptionTranslator, "7", typeof(CannotAcquireLockException));
|
||||
CheckTranslation(exceptionTranslator, "8", typeof(DeadlockLoserDataAccessException));
|
||||
CheckTranslation(exceptionTranslator, "9", typeof(CannotSerializeTransactionException));
|
||||
}
|
||||
|
||||
private void CheckTranslation(IAdoExceptionTranslator translator, string errorCode, Type exType)
|
||||
{
|
||||
TestSqlException sex = new TestSqlException("", errorCode);
|
||||
DataAccessException ex = translator.Translate("", "", sex);
|
||||
Assert.IsTrue(exType.IsAssignableFrom(ex.GetType()));
|
||||
Assert.IsTrue(ex.InnerException == sex);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
167
test/Spring/Spring.Data.Tests/Support/TestDbProvider.cs
Normal file
167
test/Spring/Spring.Data.Tests/Support/TestDbProvider.cs
Normal file
@@ -0,0 +1,167 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2006 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using Spring.Data.Common;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Support
|
||||
{
|
||||
/// <summary>
|
||||
/// A fake provider class used to test exception translation functionality
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack (.NET)</author>
|
||||
/// <version>$Id: TestDbProvider.cs,v 1.11 2007/12/06 05:48:32 markpollack Exp $</version>
|
||||
public class TestDbProvider : IDbProvider
|
||||
{
|
||||
private string connectionString;
|
||||
private IDbConnection connection;
|
||||
|
||||
protected IDbMetadata dbMetadata;
|
||||
|
||||
public TestDbProvider()
|
||||
{
|
||||
IDbProvider provider = DbProviderFactory.GetDbProvider("SqlServer-1.1");
|
||||
dbMetadata = provider.DbMetadata;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Return metadata information about the database.
|
||||
/// </summary>
|
||||
public IDbMetadata DbMetadata
|
||||
{
|
||||
get
|
||||
{
|
||||
return dbMetadata;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Connection string used to create connections.
|
||||
/// </summary>
|
||||
public string ConnectionString
|
||||
{
|
||||
set { connectionString = value; }
|
||||
get { return connectionString; }
|
||||
}
|
||||
public IDbCommand CreateCommand()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public IDbConnection CreateConnection()
|
||||
{
|
||||
return connection;
|
||||
}
|
||||
|
||||
public IDbDataParameter CreateParameter()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
public IDbDataAdapter CreateDataAdapter()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public object CreateCommandBuilder()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public string ExtractError(Exception e)
|
||||
{
|
||||
TestSqlException testSqlException = (TestSqlException)e;
|
||||
return testSqlException.ErrorNumber;
|
||||
}
|
||||
|
||||
public bool IsDataAccessException(Exception e)
|
||||
{
|
||||
#if NET_2_0
|
||||
if (e is System.Data.Common.DbException)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#else
|
||||
return IsDataAccessExceptionBCL11(e);
|
||||
#endif
|
||||
}
|
||||
|
||||
public bool IsDataAccessExceptionBCL11(Exception e)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public string CreateParameterName(string name)
|
||||
{
|
||||
if (dbMetadata.BindByName)
|
||||
{
|
||||
if (DbMetadata.UseParameterPrefixInSql)
|
||||
{
|
||||
return DbMetadata.ParameterNamePrefix + name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return DbMetadata.ParameterNamePrefix;
|
||||
}
|
||||
}
|
||||
|
||||
public string CreateParameterNameForCollection(string name)
|
||||
{
|
||||
if (dbMetadata.BindByName)
|
||||
{
|
||||
if (DbMetadata.UseParameterNamePrefixInParameterCollection)
|
||||
{
|
||||
return DbMetadata.ParameterNamePrefix + name;
|
||||
}
|
||||
else
|
||||
{
|
||||
return name;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return DbMetadata.ParameterNamePrefix;
|
||||
}
|
||||
}
|
||||
|
||||
#region Stub method to set behavior
|
||||
|
||||
public IDbConnection ConnectionToCreate
|
||||
{
|
||||
set { connection = value;}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
84
test/Spring/Spring.Data.Tests/Support/TestSqlException.cs
Normal file
84
test/Spring/Spring.Data.Tests/Support/TestSqlException.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2006 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Support
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple exception class to test exception translation functionality
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack (.NET)</author>
|
||||
/// <version>$Id: TestSqlException.cs,v 1.2 2006/06/26 18:57:31 markpollack Exp $</version>
|
||||
[Serializable]
|
||||
public class TestSqlException : Exception
|
||||
{
|
||||
|
||||
|
||||
private string errorNumber;
|
||||
|
||||
public TestSqlException() {}
|
||||
|
||||
|
||||
public TestSqlException( string message ) : base( message ) {}
|
||||
|
||||
public TestSqlException(string message, string errorNumber) :base (message)
|
||||
{
|
||||
ErrorNumber = errorNumber;
|
||||
}
|
||||
|
||||
public TestSqlException( string message, Exception rootCause)
|
||||
: base( message , rootCause ) {}
|
||||
|
||||
protected TestSqlException(
|
||||
SerializationInfo info, StreamingContext context ) : base( info, context )
|
||||
{
|
||||
errorNumber = info.GetString( "errorNumber" );
|
||||
}
|
||||
|
||||
public string ErrorNumber
|
||||
{
|
||||
get { return errorNumber; }
|
||||
set { errorNumber = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// Override of <see cref="System.Exception.GetObjectData(SerializationInfo, StreamingContext)"/>
|
||||
/// to allow for private serialization.
|
||||
/// </summary>
|
||||
/// <param name="info">
|
||||
/// The <see cref="System.Runtime.Serialization.SerializationInfo"/>
|
||||
/// that holds the serialized object data about the exception.
|
||||
/// </param>
|
||||
/// <param name="context">
|
||||
/// The <see cref="System.Runtime.Serialization.StreamingContext"/>
|
||||
/// that contains contextual information about the source or destination.
|
||||
/// </param>
|
||||
public override void GetObjectData(SerializationInfo info, StreamingContext context)
|
||||
{
|
||||
info.AddValue( "errorNumber", errorNumber );
|
||||
base.GetObjectData( info, context );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
using Spring.Transaction.Support;
|
||||
|
||||
namespace Spring.Transaction
|
||||
{
|
||||
/// <summary>
|
||||
/// This is a test implementation to count the number of times PlatformTransactionManager methods
|
||||
/// have been called.
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: CallCountingTransactionManager.cs,v 1.1 2007/05/26 00:43:07 markpollack Exp $</version>
|
||||
public class CallCountingTransactionManager : AbstractPlatformTransactionManager
|
||||
{
|
||||
|
||||
public int begun;
|
||||
public int commits;
|
||||
public int rollbacks;
|
||||
public int inflight;
|
||||
|
||||
|
||||
protected override object DoGetTransaction()
|
||||
{
|
||||
return new object();
|
||||
}
|
||||
|
||||
protected override void DoBegin(object transaction, ITransactionDefinition definition)
|
||||
{
|
||||
++begun;
|
||||
++inflight;
|
||||
}
|
||||
|
||||
protected override void DoCommit(DefaultTransactionStatus status)
|
||||
{
|
||||
++commits;
|
||||
--inflight;
|
||||
}
|
||||
|
||||
protected override void DoRollback(DefaultTransactionStatus status)
|
||||
{
|
||||
++rollbacks;
|
||||
--inflight;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
begun = commits = rollbacks = inflight = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
370
test/Spring/Spring.Data.Tests/Transaction/CommonTypes.cs
Normal file
370
test/Spring/Spring.Data.Tests/Transaction/CommonTypes.cs
Normal file
@@ -0,0 +1,370 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using DotNetMock;
|
||||
using Spring.Transaction.Support;
|
||||
|
||||
namespace Spring.Transaction
|
||||
{
|
||||
public class MyMockTxnObject : MockObject, ISmartTransactionObject
|
||||
{
|
||||
private ExpectationCounter _isRollbackOnlyCalls = new ExpectationCounter( "IsRollbackOnlyCalls" );
|
||||
private bool _isRollbackOnly = false;
|
||||
|
||||
public MyMockTxnObject() : this( "MyMockTxnObject" ) {}
|
||||
public MyMockTxnObject( string name ) : base( name ) {}
|
||||
|
||||
|
||||
|
||||
public void SetExpectedRollbackOnlyCalls( int calls )
|
||||
{
|
||||
_isRollbackOnlyCalls.Expected = calls;
|
||||
}
|
||||
public void SetExpectedIsRollBackOnlyValue( bool isRollbackOnly )
|
||||
{
|
||||
_isRollbackOnly = isRollbackOnly;
|
||||
}
|
||||
#region ISmartTransactionObject Members
|
||||
|
||||
public bool RollbackOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
_isRollbackOnlyCalls.Inc();
|
||||
return _isRollbackOnly;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
public class MyMockTxnObjectSavepointMgr : MockObject, ISavepointManager, ISmartTransactionObject
|
||||
{
|
||||
private string _savepoint;
|
||||
private ExpectationString _expectedSavepoint = new ExpectationString("Savepoint");
|
||||
|
||||
public void SetSavepointToReturn( string savepoint )
|
||||
{
|
||||
_savepoint = savepoint;
|
||||
}
|
||||
public void SetExpectedSavepoint( string savepoint )
|
||||
{
|
||||
_expectedSavepoint.Expected = savepoint;
|
||||
}
|
||||
#region ISmartTransactionObject Members
|
||||
|
||||
public bool RollbackOnly
|
||||
{
|
||||
get
|
||||
{ // TODO: Add MyMockTxnObjectSavepointMgr.IsRollbackOnly implementation
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ISavepointManager Members
|
||||
public void ReleaseSavepoint(string savepoint)
|
||||
{
|
||||
_expectedSavepoint.Actual = savepoint;
|
||||
}
|
||||
|
||||
public void CreateSavepoint( string savepoint )
|
||||
{
|
||||
_expectedSavepoint.Actual = savepoint;
|
||||
}
|
||||
|
||||
public void RollbackToSavepoint(string savepoint)
|
||||
{
|
||||
_expectedSavepoint.Actual = savepoint;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class MockTxnPlatformMgr : MockObject, IPlatformTransactionManager
|
||||
{
|
||||
private ExpectationCounter _commitCalls = new ExpectationCounter("CommitCalls");
|
||||
private ExpectationCounter _getTransactionCalls = new ExpectationCounter("GetTxnCalls");
|
||||
private ExpectationCounter _rollbackCalls = new ExpectationCounter("RollbackCalls");
|
||||
private bool _throwRollbackException = false;
|
||||
|
||||
#region IPlatformTransactionManager Members
|
||||
public void SetExpectedCommitCallCount( int count )
|
||||
{
|
||||
_commitCalls.Expected = count;
|
||||
}
|
||||
public void SetExpectedRollbackCallCount( int count )
|
||||
{
|
||||
_rollbackCalls.Expected = count;
|
||||
}
|
||||
public void SetExpectedGetTxnCallCount( int count )
|
||||
{
|
||||
_getTransactionCalls.Expected = count;
|
||||
}
|
||||
public bool ThrowRollbackException
|
||||
{
|
||||
set { _throwRollbackException = value; }
|
||||
}
|
||||
public void Rollback(ITransactionStatus transactionStatus)
|
||||
{
|
||||
_rollbackCalls.Inc();
|
||||
if ( _throwRollbackException )
|
||||
{
|
||||
throw new Exception("Rollback");
|
||||
}
|
||||
}
|
||||
|
||||
public void Commit(ITransactionStatus transactionStatus)
|
||||
{
|
||||
_commitCalls.Inc();
|
||||
}
|
||||
|
||||
public ITransactionStatus GetTransaction(ITransactionDefinition definition)
|
||||
{
|
||||
_getTransactionCalls.Inc();
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
public class MockTxnSync : MockObject, ITransactionSynchronization
|
||||
{
|
||||
#region ITransactionSynchronization Members
|
||||
|
||||
public void AfterCompletion(Spring.Transaction.Support.TransactionSynchronizationStatus status)
|
||||
{
|
||||
// TODO: Add MockTxnSync.AfterCompletion implementation
|
||||
}
|
||||
|
||||
public void BeforeCommit(bool readOnly)
|
||||
{
|
||||
// TODO: Add MockTxnSync.BeforeCommit implementation
|
||||
}
|
||||
|
||||
public void AfterCommit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Resume()
|
||||
{
|
||||
// TODO: Add MockTxnSync.Resume implementation
|
||||
}
|
||||
|
||||
public void BeforeCompletion()
|
||||
{
|
||||
// TODO: Add MockTxnSync.BeforeCompletion implementation
|
||||
}
|
||||
|
||||
public void Suspend()
|
||||
{
|
||||
// TODO: Add MockTxnSync.Suspend implementation
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class MockTxnDefinition : MockObject, ITransactionDefinition
|
||||
{
|
||||
private int _transactionTimeout = DefaultTransactionDefinition.TIMEOUT_DEFAULT;
|
||||
private TransactionPropagation _transactionPropagation = TransactionPropagation.NotSupported;
|
||||
private bool _readOnly = false;
|
||||
private string _name = null;
|
||||
#if NET_2_0
|
||||
private System.Transactions.EnterpriseServicesInteropOption _esInteropOption;
|
||||
|
||||
#endif
|
||||
#region ITransactionDefinition Members
|
||||
|
||||
public bool ReadOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return _readOnly;
|
||||
}
|
||||
set
|
||||
{
|
||||
_readOnly = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int TransactionTimeout
|
||||
{
|
||||
get
|
||||
{
|
||||
return _transactionTimeout;
|
||||
}
|
||||
set
|
||||
{
|
||||
_transactionTimeout = value;
|
||||
}
|
||||
}
|
||||
|
||||
public IsolationLevel TransactionIsolationLevel
|
||||
{
|
||||
get
|
||||
{
|
||||
return IsolationLevel.Unspecified;
|
||||
}
|
||||
}
|
||||
|
||||
public TransactionPropagation PropagationBehavior
|
||||
{
|
||||
get
|
||||
{
|
||||
return _transactionPropagation;
|
||||
}
|
||||
set
|
||||
{
|
||||
_transactionPropagation = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if NET_2_0
|
||||
public System.Transactions.EnterpriseServicesInteropOption EnterpriseServicesInteropOption
|
||||
{
|
||||
get { return _esInteropOption; }
|
||||
set { _esInteropOption = value; }
|
||||
}
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
public class MockTxnPlatformMgrAbstract : AbstractPlatformTransactionManager, IMockObject
|
||||
{
|
||||
private object _transaction;
|
||||
private bool _isVerified;
|
||||
private string _mockName;
|
||||
private bool _isExistingTransaction;
|
||||
|
||||
private ExpectationCounter _doBeginCalls = new ExpectationCounter("DoBegin Calls");
|
||||
private ExpectationCounter _doGetTxnCalls = new ExpectationCounter("DoGetTransaction Calls");
|
||||
private ExpectationCounter _isExistingTxnCalls = new ExpectationCounter("IsExistingTransaction Calls");
|
||||
|
||||
|
||||
private bool _useSavepointForNestedTransaction;
|
||||
|
||||
public void SetExpectedCalls( string method, int calls )
|
||||
{
|
||||
switch ( method )
|
||||
{
|
||||
case "DoBegin":
|
||||
_doBeginCalls.Expected = calls;
|
||||
break;
|
||||
case "IsExistingTransaction":
|
||||
_isExistingTxnCalls.Expected = calls;
|
||||
break;
|
||||
case "DoGetTransaction":
|
||||
_doGetTxnCalls.Expected = calls;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void SetTransaction( object transaction )
|
||||
{
|
||||
_transaction = transaction;
|
||||
_isExistingTransaction = true;
|
||||
}
|
||||
public object Transaction
|
||||
{
|
||||
get { return _transaction; }
|
||||
}
|
||||
public bool Savepoints
|
||||
{
|
||||
set { _useSavepointForNestedTransaction = value; }
|
||||
}
|
||||
#region IMockObject Members
|
||||
|
||||
public void NotImplemented(string methodName)
|
||||
{
|
||||
// TODO: Add MockTxnPlatformMgrAbstract.NotImplemented implementation
|
||||
}
|
||||
|
||||
public string MockName
|
||||
{
|
||||
get { return _mockName; }
|
||||
set { _mockName = value;}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IVerifiable Members
|
||||
|
||||
public void Verify()
|
||||
{
|
||||
Verifier.Verify( this );
|
||||
_isVerified = true;
|
||||
}
|
||||
|
||||
public bool IsVerified
|
||||
{
|
||||
get { return _isVerified; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region AbstractPlatformTransactionManager Impls
|
||||
protected override void DoResume(object transaction, object suspendedResources)
|
||||
{
|
||||
|
||||
}
|
||||
protected override void DoCommit(DefaultTransactionStatus status)
|
||||
{
|
||||
|
||||
}
|
||||
protected override object DoGetTransaction()
|
||||
{
|
||||
_doGetTxnCalls.Inc();
|
||||
if ( null == _transaction )
|
||||
{
|
||||
return new object();
|
||||
}
|
||||
else
|
||||
{
|
||||
return _transaction;
|
||||
}
|
||||
}
|
||||
protected override object DoSuspend(object transaction)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
protected override void DoBegin(object transaction, ITransactionDefinition definition)
|
||||
{
|
||||
_doBeginCalls.Inc();
|
||||
}
|
||||
protected override void DoSetRollbackOnly(DefaultTransactionStatus status)
|
||||
{
|
||||
|
||||
}
|
||||
protected override void DoRollback(DefaultTransactionStatus status)
|
||||
{
|
||||
|
||||
}
|
||||
protected override bool IsExistingTransaction(object transaction)
|
||||
{
|
||||
_isExistingTxnCalls.Inc();
|
||||
return _isExistingTransaction;
|
||||
}
|
||||
|
||||
protected override bool UseSavepointForNestedTransaction()
|
||||
{
|
||||
return _useSavepointForNestedTransaction;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2007 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Spring.Aop.Config;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Objects;
|
||||
using Spring.Objects.Factory.Xml;
|
||||
using Spring.Transaction.Interceptor;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Transaction.Config
|
||||
{
|
||||
[TestFixture]
|
||||
public class TxNamespaceParserTests
|
||||
{
|
||||
private IApplicationContext ctx;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
NamespaceParserRegistry.RegisterParser(typeof(TxNamespaceParser));
|
||||
NamespaceParserRegistry.RegisterParser(typeof(AopNamespaceParser));
|
||||
ctx = new XmlApplicationContext("assembly://Spring.Data.Tests/Spring.Transaction.Config/TxNamespaceParserTests.xml");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Registered()
|
||||
{
|
||||
Assert.IsNotNull(NamespaceParserRegistry.GetParser("http://www.springframework.net/tx"));
|
||||
Assert.IsTrue(ctx.ContainsObjectDefinition(AopNamespaceUtils.AUTO_PROXY_CREATOR_OBJECT_NAME));
|
||||
Assert.IsTrue(ctx.ContainsObjectDefinition("Spring.Transaction.Interceptor.TransactionAttributeSourceAdvisor"));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void InvokeTransactional()
|
||||
{
|
||||
ITestObject testObject = TestObject;
|
||||
CallCountingTransactionManager ptm = ctx["transactionManager"] as CallCountingTransactionManager;
|
||||
Assert.IsNotNull(ptm);
|
||||
|
||||
// try with transactional
|
||||
Assert.AreEqual(0, ptm.begun,"Should not have started any transactions");
|
||||
testObject.GetDescription();
|
||||
Assert.AreEqual(1, ptm.begun, "Should have 1 started transaction");
|
||||
Assert.AreEqual(1, ptm.commits, "Should have 1 committed transaction");
|
||||
|
||||
// try with non-transaction
|
||||
int i = testObject.Age;
|
||||
Assert.AreEqual(1, ptm.begun, "Should not have started another transaction");
|
||||
|
||||
// try with exceptional
|
||||
try
|
||||
{
|
||||
testObject.Exceptional(new ArgumentNullException());
|
||||
Assert.Fail("Should not get here");
|
||||
} catch (Exception)
|
||||
{
|
||||
Assert.AreEqual(2, ptm.begun, "Should have another started transaction");
|
||||
Assert.AreEqual(1, ptm.rollbacks, "Should have 1 rolled back transaction");
|
||||
}
|
||||
}
|
||||
|
||||
private ITestObject TestObject
|
||||
{
|
||||
get
|
||||
{
|
||||
return ctx["testObject"] as
|
||||
ITestObject;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RollbackRules()
|
||||
{
|
||||
TransactionInterceptor txInterceptor = ctx.GetObject("txRollbackAdvice") as TransactionInterceptor;
|
||||
Assert.IsNotNull(txInterceptor);
|
||||
|
||||
MethodInfo getDescriptionMethod = typeof(ITestObject).GetMethod("GetDescription");
|
||||
MethodInfo exceptionalMethod = typeof (ITestObject).GetMethod("Exceptional");
|
||||
ITransactionAttributeSource txAttrSource = txInterceptor.TransactionAttributeSource;
|
||||
ITransactionAttribute txAttr = txAttrSource.ReturnTransactionAttribute(getDescriptionMethod, typeof (ITestObject));
|
||||
Assert.IsTrue(txAttr.RollbackOn(new System.ApplicationException()));
|
||||
|
||||
txAttr = txAttrSource.ReturnTransactionAttribute(exceptionalMethod, typeof (ITestObject));
|
||||
Assert.IsFalse(txAttr.RollbackOn(new System.ArithmeticException()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:tx="http://www.springframework.net/tx"
|
||||
xmlns:aop="http://www.springframework.net/aop"
|
||||
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/schema/objects/spring-objects.xsd
|
||||
http://www.springframework.net/tx http://www.springframework.net/schema/tx/spring-tx-1.1.xsd">
|
||||
|
||||
<object id="testObjectOperation" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop">
|
||||
<property name="pattern" value="Spring.Objects.TestObject.*"/>
|
||||
</object>
|
||||
|
||||
<tx:advice id="txAdvice">
|
||||
<tx:attributes>
|
||||
<tx:method name="Get*" read-only="true"/>
|
||||
<tx:method name="Exceptional"/>
|
||||
</tx:attributes>
|
||||
</tx:advice>
|
||||
|
||||
<!-- this advice is not applied, just testing advice definition itself. -->
|
||||
<tx:advice id="txRollbackAdvice">
|
||||
<tx:attributes>
|
||||
<tx:method name="Get*" rollback-for="System.ApplicationException"/>
|
||||
<tx:method name="Exceptional" no-rollback-for="System.ArithmeticException"/>
|
||||
</tx:attributes>
|
||||
</tx:advice>
|
||||
|
||||
<!-- this will not match any object in the context, just used to check internal registration -->
|
||||
<tx:attribute-driven/>
|
||||
|
||||
|
||||
<aop:config>
|
||||
|
||||
<aop:advisor pointcut-ref="testObjectOperation" advice-ref="txAdvice"/>
|
||||
|
||||
</aop:config>
|
||||
|
||||
|
||||
<object name="transactionManager" type="Spring.Transaction.CallCountingTransactionManager, Spring.Data.Tests"/>
|
||||
|
||||
<object name="testObject" type="Spring.Objects.TestObject, Spring.Core.Tests"/>
|
||||
|
||||
</objects>
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using Spring.Transaction;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction
|
||||
{
|
||||
[TestFixture]
|
||||
public class HeuristicCompletionExceptionTests
|
||||
{
|
||||
[Test]
|
||||
public void TransactionOutcomeStateGetter()
|
||||
{
|
||||
HeuristicCompletionException ex = new HeuristicCompletionException( TransactionOutcomeState.Unknown, new Exception() );
|
||||
Assert.IsTrue( TransactionOutcomeState.Unknown == ex.OutcomeState );
|
||||
}
|
||||
[Test]
|
||||
public void TransactionOutcomeStateGetterCommittted()
|
||||
{
|
||||
HeuristicCompletionException ex = new HeuristicCompletionException( TransactionOutcomeState.Committed, new Exception() );
|
||||
Assert.IsTrue( TransactionOutcomeState.Committed == ex.OutcomeState );
|
||||
}
|
||||
[Test]
|
||||
public void TransactionOutcomeStateGetterMixed()
|
||||
{
|
||||
HeuristicCompletionException ex = new HeuristicCompletionException( TransactionOutcomeState.Mixed, new Exception() );
|
||||
Assert.IsTrue( TransactionOutcomeState.Mixed == ex.OutcomeState );
|
||||
}
|
||||
[Test]
|
||||
public void TransactionOutcomeStateGetterRolledback()
|
||||
{
|
||||
HeuristicCompletionException ex = new HeuristicCompletionException( TransactionOutcomeState.Rolledback, new Exception() );
|
||||
Assert.IsTrue( TransactionOutcomeState.Rolledback == ex.OutcomeState );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
using Spring.Data;
|
||||
using Spring.Objects;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
/// <summary>
|
||||
/// Mock object based tests for transaction aspects.
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: AbstractTransactionAspectTests.cs,v 1.5 2007/10/21 18:16:58 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public abstract class AbstractTransactionAspectTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CopyAttributes()
|
||||
{
|
||||
|
||||
IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction();
|
||||
AttributesTransactionAttributeSource tas = new AttributesTransactionAttributeSource();
|
||||
TestObjectMgr to = new TestObjectMgr();
|
||||
ITestObjectMgr ito = (ITestObjectMgr)Advised(to, ptm, tas);
|
||||
|
||||
ito.DeleteTwoTestObjects("foo", "bar");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CannotCommitTransaction()
|
||||
{
|
||||
ITransactionAttribute txatt = new DefaultTransactionAttribute();
|
||||
MethodInfo m = typeof (ITestObject).GetMethod("GetDescription");
|
||||
MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();
|
||||
tas.AddTransactionalMethod(m, txatt);
|
||||
|
||||
|
||||
IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction();
|
||||
|
||||
ITransactionStatus status = TransactionStatusForNewTransaction();
|
||||
Expect.On(ptm).Call(ptm.GetTransaction(txatt)).Return(status);
|
||||
UnexpectedRollbackException ex = new UnexpectedRollbackException("foobar", null);
|
||||
ptm.Commit(status);
|
||||
LastCall.On(ptm).Throw(ex);
|
||||
mocks.ReplayAll();
|
||||
|
||||
TestObject to = new TestObject();
|
||||
ITestObject ito = (ITestObject) Advised(to, ptm, tas);
|
||||
|
||||
try
|
||||
{
|
||||
ito.GetDescription();
|
||||
Assert.Fail("Shouldn't have succeeded");
|
||||
} catch (UnexpectedRollbackException thrown)
|
||||
{
|
||||
Assert.IsTrue(thrown == ex);
|
||||
}
|
||||
|
||||
mocks.VerifyAll();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private IPlatformTransactionManager PlatformTxManagerForNewTransaction()
|
||||
{
|
||||
return (IPlatformTransactionManager) mocks.DynamicMock(typeof(IPlatformTransactionManager));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ProgrammaticRollback()
|
||||
{
|
||||
ITransactionAttribute txatt = new DefaultTransactionAttribute();
|
||||
MethodInfo m = typeof(RollbackTestObject).GetMethod("GetDescription");
|
||||
|
||||
MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();
|
||||
tas.AddTransactionalMethod(m, txatt);
|
||||
|
||||
ITransactionStatus status = TransactionStatusForNewTransaction();
|
||||
|
||||
IPlatformTransactionManager ptm = PlatformTxManagerForNewTransaction();
|
||||
|
||||
Expect.Call(ptm.GetTransaction(txatt)).Return(status).Repeat.Once();
|
||||
ptm.Commit(status);
|
||||
LastCall.On(ptm).Repeat.Once();
|
||||
|
||||
mocks.ReplayAll();
|
||||
|
||||
RollbackTestObject to = new RollbackTestObject();
|
||||
|
||||
ITestObject ito = (ITestObject) Advised(to, ptm, tas);
|
||||
|
||||
Assert.AreEqual("test description", ito.GetDescription());
|
||||
|
||||
mocks.VerifyAll();
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RollbackOnException()
|
||||
{
|
||||
DoTestRollbackOnException(new Exception(), true, false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoRollbackOnException()
|
||||
{
|
||||
DoTestRollbackOnException(new Exception(), false, false);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RollbackOnExceptionWithRollbackException()
|
||||
{
|
||||
DoTestRollbackOnException(new Exception(), true, true);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NoRollbackOnExceptionWithRollbackException()
|
||||
{
|
||||
DoTestRollbackOnException(new Exception(), false, true);
|
||||
}
|
||||
|
||||
private void DoTestRollbackOnException(Exception exception, bool shouldRollback, bool rollbackException)
|
||||
{
|
||||
ITransactionAttribute txatt = new ConfigurableTransactionAttribute(shouldRollback);
|
||||
|
||||
|
||||
MethodInfo mi = typeof (ITestObject).GetMethod("Exceptional");
|
||||
|
||||
MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();
|
||||
tas.AddTransactionalMethod(mi, txatt);
|
||||
ITransactionStatus status = TransactionStatusForNewTransaction();
|
||||
|
||||
IPlatformTransactionManager ptm =
|
||||
(IPlatformTransactionManager) mocks.DynamicMock(typeof (IPlatformTransactionManager));
|
||||
|
||||
|
||||
Expect.On(ptm).Call(ptm.GetTransaction(txatt)).Return(status);
|
||||
|
||||
|
||||
if (shouldRollback)
|
||||
{
|
||||
ptm.Rollback(status);
|
||||
}
|
||||
else
|
||||
{
|
||||
ptm.Commit(status);
|
||||
}
|
||||
TransactionSystemException tex = new TransactionSystemException("system exception");
|
||||
if (rollbackException)
|
||||
{
|
||||
LastCall.On(ptm).Throw(tex).Repeat.Once();
|
||||
}
|
||||
else
|
||||
{
|
||||
LastCall.On(ptm).Repeat.Once();
|
||||
}
|
||||
mocks.ReplayAll();
|
||||
|
||||
TestObject to = new TestObject();
|
||||
ITestObject ito = (ITestObject) Advised(to, ptm, tas);
|
||||
|
||||
try
|
||||
{
|
||||
ito.Exceptional(exception);
|
||||
Assert.Fail("Should have thrown exception");
|
||||
} catch (Exception e)
|
||||
{
|
||||
if (rollbackException)
|
||||
{
|
||||
Assert.AreEqual(tex, e);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.AreEqual(exception, e);
|
||||
}
|
||||
}
|
||||
|
||||
mocks.VerifyAll();
|
||||
|
||||
}
|
||||
|
||||
private ITransactionStatus TransactionStatusForNewTransaction()
|
||||
{
|
||||
return (ITransactionStatus) mocks.DynamicMock(typeof (ITransactionStatus));
|
||||
}
|
||||
|
||||
protected abstract object Advised(object target, IPlatformTransactionManager ptm,
|
||||
ITransactionAttributeSource tas);
|
||||
}
|
||||
|
||||
internal class RollbackTestObject : TestObject
|
||||
{
|
||||
public override string GetDescription()
|
||||
{
|
||||
ITransactionStatus txStatus = TransactionInterceptor.CurrentTransactionStatus;
|
||||
txStatus.RollbackOnly = true;
|
||||
return "test description";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class ConfigurableTransactionAttribute : DefaultTransactionAttribute
|
||||
{
|
||||
private bool shouldRollback;
|
||||
public ConfigurableTransactionAttribute(bool shouldRollback)
|
||||
{
|
||||
this.shouldRollback = shouldRollback;
|
||||
}
|
||||
|
||||
public override bool RollbackOn(Exception exception)
|
||||
{
|
||||
return shouldRollback;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
[TestFixture]
|
||||
public class DefaultTransactionAttributeTests
|
||||
{
|
||||
[Test]
|
||||
public void RollbackOnTests()
|
||||
{
|
||||
DefaultTransactionAttribute dta = new DefaultTransactionAttribute();
|
||||
Assert.IsTrue( dta.RollbackOn( new SystemException()));
|
||||
//mlp 3/17 changed rollback to rollback on all exceptions.
|
||||
Assert.IsTrue( dta.RollbackOn( new TransactionSystemException()));
|
||||
}
|
||||
[Test]
|
||||
public void ToStringTests()
|
||||
{
|
||||
DefaultTransactionAttribute dta = new DefaultTransactionAttribute();
|
||||
Assert.AreEqual( "PROPAGATION_Required,ISOLATION_ReadCommitted,-System.Exception", dta.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using Spring.Core.TypeResolution;
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
/// <summary>
|
||||
/// Test MatchAlwaysTransactionAttributeSourceTests
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: MatchAlwaysTransactionAttributeSourceTests.cs,v 1.7 2008/05/27 19:07:03 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class MatchAlwaysTransactionAttributeSourceTests
|
||||
{
|
||||
[Test]
|
||||
public void GetTransactionAttribute()
|
||||
{
|
||||
MatchAlwaysTransactionAttributeSource tas = new MatchAlwaysTransactionAttributeSource();
|
||||
ITransactionAttribute ta = tas.ReturnTransactionAttribute(typeof (Object).GetMethod("GetHashCode"), null);
|
||||
Assert.IsNotNull(ta);
|
||||
Assert.IsTrue(TransactionPropagation.Required == ta.PropagationBehavior);
|
||||
tas.TransactionAttribute = new DefaultTransactionAttribute(TransactionPropagation.Supports);
|
||||
ta =
|
||||
tas.ReturnTransactionAttribute(typeof (DataException).GetType().GetMethod("GetHashCode"),
|
||||
typeof (DataException));
|
||||
Assert.IsNotNull(ta);
|
||||
Assert.IsTrue(TransactionPropagation.Supports == ta.PropagationBehavior);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CanConfigureInAppContext()
|
||||
{
|
||||
TypeRegistry.RegisterType("TransactionPropagation", typeof(TransactionPropagation));
|
||||
IApplicationContext ctx =
|
||||
new XmlApplicationContext(
|
||||
"assembly://Spring.Data.Tests/Spring.Transaction.Interceptor/MatchAlwaysTransactionAttributeSourceTests.xml");
|
||||
MatchAlwaysTransactionAttributeSource tas =
|
||||
(MatchAlwaysTransactionAttributeSource) ctx.GetObject("MatchAlwaysTransactionAttributeSource");
|
||||
Assert.AreEqual(TransactionPropagation.RequiresNew,
|
||||
tas.ReturnTransactionAttribute(null, null).PropagationBehavior);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns='http://www.springframework.net'>
|
||||
<object id="MatchAlwaysTransactionAttributeSource"
|
||||
type="Spring.Transaction.Interceptor.MatchAlwaysTransactionAttributeSource, Spring.Data">
|
||||
|
||||
<property name="transactionAttribute" value="PROPAGATION_REQUIRES_NEW" />
|
||||
|
||||
</object>
|
||||
</objects>
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using Spring.Aop.Framework;
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
[TestFixture]
|
||||
public class NoNoRollbackRuleAttributeTests
|
||||
{
|
||||
[Test]
|
||||
public void FoundImmediatelyWithString()
|
||||
{
|
||||
NoRollbackRuleAttribute rr = new NoRollbackRuleAttribute("System.Exception");
|
||||
Assert.IsTrue(rr.GetDepth(typeof(Exception)) == 0);
|
||||
}
|
||||
[Test]
|
||||
public void FoundImmediatelyWithClass()
|
||||
{
|
||||
NoRollbackRuleAttribute rr = new NoRollbackRuleAttribute(typeof(Exception));
|
||||
Assert.IsTrue(rr.GetDepth(typeof(Exception)) == 0);
|
||||
}
|
||||
[Test]
|
||||
public void NotFound()
|
||||
{
|
||||
NoRollbackRuleAttribute rr = new NoRollbackRuleAttribute("System.Data.DataException");
|
||||
Assert.IsTrue(rr.GetDepth(typeof(ApplicationException)) == -1);
|
||||
}
|
||||
[Test]
|
||||
public void Ancestry()
|
||||
{
|
||||
NoRollbackRuleAttribute rr = new NoRollbackRuleAttribute("System.Exception");
|
||||
Assert.IsTrue(rr.GetDepth(typeof(DataException)) == 2);
|
||||
}
|
||||
[Test]
|
||||
public void AlwaysTrue()
|
||||
{
|
||||
NoRollbackRuleAttribute rr = new NoRollbackRuleAttribute("System.Exception");
|
||||
Assert.IsTrue(rr.GetDepth(typeof(SystemException)) > 0);
|
||||
Assert.IsTrue(rr.GetDepth(typeof(ApplicationException)) > 0);
|
||||
Assert.IsTrue(rr.GetDepth(typeof(DataException)) > 0);
|
||||
Assert.IsTrue(rr.GetDepth(typeof(TransactionSystemException)) > 0);
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(AopConfigException))]
|
||||
public void ConstructorArgMustBeAExceptionClass()
|
||||
{
|
||||
new NoRollbackRuleAttribute( typeof( StringBuilder ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using Spring.Aop.Framework;
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
[TestFixture]
|
||||
public class RollbackRuleAttributeTests
|
||||
{
|
||||
[Test]
|
||||
public void FoundImmediatelyWithString()
|
||||
{
|
||||
RollbackRuleAttribute rr = new RollbackRuleAttribute("System.Exception");
|
||||
Assert.IsTrue(rr.GetDepth(typeof (Exception)) == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FoundImmediatelyWithClass()
|
||||
{
|
||||
RollbackRuleAttribute rr = new RollbackRuleAttribute(typeof (Exception));
|
||||
Assert.IsTrue(rr.GetDepth(new Exception()) == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FoundImmediatelyWithType()
|
||||
{
|
||||
RollbackRuleAttribute rr = new RollbackRuleAttribute(typeof (Exception));
|
||||
Assert.IsTrue(rr.GetDepth(typeof (Exception)) == 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NotFound()
|
||||
{
|
||||
RollbackRuleAttribute rr = new RollbackRuleAttribute("System.Data.DataException");
|
||||
Assert.IsTrue(rr.GetDepth(typeof (ApplicationException)) == -1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Ancestry()
|
||||
{
|
||||
RollbackRuleAttribute rr = new RollbackRuleAttribute("System.Exception");
|
||||
Assert.IsTrue(rr.GetDepth(typeof (DataException)) == 2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AlwaysTrue()
|
||||
{
|
||||
RollbackRuleAttribute rr = new RollbackRuleAttribute("System.Exception");
|
||||
Assert.IsTrue(rr.GetDepth(typeof (SystemException)) > 0);
|
||||
Assert.IsTrue(rr.GetDepth(typeof (ApplicationException)) > 0);
|
||||
Assert.IsTrue(rr.GetDepth(typeof (DataException)) > 0);
|
||||
Assert.IsTrue(rr.GetDepth(typeof (TransactionSystemException)) > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof (AopConfigException))]
|
||||
public void ConstructorArgMustBeAExceptionClass()
|
||||
{
|
||||
new RollbackRuleAttribute(typeof (StringBuilder));
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void ConstructorArgMustBeAExceptionClassWithNullThrowableType()
|
||||
{
|
||||
new RollbackRuleAttribute((Type)null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentNullException))]
|
||||
public void ConstructorArgExceptionStringNameVersionWithNull()
|
||||
{
|
||||
new RollbackRuleAttribute((String)null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using NUnit.Framework;
|
||||
using Spring.Collections;
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
[TestFixture]
|
||||
public class RuleBasedTransactionAttributeTests
|
||||
{
|
||||
[Test]
|
||||
public void DefaultRule()
|
||||
{
|
||||
RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute();
|
||||
Assert.IsTrue(rta.RollbackOn(new SystemException()));
|
||||
//mlp 3/17 changed rollback to rollback on all exceptions.
|
||||
Assert.IsTrue(rta.RollbackOn(new ApplicationException()));
|
||||
Assert.IsTrue( rta.RollbackOn(new TransactionSystemException()));
|
||||
}
|
||||
[Test]
|
||||
public void RuleForRollbackOnApplicationException()
|
||||
{
|
||||
IList list = new LinkedList();
|
||||
list.Add(new RollbackRuleAttribute("Spring.Transaction.TransactionSystemException"));
|
||||
RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute( TransactionPropagation.Required, list );
|
||||
|
||||
Assert.IsTrue( rta.RollbackOn(new SystemException()));
|
||||
//mlp 3/17 changed rollback to rollback on all exceptions.
|
||||
Assert.IsTrue( rta.RollbackOn(new ApplicationException()));
|
||||
Assert.IsTrue(( rta.RollbackOn( new TransactionSystemException())));
|
||||
}
|
||||
[Test]
|
||||
public void RuleForCommitOnUnchecked()
|
||||
{
|
||||
IList list = new LinkedList();
|
||||
list.Add( new NoRollbackRuleAttribute("System.SystemException"));
|
||||
list.Add(new RollbackRuleAttribute("Spring.Transaction.TransactionSystemException"));
|
||||
|
||||
RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute( TransactionPropagation.Required, list );
|
||||
Assert.IsFalse( rta.RollbackOn(new SystemException()));
|
||||
Assert.IsTrue( rta.RollbackOn(new TransactionSystemException()));
|
||||
}
|
||||
[Test]
|
||||
public void RuleForSelectiveRollbackOnCheckedWithString()
|
||||
{
|
||||
IList list = new LinkedList();
|
||||
list.Add( new RollbackRuleAttribute("Spring.Transaction.TransactionSystemException"));
|
||||
RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute( TransactionPropagation.Required, list );
|
||||
ruleForSelectionRollbackOnChecked( rta );
|
||||
}
|
||||
[Test]
|
||||
public void RuleForSelectiveRollbackOnCheckedWithClass()
|
||||
{
|
||||
IList list = new LinkedList();
|
||||
list.Add( new RollbackRuleAttribute(typeof(TransactionSystemException)));
|
||||
RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute( TransactionPropagation.Required, list );
|
||||
ruleForSelectionRollbackOnChecked( rta );
|
||||
}
|
||||
private void ruleForSelectionRollbackOnChecked( RuleBasedTransactionAttribute rta )
|
||||
{
|
||||
Assert.IsTrue(rta.RollbackOn(new SystemException()));
|
||||
Assert.IsTrue( rta.RollbackOn(new TransactionSystemException()));
|
||||
}
|
||||
[Test]
|
||||
public void RuleForCommitOnSubclassOfChecked()
|
||||
{
|
||||
IList list = new LinkedList();
|
||||
list.Add( new RollbackRuleAttribute("System.Data.DataException"));
|
||||
list.Add( new NoRollbackRuleAttribute("Spring.Transaction.TransactionSystemException"));
|
||||
RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute( TransactionPropagation.Required, list );
|
||||
|
||||
Assert.IsTrue( rta.RollbackOn(new SystemException()));
|
||||
Assert.IsFalse( rta.RollbackOn(new TransactionSystemException()));
|
||||
}
|
||||
[Test]
|
||||
public void RollbackNever()
|
||||
{
|
||||
IList list = new LinkedList();
|
||||
list.Add( new NoRollbackRuleAttribute("System.Exception"));
|
||||
RuleBasedTransactionAttribute rta = new RuleBasedTransactionAttribute( TransactionPropagation.Required, list );
|
||||
|
||||
Assert.IsFalse(rta.RollbackOn(new SystemException()));
|
||||
Assert.IsFalse(rta.RollbackOn(new DataException()));
|
||||
Assert.IsFalse(rta.RollbackOn(new ApplicationException()));
|
||||
Assert.IsFalse(rta.RollbackOn(new TransactionSystemException()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Runtime.Remoting;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
[TestFixture]
|
||||
public class TransactionAttributeEditorTests
|
||||
{
|
||||
[Test]
|
||||
public void NullTest()
|
||||
{
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor( );
|
||||
editor.SetAsText( null );
|
||||
ITransactionAttribute ta = editor.Value;
|
||||
Assert.IsNull( ta );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmptyStringTest()
|
||||
{
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor( );
|
||||
editor.SetAsText( String.Empty );
|
||||
ITransactionAttribute ta = editor.Value;
|
||||
Assert.IsNull( ta );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidPropagationCodeOnly()
|
||||
{
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor( );
|
||||
editor.SetAsText( "PROPAGATION_REQUIRED" );
|
||||
ITransactionAttribute ta = editor.Value;
|
||||
Assert.IsTrue( ta != null );
|
||||
Assert.IsTrue( ta.PropagationBehavior == TransactionPropagation.Required );
|
||||
Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.ReadCommitted );
|
||||
Assert.IsFalse( ta.ReadOnly );
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException( typeof ( ArgumentException ) )]
|
||||
public void InvalidPropagationCodeOnly()
|
||||
{
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor( );
|
||||
editor.SetAsText( "INVALIDPROPAGATIONCODE" );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidPropagationCodeAndIsolationCode()
|
||||
{
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor( );
|
||||
editor.SetAsText( "PROPAGATION_REQUIRED, ISOLATION_READUNCOMMITTED" );
|
||||
ITransactionAttribute ta = editor.Value;
|
||||
Assert.IsTrue( ta != null );
|
||||
Assert.IsTrue( ta.PropagationBehavior == TransactionPropagation.Required );
|
||||
Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.ReadUncommitted );
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException( typeof ( ArgumentException ) )]
|
||||
public void ValidPropagationAndIsolationCodeAndInvalidRollbackRule()
|
||||
{
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor( );
|
||||
editor.SetAsText( "PROPAGATION_REQUIRED,ISOLATION_READUNCOMMITTED,XXX" );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidPropagationCodeAndIsolationCodeAndRollbackRules1()
|
||||
{
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor( );
|
||||
editor.SetAsText( "PROPAGATION_MANDATORY,ISOLATION_REPEATABLEREAD,timeout_10,-DataException,+RemotingException" );
|
||||
ITransactionAttribute ta = editor.Value;
|
||||
Assert.IsNotNull( ta );
|
||||
Assert.IsTrue( ta.PropagationBehavior == TransactionPropagation.Mandatory );
|
||||
Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.RepeatableRead );
|
||||
Assert.IsTrue( ta.TransactionTimeout == 10 );
|
||||
Assert.IsFalse( ta.ReadOnly );
|
||||
Assert.IsTrue( ta.RollbackOn( new SystemException( ) ) );
|
||||
// Check for our bizarre customized rollback rules
|
||||
Assert.IsTrue( ta.RollbackOn( new DataException( ) ) );
|
||||
Assert.IsTrue( !ta.RollbackOn( new RemotingException( ) ) );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ValidPropagationCodeAndIsolationCodeAndRollbackRules2()
|
||||
{
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor( );
|
||||
editor.SetAsText( "+DataException,readOnly,ISOLATION_READCOMMITTED,-RemotingException,PROPAGATION_SUPPORTS" );
|
||||
ITransactionAttribute ta = editor.Value;
|
||||
Assert.IsNotNull( ta );
|
||||
Assert.IsTrue( ta.PropagationBehavior == TransactionPropagation.Supports );
|
||||
Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.ReadCommitted );
|
||||
Assert.IsTrue( ta.TransactionTimeout == -1 );
|
||||
Assert.IsTrue( ta.ReadOnly );
|
||||
Assert.IsTrue( ta.RollbackOn( new SystemException( ) ) );
|
||||
// Check for our bizarre customized rollback rules
|
||||
Assert.IsFalse( ta.RollbackOn( new DataException( ) ) );
|
||||
Assert.IsTrue( ta.RollbackOn( new RemotingException( ) ) );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DefaultTransactionAttributeToString()
|
||||
{
|
||||
DefaultTransactionAttribute source = new DefaultTransactionAttribute( );
|
||||
source.PropagationBehavior = TransactionPropagation.Supports;
|
||||
source.TransactionIsolationLevel = IsolationLevel.RepeatableRead;
|
||||
source.TransactionTimeout = 10;
|
||||
source.ReadOnly = true;
|
||||
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor( );
|
||||
editor.SetAsText( source.ToString( ) );
|
||||
ITransactionAttribute ta = editor.Value;
|
||||
Assert.AreEqual( source, ta );
|
||||
Assert.AreEqual( ta.PropagationBehavior, TransactionPropagation.Supports );
|
||||
Assert.AreEqual( ta.TransactionIsolationLevel, IsolationLevel.RepeatableRead );
|
||||
Assert.AreEqual( ta.TransactionTimeout, 10 );
|
||||
Assert.IsTrue( ta.ReadOnly );
|
||||
Assert.IsTrue( ta.RollbackOn( new SystemException( ) ) );
|
||||
//mlp 3/17 changed rollback to rollback on all exceptions.
|
||||
Assert.IsTrue( ta.RollbackOn( new ApplicationException( ) ) );
|
||||
|
||||
source.TransactionTimeout = 9;
|
||||
Assert.IsFalse( ta == source );
|
||||
source.TransactionTimeout = 10;
|
||||
Assert.AreEqual( ta, source );
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RuleBasedTransactionAttributeToString()
|
||||
{
|
||||
RuleBasedTransactionAttribute source = new RuleBasedTransactionAttribute();
|
||||
source.PropagationBehavior = TransactionPropagation.Supports;
|
||||
source.TransactionIsolationLevel = IsolationLevel.RepeatableRead;
|
||||
source.TransactionTimeout = 10;
|
||||
source.ReadOnly = true;
|
||||
source.AddRollbackRule( new RollbackRuleAttribute("ArgumentException"));
|
||||
source.AddRollbackRule( new NoRollbackRuleAttribute("IllegalTransactionStateException"));
|
||||
|
||||
TransactionAttributeEditor editor = new TransactionAttributeEditor();
|
||||
editor.SetAsText( source.ToString() );
|
||||
ITransactionAttribute ta = editor.Value;
|
||||
Assert.AreEqual( source, ta );
|
||||
Assert.AreEqual( ta.PropagationBehavior, TransactionPropagation.Supports );
|
||||
Assert.AreEqual( ta.TransactionIsolationLevel, IsolationLevel.RepeatableRead );
|
||||
Assert.AreEqual( ta.TransactionTimeout, 10 );
|
||||
Assert.IsTrue( ta.ReadOnly );
|
||||
Assert.IsTrue(ta.RollbackOn(new ArgumentException()));
|
||||
Assert.IsFalse( ta.RollbackOn(new IllegalTransactionStateException()));
|
||||
|
||||
source.ClearRollbackRules();
|
||||
Assert.IsFalse( ta == source );
|
||||
source.AddRollbackRule( new RollbackRuleAttribute("ArgumentException"));
|
||||
source.AddRollbackRule( new NoRollbackRuleAttribute("IllegalTransactionStateException"));
|
||||
Assert.AreEqual( ta, source );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using NUnit.Framework;
|
||||
using Spring.Util;
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
[TestFixture]
|
||||
public class TransactionAttributeSourceAdvisorTests
|
||||
{
|
||||
[Test]
|
||||
public void Serializability()
|
||||
{
|
||||
TransactionInterceptor ti = new TransactionInterceptor();
|
||||
ti.TransactionAttributes = new NameValueCollection();
|
||||
TransactionAttributeSourceAdvisor tas = new TransactionAttributeSourceAdvisor(ti);
|
||||
SerializationTestUtils.SerializeAndDeserialize(tas);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Reflection;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
[TestFixture]
|
||||
public class TransactionAttributeSourceEditorTests
|
||||
{
|
||||
[Test]
|
||||
public void Null()
|
||||
{
|
||||
TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();
|
||||
pe.SetAsText(null);
|
||||
ITransactionAttributeSource tas = pe.Value;
|
||||
MethodInfo m = typeof(object).GetMethod("GetHashCode");
|
||||
Assert.IsTrue(tas.ReturnTransactionAttribute(m, null) == null);
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void Invalid()
|
||||
{
|
||||
TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();
|
||||
pe.SetAsText("foo=bar");
|
||||
}
|
||||
[Test]
|
||||
public void MatchesSpecific()
|
||||
{
|
||||
TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();
|
||||
pe.SetAsText("System.Object.GetHashCode, Mscorlib =PROPAGATION_REQUIRED\n" +
|
||||
"System.Object.Equals, Mscorlib =PROPAGATION_MANDATORY\n" +
|
||||
"System.Object.*pe, Mscorlib=PROPAGATION_SUPPORTS");
|
||||
ITransactionAttributeSource tas = pe.Value;
|
||||
|
||||
checkTransactionProperties(tas, typeof(object).GetMethod("GetHashCode"), TransactionPropagation.Required);
|
||||
checkTransactionProperties(tas, typeof(object).GetMethod("Equals", new Type[] { typeof(object) }),TransactionPropagation.Mandatory);
|
||||
checkTransactionProperties(tas, typeof(object).GetMethod( "GetType" ), TransactionPropagation.Supports);
|
||||
checkTransactionProperties(tas, typeof(object).GetMethod("ToString") );
|
||||
}
|
||||
[Test]
|
||||
public void MatchesAll()
|
||||
{
|
||||
TransactionAttributeSourceEditor pe = new TransactionAttributeSourceEditor();
|
||||
pe.SetAsText("System.Object.*, Mscorlib=PROPAGATION_REQUIRED");
|
||||
ITransactionAttributeSource tas = pe.Value;
|
||||
|
||||
checkTransactionProperties(tas, typeof(object).GetMethod("GetHashCode"), TransactionPropagation.Required);
|
||||
checkTransactionProperties(tas, typeof(object).GetMethod("Equals", new Type[] { typeof(object) }),TransactionPropagation.Required);
|
||||
checkTransactionProperties(tas, typeof(object).GetMethod("GetType"), TransactionPropagation.Required);
|
||||
checkTransactionProperties(tas, typeof(object).GetMethod("ToString"), TransactionPropagation.Required);
|
||||
}
|
||||
private void checkTransactionProperties( ITransactionAttributeSource tas, MethodInfo method )
|
||||
{
|
||||
ITransactionAttribute ta = tas.ReturnTransactionAttribute( method, null );
|
||||
Assert.IsNull(ta);
|
||||
}
|
||||
private void checkTransactionProperties( ITransactionAttributeSource tas, MethodInfo method, TransactionPropagation transactionPropagation )
|
||||
{
|
||||
ITransactionAttribute ta = tas.ReturnTransactionAttribute( method, null );
|
||||
Assert.IsTrue( ta != null );
|
||||
Assert.IsTrue( ta.TransactionIsolationLevel == IsolationLevel.ReadCommitted );
|
||||
Assert.IsTrue( ta.PropagationBehavior == transactionPropagation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2008 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Specialized;
|
||||
using NUnit.Framework;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains tests for the various
|
||||
/// <see cref="ITransactionAttributeSource"/> implementations.
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: TransactionAttributeSourceTests.cs,v 1.1 2008/05/27 19:07:03 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class TransactionAttributeSourceTests
|
||||
{
|
||||
[Test]
|
||||
public void MethodMapTransactionAttributeSource()
|
||||
{
|
||||
MethodMapTransactionAttributeSource tas = new MethodMapTransactionAttributeSource();
|
||||
IDictionary methodMap = new Hashtable();
|
||||
methodMap.Add("System.Object.GetHashCode, mscorlib", "PROPAGATION_REQUIRED");
|
||||
methodMap.Add("System.Object.ToString, mscorlib",
|
||||
new DefaultTransactionAttribute(TransactionPropagation.Supports));
|
||||
tas.MethodMap = methodMap;
|
||||
|
||||
ITransactionAttribute ta = tas.ReturnTransactionAttribute(typeof(object).GetMethod("GetHashCode"), null);
|
||||
Assert.IsNotNull(ta);
|
||||
Assert.AreEqual(TransactionPropagation.Required, ta.PropagationBehavior);
|
||||
|
||||
ta = tas.ReturnTransactionAttribute(typeof(object).GetMethod("ToString"), null);
|
||||
Assert.IsNotNull(ta);
|
||||
Assert.AreEqual(TransactionPropagation.Supports, ta.PropagationBehavior);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Test that configuration of the IDictionary baesd map supports transaction attribute information
|
||||
/// set via object (i.e. DefaultTransactionAttribute) as well as strings.
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void NameMatchTransactionAttributeSource()
|
||||
{
|
||||
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
|
||||
IDictionary methodMap = new Hashtable();
|
||||
methodMap.Add("GetHashCode", "PROPAGATION_REQUIRED");
|
||||
methodMap.Add("ToString", new DefaultTransactionAttribute(TransactionPropagation.Supports));
|
||||
tas.NameMap = methodMap;
|
||||
ITransactionAttribute ta = tas.ReturnTransactionAttribute(typeof (object).GetMethod("GetHashCode"), null);
|
||||
Assert.IsNotNull(ta);
|
||||
Assert.AreEqual(TransactionPropagation.Required, ta.PropagationBehavior);
|
||||
ta = tas.ReturnTransactionAttribute(typeof (object).GetMethod("ToString"), null);
|
||||
Assert.IsNotNull(ta);
|
||||
Assert.AreEqual(TransactionPropagation.Supports, ta.PropagationBehavior);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameMatchTransactionAttributeSourceWithStarAtStartOfMethodName()
|
||||
{
|
||||
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
|
||||
NameValueCollection attributes = new NameValueCollection();
|
||||
attributes.Add("*ashCode", "PROPAGATION_REQUIRED");
|
||||
tas.NameProperties = attributes;
|
||||
ITransactionAttribute ta = tas.ReturnTransactionAttribute(typeof (object).GetMethod("GetHashCode"), null);
|
||||
Assert.IsNotNull(ta);
|
||||
Assert.AreEqual(TransactionPropagation.Required, ta.PropagationBehavior);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameMatchTransactionAttributeSourceWithStarAtEndOfMethodName()
|
||||
{
|
||||
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
|
||||
NameValueCollection attributes = new NameValueCollection();
|
||||
attributes.Add("GetHashCod*", "PROPAGATION_REQUIRED");
|
||||
tas.NameProperties = attributes;
|
||||
ITransactionAttribute ta = tas.ReturnTransactionAttribute(typeof(object).GetMethod("GetHashCode"), null);
|
||||
Assert.IsNotNull(ta);
|
||||
Assert.AreEqual(TransactionPropagation.Required, ta.PropagationBehavior);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameMatchTransactionAttributeSourceMostSpecificMethodNameIsDefinitelyMatched()
|
||||
{
|
||||
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
|
||||
NameValueCollection attributes = new NameValueCollection();
|
||||
attributes.Add("*", "PROPAGATION_REQUIRED");
|
||||
attributes.Add("GetHashCode", "PROPAGATION_MANDATORY");
|
||||
tas.NameProperties = attributes;
|
||||
ITransactionAttribute ta = tas.ReturnTransactionAttribute(typeof(object).GetMethod("GetHashCode"), null);
|
||||
Assert.IsNotNull(ta);
|
||||
Assert.AreEqual(TransactionPropagation.Mandatory, ta.PropagationBehavior);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameMatchTransactionAttributeSourceWithEmptyMethodName()
|
||||
{
|
||||
NameMatchTransactionAttributeSource tas = new NameMatchTransactionAttributeSource();
|
||||
NameValueCollection attributes = new NameValueCollection();
|
||||
attributes.Add("", "PROPAGATION_MANDATORY");
|
||||
tas.NameProperties = attributes;
|
||||
ITransactionAttribute ta = tas.ReturnTransactionAttribute(typeof(object).GetMethod("GetHashCode"), null);
|
||||
Assert.IsNull(ta);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
|
||||
#region Imports
|
||||
|
||||
using NUnit.Framework;
|
||||
using Spring.Aop.Framework;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Transaction.Interceptor
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains mock objects tests the TransactionInterceptor
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id: TransactionInterceptorTests.cs,v 1.3 2007/10/21 18:16:58 markpollack Exp $</version>
|
||||
[TestFixture]
|
||||
public class TransactionInterceptorTests : AbstractTransactionAspectTests
|
||||
{
|
||||
|
||||
|
||||
protected override object Advised(object target, IPlatformTransactionManager ptm,
|
||||
ITransactionAttributeSource tas)
|
||||
{
|
||||
TransactionInterceptor ti = new TransactionInterceptor();
|
||||
ti.TransactionManager = ptm;
|
||||
Assert.AreEqual(ptm, ti.TransactionManager);
|
||||
ti.TransactionAttributeSource = tas;
|
||||
Assert.AreEqual(tas, ti.TransactionAttributeSource);
|
||||
ProxyFactory pf = new ProxyFactory(target);
|
||||
pf.AddAdvice(0, ti);
|
||||
return pf.GetProxy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using Spring.Transaction;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction
|
||||
{
|
||||
[TestFixture]
|
||||
public class InvalidTimeoutExceptionTests
|
||||
{
|
||||
[Test]
|
||||
public void TimeoutGetter()
|
||||
{
|
||||
InvalidTimeoutException ex = new InvalidTimeoutException( "bad timeout", 2000 );
|
||||
Assert.IsTrue( 2000 == ex.Timeout );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction.Support
|
||||
{
|
||||
[TestFixture]
|
||||
public class AbstractPlatformTransactionManagerTests
|
||||
{
|
||||
private MockTxnPlatformMgrAbstract _mockTxnMgr;
|
||||
|
||||
[SetUp]
|
||||
public void Init()
|
||||
{
|
||||
_mockTxnMgr = new MockTxnPlatformMgrAbstract();
|
||||
if ( TransactionSynchronizationManager.SynchronizationActive )
|
||||
{
|
||||
TransactionSynchronizationManager.ClearSynchronization();
|
||||
}
|
||||
}
|
||||
[TearDown]
|
||||
public void Destroy()
|
||||
{
|
||||
_mockTxnMgr.Verify();
|
||||
_mockTxnMgr = null;
|
||||
if ( TransactionSynchronizationManager.SynchronizationActive )
|
||||
{
|
||||
TransactionSynchronizationManager.ClearSynchronization();
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
public void VanillaProperties()
|
||||
{
|
||||
Assert.AreEqual( TransactionSynchronizationState.Always, _mockTxnMgr.TransactionSynchronization);
|
||||
Assert.IsTrue(!_mockTxnMgr.NestedTransactionsAllowed);
|
||||
Assert.IsTrue(!_mockTxnMgr.RollbackOnCommitFailure);
|
||||
|
||||
_mockTxnMgr.NestedTransactionsAllowed = true;
|
||||
_mockTxnMgr.RollbackOnCommitFailure = true;
|
||||
_mockTxnMgr.TransactionSynchronization = TransactionSynchronizationState.OnActualTransaction;
|
||||
|
||||
Assert.AreEqual( TransactionSynchronizationState.OnActualTransaction, _mockTxnMgr.TransactionSynchronization);
|
||||
Assert.IsTrue(_mockTxnMgr.NestedTransactionsAllowed);
|
||||
Assert.IsTrue(_mockTxnMgr.RollbackOnCommitFailure);
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(InvalidTimeoutException), "Invalid transaction timeout")]
|
||||
public void DefinitionInvalidTimeoutException()
|
||||
{
|
||||
MockTxnDefinition def = new MockTxnDefinition();
|
||||
def.TransactionTimeout = -1000;
|
||||
_mockTxnMgr.GetTransaction( def );
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(IllegalTransactionStateException), "Transaction propagation 'mandatory' but no existing transaction found")]
|
||||
public void DefinitionInvalidPropagationState()
|
||||
{
|
||||
MockTxnDefinition def = new MockTxnDefinition();
|
||||
def.PropagationBehavior = TransactionPropagation.Mandatory;
|
||||
_mockTxnMgr.GetTransaction( def );
|
||||
}
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(IllegalTransactionStateException), "Transaction propagation 'never' but existing transaction found.")]
|
||||
public void NeverPropagateState()
|
||||
{
|
||||
MockTxnDefinition def = new MockTxnDefinition();
|
||||
def.PropagationBehavior = TransactionPropagation.Never;
|
||||
setGeneralGetTransactionExpectations();
|
||||
_mockTxnMgr.GetTransaction(def);
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(NestedTransactionNotSupportedException), "Transaction manager does not allow nested transactions by default - specify 'NestedTransactionsAllowed' property with value 'true'")]
|
||||
public void NoNestedTransactionsAllowed()
|
||||
{
|
||||
MockTxnDefinition def = new MockTxnDefinition();
|
||||
def.PropagationBehavior = TransactionPropagation.Nested;
|
||||
setGeneralGetTransactionExpectations();
|
||||
_mockTxnMgr.GetTransaction(def);
|
||||
}
|
||||
[Test]
|
||||
public void TransactionSuspendedSuccessfully()
|
||||
{
|
||||
MockTxnDefinition def = new MockTxnDefinition();
|
||||
def.PropagationBehavior = TransactionPropagation.NotSupported;
|
||||
def.ReadOnly = false;
|
||||
setGeneralGetTransactionExpectations();
|
||||
|
||||
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
|
||||
Assert.IsNull( status.Transaction );
|
||||
Assert.IsTrue( !status.IsNewTransaction );
|
||||
Assert.IsTrue( status.NewSynchronization );
|
||||
Assert.IsTrue( !status.ReadOnly );
|
||||
Assert.IsNotNull( status.SuspendedResources);
|
||||
}
|
||||
[Test]
|
||||
public void TransactionCreatedSuccessfully()
|
||||
{
|
||||
MockTxnDefinition def = new MockTxnDefinition();
|
||||
def.PropagationBehavior = TransactionPropagation.RequiresNew;
|
||||
def.ReadOnly = false;
|
||||
|
||||
setGeneralGetTransactionExpectations();
|
||||
|
||||
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
|
||||
Assert.AreEqual( _mockTxnMgr.Transaction, status.Transaction );
|
||||
Assert.IsTrue( status.IsNewTransaction );
|
||||
Assert.IsTrue( status.NewSynchronization );
|
||||
Assert.IsTrue( !status.ReadOnly );
|
||||
Assert.IsNotNull( status.SuspendedResources);
|
||||
}
|
||||
[Test]
|
||||
public void NestedTransactionSuccessfully()
|
||||
{
|
||||
MockTxnDefinition def = new MockTxnDefinition();
|
||||
def.PropagationBehavior = TransactionPropagation.Nested;
|
||||
def.ReadOnly = false;
|
||||
|
||||
setGeneralGetTransactionExpectations();
|
||||
_mockTxnMgr.SetExpectedCalls( "DoBegin", 1 );
|
||||
_mockTxnMgr.Savepoints = false;
|
||||
_mockTxnMgr.NestedTransactionsAllowed = true;
|
||||
|
||||
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
|
||||
Assert.AreEqual( _mockTxnMgr.Transaction, status.Transaction );
|
||||
Assert.IsTrue( status.IsNewTransaction );
|
||||
Assert.AreEqual( true, status.NewSynchronization );
|
||||
Assert.IsTrue( !status.ReadOnly );
|
||||
Assert.IsNull( status.SuspendedResources);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NestedTransactionWithSavepoint()
|
||||
{
|
||||
MockTxnDefinition def = new MockTxnDefinition();
|
||||
def.PropagationBehavior = TransactionPropagation.Nested;
|
||||
def.ReadOnly = false;
|
||||
setVanillaGetTransactionExpectations();
|
||||
_mockTxnMgr.SetTransaction( new MyMockTxnObjectSavepointMgr());
|
||||
_mockTxnMgr.SetExpectedCalls("DoBegin", 0);
|
||||
_mockTxnMgr.Savepoints = true;
|
||||
_mockTxnMgr.NestedTransactionsAllowed = true;
|
||||
|
||||
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
|
||||
Assert.AreEqual( _mockTxnMgr.Transaction, status.Transaction );
|
||||
Assert.IsFalse( status.IsNewTransaction );
|
||||
Assert.IsFalse( status.NewSynchronization );
|
||||
Assert.IsTrue( !status.ReadOnly );
|
||||
Assert.IsNull( status.SuspendedResources);
|
||||
}
|
||||
[Test]
|
||||
public void DefaultPropagationBehavior()
|
||||
{
|
||||
MockTxnDefinition def = new MockTxnDefinition();
|
||||
def.PropagationBehavior = TransactionPropagation.Required;
|
||||
def.ReadOnly = true;
|
||||
setGeneralGetTransactionExpectations();
|
||||
|
||||
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
|
||||
Assert.AreEqual( _mockTxnMgr.Transaction, status.Transaction );
|
||||
Assert.IsTrue( !status.IsNewTransaction );
|
||||
Assert.IsTrue( status.NewSynchronization );
|
||||
Assert.IsTrue( status.ReadOnly );
|
||||
Assert.IsNull( status.SuspendedResources);
|
||||
}
|
||||
[Test]
|
||||
public void DefaultPropagationBehaviorWithNullDefinition()
|
||||
{
|
||||
setGeneralGetTransactionExpectations();
|
||||
|
||||
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(null);
|
||||
Assert.AreEqual( _mockTxnMgr.Transaction, status.Transaction );
|
||||
Assert.IsTrue( !status.IsNewTransaction );
|
||||
Assert.IsTrue( status.NewSynchronization );
|
||||
Assert.IsTrue( !status.ReadOnly );
|
||||
Assert.IsNull( status.SuspendedResources);
|
||||
}
|
||||
[Test]
|
||||
public void DefaultNoExistingTransaction()
|
||||
{
|
||||
setVanillaGetTransactionExpectations();
|
||||
_mockTxnMgr.SetExpectedCalls( "DoBegin", 1 );
|
||||
|
||||
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(null);
|
||||
Assert.IsNotNull( status.Transaction );
|
||||
Assert.IsTrue( status.IsNewTransaction );
|
||||
Assert.IsTrue( status.NewSynchronization );
|
||||
Assert.IsTrue( !status.ReadOnly );
|
||||
Assert.IsNull( status.SuspendedResources);
|
||||
}
|
||||
[Test]
|
||||
public void DefaultBehaviorDefaultPropagationNoExistingTransaction()
|
||||
{
|
||||
setVanillaGetTransactionExpectations();
|
||||
_mockTxnMgr.SetExpectedCalls( "DoBegin", 0 );
|
||||
|
||||
MockTxnDefinition def = new MockTxnDefinition();
|
||||
def.PropagationBehavior = TransactionPropagation.Never;
|
||||
def.ReadOnly = true;
|
||||
|
||||
DefaultTransactionStatus status = (DefaultTransactionStatus)_mockTxnMgr.GetTransaction(def);
|
||||
Assert.IsNull( status.Transaction );
|
||||
Assert.IsTrue( !status.IsNewTransaction );
|
||||
Assert.IsTrue( status.NewSynchronization );
|
||||
Assert.IsTrue( status.ReadOnly );
|
||||
Assert.IsNull( status.SuspendedResources);
|
||||
}
|
||||
private void setGeneralGetTransactionExpectations()
|
||||
{
|
||||
_mockTxnMgr.SetTransaction( new object() );
|
||||
setVanillaGetTransactionExpectations();
|
||||
}
|
||||
|
||||
private void setVanillaGetTransactionExpectations()
|
||||
{
|
||||
_mockTxnMgr.SetExpectedCalls( "DoGetTransaction", 1);
|
||||
_mockTxnMgr.SetExpectedCalls( "IsExistingTransaction", 1);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction.Support
|
||||
{
|
||||
[TestFixture]
|
||||
public class DefaultTransactionDefinitionTests
|
||||
{
|
||||
[Test]
|
||||
public void VanillaTest()
|
||||
{
|
||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition( TransactionPropagation.NotSupported);
|
||||
Assert.IsTrue( def.PropagationBehavior == TransactionPropagation.NotSupported );
|
||||
def.PropagationBehavior = TransactionPropagation.Nested;
|
||||
Assert.IsTrue( def.PropagationBehavior == TransactionPropagation.Nested );
|
||||
def.TransactionIsolationLevel = IsolationLevel.ReadCommitted;
|
||||
Assert.IsTrue( def.TransactionIsolationLevel == IsolationLevel.ReadCommitted);
|
||||
def.TransactionTimeout = 1000;
|
||||
Assert.IsTrue( 1000 == def.TransactionTimeout );
|
||||
Assert.IsTrue( false == def.ReadOnly );
|
||||
def.ReadOnly = true;
|
||||
Assert.IsTrue( true == def.ReadOnly );
|
||||
}
|
||||
[Test]
|
||||
public void IsolationLeveNonDefaultl()
|
||||
{
|
||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
||||
Assert.IsTrue( def.PropagationBehavior == TransactionPropagation.Required );
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void InvalidTimeout()
|
||||
{
|
||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
||||
def.TransactionTimeout = -1000;
|
||||
}
|
||||
[Test]
|
||||
public void DefinitionString()
|
||||
{
|
||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
||||
DefaultTransactionDefinition def2 = new DefaultTransactionDefinition();
|
||||
|
||||
Assert.IsTrue( def.ToString() == def2.ToString());
|
||||
def.Equals(def2);
|
||||
}
|
||||
[Test]
|
||||
public void DefinitionStringFilled()
|
||||
{
|
||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition( TransactionPropagation.Never );
|
||||
def.TransactionIsolationLevel = IsolationLevel.Chaos;
|
||||
def.TransactionTimeout = 1000;
|
||||
def.ReadOnly = true;
|
||||
Assert.AreEqual( "PROPAGATION_Never,ISOLATION_Chaos,timeout_1000,readOnly", def.ToString());
|
||||
|
||||
DefaultTransactionDefinition def2 = new DefaultTransactionDefinition( TransactionPropagation.Never );
|
||||
def2.TransactionIsolationLevel = IsolationLevel.Chaos;
|
||||
def2.TransactionTimeout = 1000;
|
||||
def2.ReadOnly = true;
|
||||
|
||||
Assert.IsTrue( def2.Equals(def));
|
||||
Assert.IsTrue( def.GetHashCode() == def2.GetHashCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using Spring.Transaction;
|
||||
|
||||
namespace Spring.Transaction.Support
|
||||
{
|
||||
[TestFixture]
|
||||
public class DefaultTransactionStatusTests
|
||||
{
|
||||
[Test]
|
||||
public void DefaultConstructorTests()
|
||||
{
|
||||
MyMockTxnObject txn = new MyMockTxnObject();
|
||||
txn.SetExpectedIsRollBackOnlyValue( false );
|
||||
txn.SetExpectedRollbackOnlyCalls( 1 );
|
||||
|
||||
DefaultTransactionStatus stat = new DefaultTransactionStatus( txn, true, false, false, true, new object() );
|
||||
Assert.IsNotNull( stat.Transaction );
|
||||
Assert.IsTrue( !stat.ReadOnly );
|
||||
Assert.IsTrue( !stat.NewSynchronization );
|
||||
Assert.IsNotNull( stat.SuspendedResources );
|
||||
Assert.IsTrue( stat.IsNewTransaction );
|
||||
Assert.IsTrue( ! stat.RollbackOnly );
|
||||
stat.RollbackOnly = true;
|
||||
Assert.IsTrue( stat.RollbackOnly );
|
||||
txn.Verify();
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(NestedTransactionNotSupportedException))]
|
||||
public void CreateSavepointException()
|
||||
{
|
||||
DefaultTransactionStatus stat = new DefaultTransactionStatus( new MyMockTxnObject(), true, false, false, true, new object() );
|
||||
stat.CreateSavepoint( "mySavePoint" );
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(NestedTransactionNotSupportedException))]
|
||||
public void RollbackSavepointException()
|
||||
{
|
||||
DefaultTransactionStatus stat = new DefaultTransactionStatus( new MyMockTxnObject(), true, false, false, true, new object() );
|
||||
stat.RollbackToSavepoint(null);
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(NestedTransactionNotSupportedException))]
|
||||
public void ReleaseSavepointException()
|
||||
{
|
||||
DefaultTransactionStatus stat = new DefaultTransactionStatus( new MyMockTxnObject(), true, false, false, true, new object() );
|
||||
stat.ReleaseSavepoint(null);
|
||||
}
|
||||
[Test]
|
||||
public void CreateSaveAndHoldValidSavepoint()
|
||||
{
|
||||
MyMockTxnObjectSavepointMgr saveMgr = new MyMockTxnObjectSavepointMgr();
|
||||
saveMgr.SetSavepointToReturn( "savepoint" );
|
||||
DefaultTransactionStatus status = new DefaultTransactionStatus( saveMgr , true, false, false, true, new object());
|
||||
status.CreateAndHoldSavepoint( "savepoint" );
|
||||
Assert.IsTrue( status.HasSavepoint );
|
||||
Assert.AreEqual( "savepoint", status.Savepoint );
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(TransactionUsageException))]
|
||||
public void RollbackHeldSavepointException()
|
||||
{
|
||||
DefaultTransactionStatus stat = new DefaultTransactionStatus( new MyMockTxnObject(), true, false, false, true, new object() );
|
||||
stat.RollbackToHeldSavepoint();
|
||||
}
|
||||
[Test]
|
||||
public void RollbackHeldSavepointSuccess()
|
||||
{
|
||||
MyMockTxnObjectSavepointMgr saveMgr = new MyMockTxnObjectSavepointMgr();
|
||||
string savepoint = "savepoint";
|
||||
saveMgr.SetExpectedSavepoint( savepoint );
|
||||
saveMgr.SetSavepointToReturn( savepoint );
|
||||
DefaultTransactionStatus status = new DefaultTransactionStatus( saveMgr , true, false, false, true, new object());
|
||||
status.CreateAndHoldSavepoint( savepoint );
|
||||
Assert.IsTrue( status.HasSavepoint );
|
||||
Assert.AreEqual( savepoint, status.Savepoint );
|
||||
|
||||
status.RollbackToHeldSavepoint();
|
||||
saveMgr.Verify();
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(TransactionUsageException))]
|
||||
public void ReleaseHeldSavepointException()
|
||||
{
|
||||
DefaultTransactionStatus stat = new DefaultTransactionStatus( new MyMockTxnObject(), true, false, false, true, new object() );
|
||||
stat.ReleaseHeldSavepoint();
|
||||
}
|
||||
[Test]
|
||||
public void ReleaseHeldSavepointSuccess()
|
||||
{
|
||||
MyMockTxnObjectSavepointMgr saveMgr = new MyMockTxnObjectSavepointMgr();
|
||||
string savepoint = "savepoint";
|
||||
saveMgr.SetExpectedSavepoint( savepoint );
|
||||
saveMgr.SetSavepointToReturn( savepoint );
|
||||
DefaultTransactionStatus status = new DefaultTransactionStatus( saveMgr , true, false, false, true, new object());
|
||||
status.CreateAndHoldSavepoint( savepoint );
|
||||
Assert.IsTrue( status.HasSavepoint );
|
||||
Assert.AreEqual( savepoint, status.Savepoint );
|
||||
|
||||
status.ReleaseHeldSavepoint();
|
||||
saveMgr.Verify();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction.Support
|
||||
{
|
||||
[TestFixture]
|
||||
public class ResourceHolderSupportTests : ResourceHolderSupport
|
||||
{
|
||||
[TearDown]
|
||||
public void Destroy()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
[Test]
|
||||
public void PropertiesTest()
|
||||
{
|
||||
Assert.AreEqual( DateTime.MinValue, Deadline);
|
||||
Assert.IsTrue( !SynchronizedWithTransaction );
|
||||
Assert.IsTrue( !RollbackOnly);
|
||||
|
||||
//TODO investigate
|
||||
/*
|
||||
Deadline = DateTime.Now.AddDays(2);
|
||||
Assert.IsTrue( HasDeadline );
|
||||
Assert.AreEqual( DateTime.Now.AddDays(2).Date, Deadline.Date );
|
||||
*/
|
||||
|
||||
SynchronizedWithTransaction = true;
|
||||
Assert.IsTrue( SynchronizedWithTransaction );
|
||||
|
||||
RollbackOnly = true;
|
||||
Assert.IsTrue( RollbackOnly);
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void InvalidDeadline()
|
||||
{
|
||||
int time = TimeToLiveInSeconds;
|
||||
}
|
||||
|
||||
/*
|
||||
[Ignore("investigate...")]
|
||||
[Test]
|
||||
public void ZeroMilliseconds()
|
||||
{
|
||||
Deadline = DateTime.Now.AddDays(-1);
|
||||
Assert.AreEqual( 0, TimeToLiveInMilliseconds );
|
||||
}
|
||||
*/
|
||||
/*
|
||||
[Test]
|
||||
public void MillisecondToLive()
|
||||
{
|
||||
Deadline = DateTime.Now.AddDays(1);
|
||||
Assert.IsTrue( TimeToLiveInMilliseconds >= 0);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
[Test]
|
||||
public void SetDeadline()
|
||||
{
|
||||
SetDeadlineInSeconds( 10 );
|
||||
Assert.IsTrue( TimeToLiveInSeconds >= 0);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
[Test]
|
||||
public void SetDeadlineMillis()
|
||||
{
|
||||
SetDeadlineInMilliseconds(1000);
|
||||
Assert.IsTrue( TimeToLiveInMilliseconds >= 0);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction.Support
|
||||
{
|
||||
[TestFixture]
|
||||
public class TransactionSynchronizationAdapterTests : TransactionSynchronizationAdapter
|
||||
{
|
||||
[Test]
|
||||
public void CoverageTests()
|
||||
{
|
||||
AfterCompletion( TransactionSynchronizationStatus.Committed );
|
||||
BeforeCommit(false);
|
||||
BeforeCompletion();
|
||||
Resume();
|
||||
Suspend();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction.Support
|
||||
{
|
||||
[TestFixture]
|
||||
public class TransactionSynchronizationManagerTests
|
||||
{
|
||||
[SetUp]
|
||||
public void Init()
|
||||
{
|
||||
if ( TransactionSynchronizationManager.SynchronizationActive )
|
||||
{
|
||||
TransactionSynchronizationManager.ClearSynchronization();
|
||||
}
|
||||
}
|
||||
[TearDown]
|
||||
public void Destory()
|
||||
{
|
||||
if ( TransactionSynchronizationManager.SynchronizationActive )
|
||||
{
|
||||
TransactionSynchronizationManager.ClearSynchronization();
|
||||
}
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
public void SynchronizationsInvalid()
|
||||
{
|
||||
IList syncs = TransactionSynchronizationManager.Synchronizations;
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
public void InitSynchronizationsInvalid()
|
||||
{
|
||||
TransactionSynchronizationManager.InitSynchronization();
|
||||
TransactionSynchronizationManager.InitSynchronization();
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
public void SynchronizationsClearInvalid()
|
||||
{
|
||||
TransactionSynchronizationManager.ClearSynchronization();
|
||||
}
|
||||
[Test]
|
||||
[ExpectedException(typeof(InvalidOperationException))]
|
||||
public void RegisterSyncsInvalid()
|
||||
{
|
||||
TransactionSynchronizationManager.RegisterSynchronization(new MockTxnSync());
|
||||
}
|
||||
[Test]
|
||||
public void SynchronizationsLifeCycle()
|
||||
{
|
||||
TransactionSynchronizationManager.InitSynchronization();
|
||||
IList syncs = TransactionSynchronizationManager.Synchronizations;
|
||||
Assert.AreEqual( 0, syncs.Count );
|
||||
TransactionSynchronizationManager.RegisterSynchronization( new MockTxnSync() );
|
||||
syncs = TransactionSynchronizationManager.Synchronizations;
|
||||
Assert.AreEqual( 1, syncs.Count );
|
||||
TransactionSynchronizationManager.ClearSynchronization();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Spring.Transaction.Support
|
||||
{
|
||||
[TestFixture]
|
||||
public class TransactionTemplateTests
|
||||
{
|
||||
[Test]
|
||||
[ExpectedException(typeof(ArgumentException))]
|
||||
public void NoTxnMgr()
|
||||
{
|
||||
TransactionTemplate temp = new TransactionTemplate();
|
||||
temp.AfterPropertiesSet();
|
||||
}
|
||||
[Test]
|
||||
public void TxnMgr()
|
||||
{
|
||||
TransactionTemplate temp = new TransactionTemplate();
|
||||
temp.PlatformTransactionManager = new MockTxnPlatformMgr();
|
||||
temp.AfterPropertiesSet();
|
||||
}
|
||||
[Test]
|
||||
public void ExecuteException()
|
||||
{
|
||||
MockTxnPlatformMgr mock = new MockTxnPlatformMgr();
|
||||
mock.SetExpectedGetTxnCallCount(1);
|
||||
mock.SetExpectedRollbackCallCount(1);
|
||||
TransactionTemplate temp = new TransactionTemplate(mock);
|
||||
try
|
||||
{
|
||||
temp.Execute(new TransactionDelegate(DummyExceptionMethod));
|
||||
Assert.Fail("Should throw exception");
|
||||
} catch
|
||||
{
|
||||
|
||||
}
|
||||
mock.Verify();
|
||||
}
|
||||
[Test]
|
||||
public void ExecuteExceptionRollbackException()
|
||||
{
|
||||
MockTxnPlatformMgr mock = new MockTxnPlatformMgr();
|
||||
mock.SetExpectedGetTxnCallCount(1);
|
||||
mock.SetExpectedRollbackCallCount(1);
|
||||
mock.ThrowRollbackException = true;
|
||||
TransactionTemplate temp = new TransactionTemplate(mock);
|
||||
try
|
||||
{
|
||||
temp.Execute(new TransactionDelegate(DummyExceptionMethod));
|
||||
Assert.Fail("Should throw exception");
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
mock.Verify();
|
||||
}
|
||||
[Test]
|
||||
public void NullResult()
|
||||
{
|
||||
MockTxnPlatformMgr mock = new MockTxnPlatformMgr();
|
||||
mock.SetExpectedGetTxnCallCount(1);
|
||||
mock.SetExpectedCommitCallCount(1);
|
||||
TransactionTemplate temp = new TransactionTemplate(mock);
|
||||
temp.AfterPropertiesSet();
|
||||
Assert.AreEqual( mock, temp.PlatformTransactionManager);
|
||||
Assert.IsNull( temp.Execute(new TransactionDelegate(DummyTransactionMethod) ) );
|
||||
mock.Verify();
|
||||
}
|
||||
public object DummyTransactionMethod( ITransactionStatus status )
|
||||
{
|
||||
return status;
|
||||
}
|
||||
public object DummyExceptionMethod( ITransactionStatus status )
|
||||
{
|
||||
throw new Exception("Bad Error");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user