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

            using (_repository.Ordered())
            {
                _dbCommandBuilderMock1.Expect(mock => mock.Create(_commandExecutionContextStub)).Return(_dbCommandMock1);
                _commandExecutionContextStub.Stub(stub => stub.ExecuteReader(_dbCommandMock1, CommandBehavior.SingleResult)).Return(_dataReaderMock);
                _objectReaderStub1.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 MultiObjectLoadCommand <object> (new[] { Tuple.Create(_dbCommandBuilderMock1, _objectReaderStub1) });

            var result = command.Execute(_commandExecutionContextStub);

            result.ToArray();

            _repository.VerifyAll();
        }
        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 }));
        }
Пример #3
0
        public virtual IStorageProviderCommand <IEnumerable <ObjectLookupResult <object> >, IRdbmsProviderCommandExecutionContext> CreateForMultiTimestampLookup(
            IEnumerable <ObjectID> objectIDs)
        {
            ArgumentUtility.CheckNotNull("objectIDs", objectIDs);

            var dbCommandBuildersAndReaders =
                from id in objectIDs
                let tableDefinition = _tableDefinitionFinder.GetTableDefinition(id)
                                      group id by tableDefinition
                                      into idsByTable
                                      let selectedColumns = idsByTable.Key.ObjectIDProperty.GetColumns().Concat(idsByTable.Key.TimestampProperty.GetColumns()).ToArray()
                                                            let timestampReader = _objectReaderFactory.CreateTimestampReader(idsByTable.Key, selectedColumns)
                                                                                  let dbCommandBuilder = CreateIDLookupDbCommandBuilder(idsByTable.Key, selectedColumns, idsByTable)
                                                                                                         select Tuple.Create(dbCommandBuilder, timestampReader);

            var loadCommand = new MultiObjectLoadCommand <Tuple <ObjectID, object> > (dbCommandBuildersAndReaders);

            return(DelegateBasedCommand.Create(
                       loadCommand,
                       lookupResults => lookupResults.Select(
                           result =>
            {
                Assertion.IsNotNull(
                    result.Item1,
                    "Because we included IDColumn into the projection and used it for the lookup, every row in the result set certainly has an ID.");
                return new ObjectLookupResult <object> (result.Item1, result.Item2);
            })));
        }
        public void Initialization()
        {
            var command = new MultiObjectLoadCommand <object> (
                new[]
            {
                Tuple.Create(_dbCommandBuilderMock1, _objectReaderStub1),
                Tuple.Create(_dbCommandBuilderMock2, _objectReaderStub2)
            });

            Assert.That(
                command.DbCommandBuildersAndReaders,
                Is.EqualTo(
                    new[]
            {
                Tuple.Create(_dbCommandBuilderMock1, _objectReaderStub1),
                Tuple.Create(_dbCommandBuilderMock2, _objectReaderStub2)
            }));
        }
Пример #5
0
        public virtual IStorageProviderCommand <IEnumerable <ObjectLookupResult <DataContainer> >, IRdbmsProviderCommandExecutionContext> CreateForSortedMultiIDLookup(
            IEnumerable <ObjectID> objectIDs)
        {
            ArgumentUtility.CheckNotNull("objectIDs", objectIDs);

            var objectIDList = objectIDs.ToList();
            var dbCommandBuildersAndReaders =
                from id in objectIDList
                let tableDefinition = _tableDefinitionFinder.GetTableDefinition(id)
                                      group id by tableDefinition
                                      into idsByTable
                                      let selectedColumns = idsByTable.Key.GetAllColumns().ToArray()
                                                            let dataContainerReader = _objectReaderFactory.CreateDataContainerReader(idsByTable.Key, selectedColumns)
                                                                                      let dbCommandBuilder = CreateIDLookupDbCommandBuilder(idsByTable.Key, selectedColumns, idsByTable)
                                                                                                             select Tuple.Create(dbCommandBuilder, dataContainerReader);

            var loadCommand = new MultiObjectLoadCommand <DataContainer> (dbCommandBuildersAndReaders);

            return(new MultiDataContainerAssociateWithIDsCommand(objectIDList, loadCommand));
        }