Update of /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.Tests/Data/Objects
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv13646/Data/Objects
Modified Files:
AdoQueryTests.cs
Added Files:
AbstractAdoQueryTests.cs AdoOperationTests.cs
StoredProcedureTests.cs
Log Message:
SPRNET-954 - DeclaredParameters property is not property initialized in AdoOperation subclasses
--- NEW FILE: AdoOperationTests.cs ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: AbstractAdoQueryTests.cs ---
(This appears to be a binary file; contents omitted.)
--- NEW FILE: StoredProcedureTests.cs ---
(This appears to be a binary file; contents omitted.)
Index: AdoQueryTests.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/test/Spring/Spring.Data.Tests/Data/Objects/AdoQueryTests.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** AdoQueryTests.cs 25 Jul 2007 08:25:34 -0000 1.3
--- AdoQueryTests.cs 30 May 2008 21:10:00 -0000 1.4
***************
*** 18,21 ****
--- 18,40 ----
#endregion
+ #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
#region Imports
***************
*** 23,29 ****
using System.Collections;
using System.Data;
! using DotNetMock.Dynamic;
using NUnit.Framework;
using Rhino.Mocks;
using Spring.Data.Common;
--- 42,49 ----
using System.Collections;
using System.Data;
! using System.Data.SqlClient;
using NUnit.Framework;
using Rhino.Mocks;
+ using Spring.Dao;
using Spring.Data.Common;
***************
*** 33,64 ****
{
/// <summary>
! /// This class contains tests for AdoQuery subclasses
/// </summary>
/// <author>Mark Pollack</author>
/// <version>$Id$</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);
--- 53,81 ----
{
/// <summary>
! /// Tests for AdoQuery
/// </summary>
/// <author>Mark Pollack</author>
/// <version>$Id$</version>
[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};
[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);
***************
*** 66,73 ****
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);
--- 83,89 ----
Expect.Call(command.ExecuteReader()).Return(reader);
! mocks.ReplayAll();
! IntMappingQueryWithContext queryWithNoContext = new IntMappingQueryWithContext(provider);
queryWithNoContext.Compile();
IList list = queryWithNoContext.QueryByNamedParam(null, null);
***************
*** 79,142 ****
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)
{
--- 95,131 ----
mocks.VerifyAll();
}
!
[Test]
! [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 sqlParameter2 = new SqlParameter();
! Expect.Call(command.CreateParameter()).Return(sqlParameter2);
! Expect.Call(provider.CreateParameterNameForCollection(COLUMN_NAMES[1])).Return("@" + COLUMN_NAMES[1]);
! mocks.ReplayAll();
+ IntMappingAdoQuery query = new IntMappingAdoQuery();
+ query.DbProvider = provider;
+ query.Sql = SELECT_ID_WHERE;
+ query.DeclaredParameters.Add(COLUMN_NAMES[0], COLUMN_TYPES[0]);
+ query.DeclaredParameters.Add(COLUMN_NAMES[1], COLUMN_TYPES[1]);
+ query.Compile();
+ IList list = query.Query();
+ mocks.VerifyAll();
}
!
! public class IntMappingQueryWithContext : MappingAdoQueryWithContext
{
private static string sql = "select id from custmr";
! public IntMappingQueryWithContext(IDbProvider dbProvider)
: base(dbProvider, sql)
{
***************
*** 153,156 ****
--- 142,153 ----
}
}
+
+ public class IntMappingAdoQuery : MappingAdoQuery
+ {
+ protected override object MapRow(IDataReader reader, int rowNum)
+ {
+ return reader.GetInt32(0);
+ }
+ }
}
|