/// <summary>
        /// Creates a DataMapper that can be used to test updates.
        /// </summary>
        /// <returns>Returns a StubDataMapper.</returns>
        public static IDataMapper CreateForUpdate()
        {
            var parameters = MockRepository.GenerateMock <DbParameterCollection>();

            var command = MockRepository.GenerateMock <DbCommand>();

            command.Expect(c => c.Parameters).Return(parameters);
            command.Stub(c => c.CommandText);
            command.Expect(c => c.ExecuteNonQuery()).Return(1);
            command
            .Expect(c => c.CreateParameter())
            .Repeat.Any()
            .Return(MockRepository.GenerateStub <DbParameter>());

            var connection = MockRepository.GenerateMock <DbConnection>();

            connection.Expect(c => c.CreateCommand()).Return(command);

            command.Expect(c => c.Connection).Return(connection);

            DbProviderFactory dbFactory = MockRepository.GenerateMock <DbProviderFactory>();

            dbFactory.Expect(f => f.CreateConnection()).Return(connection);

            return(new StubDataMapper(dbFactory));
        }
Esempio n. 2
0
        protected IDataMapper CreateDB_ForQuery(StubResultSet rs)
        {
            StubDataReader reader = new StubDataReader(rs);

            _parameters = MockRepository.GenerateMock <DbParameterCollection>();
            _parameters.Expect(p => p.Add(null)).Return(1).IgnoreArguments();

            _command = MockRepository.GenerateMock <DbCommand>();
            _command.Expect(c => c.ExecuteReader()).Return(reader);

            _command.Expect(c => c.Parameters).Return(_parameters);
            _command.Expect(c => c.CreateParameter()).Return(new System.Data.SqlClient.SqlParameter()).Repeat.Any();
            _command.Stub(c => c.CommandText);

            _connection = MockRepository.GenerateMock <DbConnection>();
            _connection.Expect(c => c.CreateCommand()).Return(_command);

            _command.Expect(c => c.Connection).Return(_connection);

            DbProviderFactory dbFactory = MockRepository.GenerateMock <DbProviderFactory>();

            dbFactory.Expect(f => f.CreateConnection()).Return(_connection);

            return(new DataMapper(dbFactory, "connString..."));
        }
Esempio n. 3
0
        protected IDataMapper CreateDataMapper()
        {
            _command = MockRepository.GenerateMock <DbCommand>();

            _connection = MockRepository.GenerateMock <DbConnection>();
            _connection.Expect(c => c.CreateCommand()).Return(_command);

            DbProviderFactory dbFactory = MockRepository.GenerateMock <DbProviderFactory>();

            dbFactory.Expect(f => f.CreateConnection()).Return(_connection);

            return(new DataMapper(dbFactory, "connString..."));
        }
Esempio n. 4
0
        protected IDataMapper CreateDB_ForInsert()
        {
            _parameters = MockRepository.GenerateMock <DbParameterCollection>();

            _command = MockRepository.GenerateMock <DbCommand>();
            _command.Expect(c => c.Parameters).Return(_parameters);
            _command.Stub(c => c.CommandText);
            _command
            .Expect(c => c.CreateParameter())
            .Repeat.Any()
            .Return(MockRepository.GenerateStub <DbParameter>());

            _connection = MockRepository.GenerateMock <DbConnection>();
            _connection.Expect(c => c.CreateCommand()).Return(_command);

            _command.Expect(c => c.Connection).Return(_connection);

            DbProviderFactory dbFactory = MockRepository.GenerateMock <DbProviderFactory>();

            dbFactory.Expect(f => f.CreateConnection()).Return(_connection);

            return(new DataMapper(dbFactory, "connString..."));
        }