Fix issues in Spring.Data.Tests caused by new version of Rhino.Mocks, also set build to happen in .NET 3.5 for Spring.Data tests (allows lambdas)
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
<!-- build Spring.Aop -->
|
||||
<!-- use .NET 3.5 compiler for tests to allow lambdas etc -->
|
||||
<property name="temp.nant.settings.currentframework" value="${nant.settings.currentframework}" />
|
||||
<property name="nant.settings.currentframework" value="net-3.5" />
|
||||
<property name="nant.settings.currentframework" value="net-3.5" if="${nant.settings.currentframework == 'net-2.0' or nant.settings.currentframework == 'net-3.0'}" />
|
||||
<csc target="library" define="${current.build.defines.csc}"
|
||||
warnaserror="true"
|
||||
optimize="${build.optimize}"
|
||||
|
||||
@@ -29,36 +29,31 @@ namespace Spring.Data.Objects
|
||||
/// </summary>
|
||||
public abstract class AbstractAdoQueryTests
|
||||
{
|
||||
|
||||
protected MockRepository mocks;
|
||||
protected IDbProvider provider;
|
||||
protected IDbCommand command;
|
||||
|
||||
|
||||
public void SetUpMocks()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
provider = (IDbProvider)mocks.DynamicMock(typeof(IDbProvider));
|
||||
provider = MockRepository.GenerateMock<IDbProvider>();
|
||||
IDbConnection connection = MockRepository.GenerateMock<IDbConnection>();
|
||||
|
||||
IDbConnection connection = (IDbConnection)mocks.DynamicMock(typeof(IDbConnection));
|
||||
|
||||
Expect.Call(provider.CreateConnection()).Return(connection);
|
||||
provider.Stub(x => x.CreateConnection()).Return(connection).Repeat.Once();
|
||||
|
||||
// Creating a query (setting DbProvider property)
|
||||
// will call new DbParameters(IDbProvider), which is a real pain to mock.
|
||||
// to store the declared parameters.
|
||||
|
||||
command = (IDbCommand)mocks.DynamicMock(typeof(IDbCommand));
|
||||
command = MockRepository.GenerateMock<IDbCommand>();
|
||||
//This IDbCommand is used as a container for the underlying parameter collection.
|
||||
Expect.Call(provider.CreateCommand()).Return(command);
|
||||
provider.Stub(x => x.CreateCommand()).Return(command).Repeat.Once();
|
||||
|
||||
//Create a real instance of IDbParameters to stored the declared parameters
|
||||
IDbProvider realDbProvider = DbProviderFactory.GetDbProvider("System.Data.SqlClient");
|
||||
IDbParameters dbParameters = new DbParameters(realDbProvider);
|
||||
|
||||
//Pass real instance into mock instance.
|
||||
Expect.Call(command.Parameters).Return(dbParameters.DataParameterCollection);
|
||||
Expect.Call(provider.CreateCommand()).Return(command);
|
||||
command.Stub(x => x.Parameters).Return(dbParameters.DataParameterCollection).Repeat.Once();
|
||||
provider.Stub(x => x.CreateCommand()).Return(command).Repeat.Once();
|
||||
|
||||
// done with init of DbParameters mock/stubbing
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region License
|
||||
|
||||
/*
|
||||
@@ -42,8 +43,11 @@
|
||||
using System.Collections;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Rhino.Mocks;
|
||||
|
||||
using Spring.Dao;
|
||||
using Spring.Data.Common;
|
||||
|
||||
@@ -58,31 +62,26 @@ namespace Spring.Data.Objects
|
||||
[TestFixture]
|
||||
public class AdoQueryTests : AbstractAdoQueryTests
|
||||
{
|
||||
|
||||
private static string SELECT_ID_WHERE = "select id from custmr";
|
||||
private static string[] COLUMN_NAMES = new string[] {"id", "forename"};
|
||||
private static DbType[] COLUMN_TYPES = new DbType[] {DbType.Int32, DbType.String};
|
||||
private static DbType[] COLUMN_TYPES = new DbType[] {DbType.Int32, DbType.String};
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
SetUpMocks();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void MappingAdoQueryWithContextWithoutParams()
|
||||
{
|
||||
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);
|
||||
IDataReader reader = MockRepository.GenerateMock<IDataReader>();
|
||||
reader.Stub(x => x.Read()).Return(true).Repeat.Once();
|
||||
reader.Stub(x => x.GetInt32(0)).Return(1).Repeat.Once();
|
||||
reader.Stub(x => x.Read()).Return(false).Repeat.Once();
|
||||
|
||||
Expect.Call(command.ExecuteReader()).Return(reader);
|
||||
command.Stub(x => x.ExecuteReader()).Return(reader);
|
||||
|
||||
mocks.ReplayAll();
|
||||
IntMappingQueryWithContext queryWithNoContext = new IntMappingQueryWithContext(provider);
|
||||
queryWithNoContext.Compile();
|
||||
IList list = queryWithNoContext.QueryByNamedParam(null, null);
|
||||
@@ -91,23 +90,19 @@ namespace Spring.Data.Objects
|
||||
{
|
||||
Assert.AreEqual(1, count);
|
||||
}
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
[ExpectedException(typeof(InvalidDataAccessApiUsageException))]
|
||||
[ExpectedException(typeof (InvalidDataAccessApiUsageException))]
|
||||
public void QueryWithoutEnoughParams()
|
||||
{
|
||||
SqlParameter sqlParameter1 = new SqlParameter();
|
||||
Expect.Call(command.CreateParameter()).Return(sqlParameter1);
|
||||
Expect.Call(provider.CreateParameterNameForCollection(COLUMN_NAMES[0])).Return("@" + COLUMN_NAMES[0]);
|
||||
SqlParameter sqlParameter1 = new SqlParameter();
|
||||
command.Stub(x => x.CreateParameter()).Return(sqlParameter1).Repeat.Once();
|
||||
provider.Stub(x => x.CreateParameterNameForCollection(COLUMN_NAMES[0])).Return("@" + COLUMN_NAMES[0]).Repeat.Once();
|
||||
|
||||
SqlParameter sqlParameter2 = new SqlParameter();
|
||||
Expect.Call(command.CreateParameter()).Return(sqlParameter2);
|
||||
Expect.Call(provider.CreateParameterNameForCollection(COLUMN_NAMES[1])).Return("@" + COLUMN_NAMES[1]);
|
||||
|
||||
mocks.ReplayAll();
|
||||
command.Stub(x => x.CreateParameter()).Return(sqlParameter2);
|
||||
provider.Stub(x => x.CreateParameterNameForCollection(COLUMN_NAMES[1])).Return("@" + COLUMN_NAMES[1]);
|
||||
|
||||
IntMappingAdoQuery query = new IntMappingAdoQuery();
|
||||
query.DbProvider = provider;
|
||||
@@ -116,11 +111,8 @@ namespace Spring.Data.Objects
|
||||
query.DeclaredParameters.Add(COLUMN_NAMES[1], COLUMN_TYPES[1]);
|
||||
query.Compile();
|
||||
query.Query();
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
|
||||
public class IntMappingQueryWithContext : MappingAdoQueryWithContext
|
||||
{
|
||||
private static string sql = "select id from custmr";
|
||||
@@ -131,7 +123,6 @@ namespace Spring.Data.Objects
|
||||
CommandType = CommandType.Text;
|
||||
}
|
||||
|
||||
|
||||
protected override object MapRow(IDataReader reader, int rowNum, IDictionary inParams,
|
||||
IDictionary callingContext)
|
||||
{
|
||||
@@ -148,6 +139,5 @@ namespace Spring.Data.Objects
|
||||
return reader.GetInt32(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region License
|
||||
|
||||
/*
|
||||
@@ -42,8 +43,11 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
using NUnit.Framework;
|
||||
|
||||
using Rhino.Mocks;
|
||||
|
||||
using Spring.Data.Common;
|
||||
|
||||
#endregion
|
||||
@@ -67,28 +71,19 @@ namespace Spring.Data.Objects
|
||||
public void NullArg()
|
||||
{
|
||||
SqlParameter sqlParameter1 = new SqlParameter();
|
||||
Expect.Call(command.CreateParameter()).Return(sqlParameter1);
|
||||
Expect.Call(provider.CreateParameterNameForCollection("ptest")).Return("@ptest");
|
||||
command.Stub(x => x.CreateParameter()).Return(sqlParameter1);
|
||||
provider.Stub(x => x.CreateParameterNameForCollection("ptest")).Return("@ptest");
|
||||
|
||||
//Create a real instance of IDbParameters to store the executable parameters
|
||||
//IDbProvider realDbProvider = DbProviderFactory.GetDbProvider("System.Data.SqlClient");
|
||||
//IDbParameters dbParameters = new DbParameters(realDbProvider);
|
||||
IDataParameterCollection dbParamCollection = new SqlCommand().Parameters;
|
||||
Expect.Call(command.Parameters).Return(dbParamCollection);
|
||||
|
||||
//provide the same instance to another call to extract output params
|
||||
Expect.Call(command.Parameters).Return(dbParamCollection);
|
||||
command.Stub(x => x.Parameters).Return(dbParamCollection).Repeat.Twice();
|
||||
|
||||
|
||||
mocks.ReplayAll();
|
||||
NullArg na = new NullArg(provider);
|
||||
na.Execute(null);
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
internal class NullArg : StoredProcedure
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
-->
|
||||
<target name="build">
|
||||
<!-- build Spring.Data.Tests -->
|
||||
<!-- use .NET 3.5 compiler for tests to allow lambdas etc -->
|
||||
<property name="temp.nant.settings.currentframework" value="${nant.settings.currentframework}" />
|
||||
<property name="nant.settings.currentframework" value="net-3.5" if="${nant.settings.currentframework == 'net-2.0' or nant.settings.currentframework == 'net-3.0'}" />
|
||||
<csc target="library" define="${current.build.defines.csc}"
|
||||
warnaserror="true"
|
||||
optimize="${build.optimize}"
|
||||
@@ -42,7 +45,10 @@
|
||||
</references>
|
||||
</csc>
|
||||
|
||||
<copy file="${project::get-base-directory()}/${project::get-name()}.dll.config"
|
||||
<!-- restore old framework setting -->
|
||||
<property name="nant.settings.currentframework" value="${temp.nant.settings.currentframework}" />
|
||||
|
||||
<copy file="${project::get-base-directory()}/${project::get-name()}.dll.config"
|
||||
tofile="${current.bin.dir}/${project::get-name()}.dll.config"/>
|
||||
</target>
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
<!-- use .NET 3.5 compiler for tests to allow lambdas etc -->
|
||||
<property name="temp.nant.settings.currentframework" value="${nant.settings.currentframework}" />
|
||||
<property name="nant.settings.currentframework" value="net-3.5" />
|
||||
<property name="nant.settings.currentframework" value="net-3.5" if="${nant.settings.currentframework == 'net-2.0' or nant.settings.currentframework == 'net-3.0'}" />
|
||||
|
||||
<csc target="library" define="${current.build.defines.csc}"
|
||||
warnaserror="true"
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
<!-- use .NET 3.5 compiler for tests to allow lambdas etc -->
|
||||
<property name="temp.nant.settings.currentframework" value="${nant.settings.currentframework}" />
|
||||
<property name="nant.settings.currentframework" value="net-3.5" />
|
||||
<property name="nant.settings.currentframework" value="net-3.5" if="${nant.settings.currentframework == 'net-2.0' or nant.settings.currentframework == 'net-3.0'}" />
|
||||
|
||||
<csc target="library" define="${current.build.defines.csc}"
|
||||
warnaserror="true"
|
||||
|
||||
Reference in New Issue
Block a user