コード例 #1
0
        public void Execute_OneDbCommandBuilder()
        {
            _dbCommandBuilder1Mock.Expect(mock => mock.Create(_commandExecutionContextStub)).Return(_dbCommandMock1);
            _dbCommandMock1.Expect(mock => mock.Dispose());
            _dataReaderMock.Expect(mock => mock.Dispose());
            _commandExecutionContextStub.Stub(stub => stub.ExecuteReader(_dbCommandMock1, CommandBehavior.SingleResult)).Return(_dataReaderMock);
            _objectIDReaderStub.Stub(stub => stub.ReadSequence(_dataReaderMock)).Return(_fakeResult);
            _repository.ReplayAll();

            var command = new MultiObjectIDLoadCommand(new[] { _dbCommandBuilder1Mock }, _objectIDReaderStub);

            var result = command.Execute(_commandExecutionContextStub).ToArray();

            _repository.VerifyAll();
            Assert.That(result, Is.EqualTo(new[] { _objectID1 }));
        }
コード例 #2
0
        public void Execute_SeveralCommandBuilders()
        {
            _commandExecutionContextStub.Stub(stub => stub.ExecuteReader(_dbCommandMock1, CommandBehavior.SingleResult)).Return(_dataReaderMock);
            _commandExecutionContextStub.Stub(stub => stub.ExecuteReader(_dbCommandMock2, CommandBehavior.SingleResult)).Return(_dataReaderMock);
            _dbCommandBuilderMock1.Expect(mock => mock.Create(_commandExecutionContextStub)).Return(_dbCommandMock1);
            _dbCommandBuilderMock2.Expect(mock => mock.Create(_commandExecutionContextStub)).Return(_dbCommandMock2);
            _dbCommandMock1.Expect(mock => mock.Dispose());
            _dbCommandMock2.Expect(mock => mock.Dispose());
            _dataReaderMock.Expect(mock => mock.Dispose()).Repeat.Twice();
            _repository.ReplayAll();

            _objectReaderStub1.Stub(stub => stub.ReadSequence(_dataReaderMock)).Return(new[] { _fakeResult1 });
            _objectReaderStub2.Stub(stub => stub.ReadSequence(_dataReaderMock)).Return(new[] { _fakeResult2 });

            var command = new MultiObjectLoadCommand <object> (
                new[]
            {
                Tuple.Create(_dbCommandBuilderMock1, _objectReaderStub1),
                Tuple.Create(_dbCommandBuilderMock2, _objectReaderStub2)
            });

            var result = command.Execute(_commandExecutionContextStub).ToArray();

            _repository.VerifyAll();
            Assert.That(result, Is.EqualTo(new[] { _fakeResult1, _fakeResult2 }));
        }