public void LoadObjectIDsFromCommandBuilder()
        {
            var enumerableStub = _repository.Stub <IEnumerable <ObjectID> > ();
            var enumeratorMock = _repository.StrictMock <IEnumerator <ObjectID> > ();

            using (_repository.Ordered())
            {
                _dbCommandBuilder1Mock.Expect(mock => mock.Create(_commandExecutionContextStub)).Return(_dbCommandMock1);
                _commandExecutionContextStub.Stub(stub => stub.ExecuteReader(_dbCommandMock1, CommandBehavior.SingleResult)).Return(_dataReaderMock);
                _objectIDReaderStub.Stub(stub => stub.ReadSequence(_dataReaderMock)).Return(enumerableStub);
                enumerableStub.Stub(stub => stub.GetEnumerator()).Return(enumeratorMock);
                enumeratorMock.Expect(mock => mock.MoveNext()).Return(false);
                enumeratorMock.Expect(mock => mock.Dispose());
                _dataReaderMock.Expect(mock => mock.Dispose());
                _dbCommandMock1.Expect(mock => mock.Dispose());
            }

            _repository.ReplayAll();

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

            var result =
                (IEnumerable <ObjectID>)
                PrivateInvoke.InvokeNonPublicMethod(command, "LoadObjectIDsFromCommandBuilder", _dbCommandBuilder1Mock, _commandExecutionContextStub);

            result.ToArray();

            _repository.VerifyAll();
        }
        protected virtual IStorageProviderCommand <IEnumerable <DataContainer>, IRdbmsProviderCommandExecutionContext> CreateForIndirectRelationLookup(
            UnionViewDefinition unionViewDefinition,
            RelationEndPointDefinition foreignKeyEndPoint,
            ObjectID foreignKeyValue,
            SortExpressionDefinition sortExpression)
        {
            var selectedColumns  = unionViewDefinition.ObjectIDProperty.GetColumns();
            var dbCommandBuilder = _dbCommandBuilderFactory.CreateForSelect(
                unionViewDefinition,
                selectedColumns,
                GetComparedColumns(foreignKeyEndPoint, foreignKeyValue),
                GetOrderedColumns(sortExpression));

            var objectIDReader = _objectReaderFactory.CreateObjectIDReader(unionViewDefinition, selectedColumns);

            var objectIDLoadCommand = new MultiObjectIDLoadCommand(new[] { dbCommandBuilder }, objectIDReader);
            var indirectDataContainerLoadCommand = new IndirectDataContainerLoadCommand(objectIDLoadCommand, _storageProviderCommandFactory);

            return(DelegateBasedCommand.Create(
                       indirectDataContainerLoadCommand,
                       lookupResults => lookupResults.Select(
                           result =>
            {
                Assertion.IsNotNull(
                    result.LocatedObject,
                    "Because ID lookup and DataContainer lookup are executed within the same database transaction, the DataContainer can never be null.");
                return result.LocatedObject;
            })));
        }
        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 }));
        }
        public override void SetUp()
        {
            base.SetUp();

            _repository = new MockRepository();

            _dbCommandBuilder1Mock = _repository.StrictMock <IDbCommandBuilder>();
            _dbCommandBuilder2Mock = _repository.StrictMock <IDbCommandBuilder>();

            _commandExecutionContextStub = _repository.Stub <IRdbmsProviderCommandExecutionContext> ();
            _objectIDReaderStub          = _repository.Stub <IObjectReader <ObjectID> > ();

            _dbCommandMock1 = _repository.StrictMock <IDbCommand>();
            _dbCommandMock2 = _repository.StrictMock <IDbCommand> ();
            _dataReaderMock = _repository.StrictMock <IDataReader>();

            _command = new MultiObjectIDLoadCommand(new[] { _dbCommandBuilder1Mock, _dbCommandBuilder2Mock }, _objectIDReaderStub);

            _objectID1  = new ObjectID("Order", Guid.NewGuid());
            _fakeResult = new[] { _objectID1 };
        }