Initial import!

This commit is contained in:
markpollack
2008-05-30 22:55:02 +00:00
commit c478a783c0
2978 changed files with 510966 additions and 0 deletions

View File

@@ -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

View 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
}
}

View 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 );
}
}
}