public void CreateForRelationLookup_TableDefinition_NoSortExpression()
        {
            var classDefinition            = ClassDefinitionObjectMother.CreateClassDefinitionWithTable(classType: typeof(Order), storageProviderDefinition: TestDomainStorageProviderDefinition);
            var relationEndPointDefinition = CreateForeignKeyEndPointDefinition(classDefinition);
            var oppositeTable = (TableDefinition)relationEndPointDefinition.ClassDefinition.StorageEntityDefinition;

            _foreignKeyStoragePropertyDefinitionStrictMock.Expect(mock => mock.SplitValueForComparison(_foreignKeyValue)).Return(_fakeComparedColumns);
            _foreignKeyStoragePropertyDefinitionStrictMock.Replay();

            var expectedSelectedColumns = _tableDefinition.GetAllColumns();

            _dbCommandBuilderFactoryStrictMock
            .Expect(
                stub => stub.CreateForSelect(
                    Arg.Is((TableDefinition)classDefinition.StorageEntityDefinition),
                    Arg <IEnumerable <ColumnDefinition> > .List.Equal(expectedSelectedColumns),
                    Arg.Is(_fakeComparedColumns),
                    Arg <IEnumerable <OrderedColumn> > .List.Equal(new OrderedColumn[0])))
            .Return(_dbCommandBuilderStub);
            _dbCommandBuilderFactoryStrictMock.Replay();

            _objectReaderFactoryStrictMock
            .Expect(
                mock => mock.CreateDataContainerReader(
                    Arg.Is((IRdbmsStorageEntityDefinition)oppositeTable),
                    Arg <IEnumerable <ColumnDefinition> > .List.Equal(expectedSelectedColumns)))
            .Return(_dataContainerReaderStub);
            _objectReaderFactoryStrictMock.Replay();

            var result = _factory.CreateForRelationLookup(relationEndPointDefinition, _foreignKeyValue, null);

            _objectReaderFactoryStrictMock.VerifyAllExpectations();
            _foreignKeyStoragePropertyDefinitionStrictMock.VerifyAllExpectations();
            _dbCommandBuilderFactoryStrictMock.VerifyAllExpectations();

            Assert.That(result, Is.TypeOf(typeof(MultiObjectLoadCommand <DataContainer>)));
            var dbCommandBuilderTuples = ((MultiObjectLoadCommand <DataContainer>)result).DbCommandBuildersAndReaders;

            Assert.That(dbCommandBuilderTuples.Length, Is.EqualTo(1));
            Assert.That(dbCommandBuilderTuples[0].Item1, Is.SameAs(_dbCommandBuilderStub));
            Assert.That(dbCommandBuilderTuples[0].Item2, Is.SameAs(_dataContainerReaderStub));
        }
Beispiel #2
0
        public void CreateForScalarQuery()
        {
            _dataStoragePropertyDefinitionFactoryStrictMock
            .Expect(mock => mock.CreateStoragePropertyDefinition(DomainObjectIDs.Order1))
            .Return(_property1);
            _dataStoragePropertyDefinitionFactoryStrictMock
            .Expect(mock => mock.CreateStoragePropertyDefinition(DomainObjectIDs.Order3.Value))
            .Return(_property2);
            _dataStoragePropertyDefinitionFactoryStrictMock
            .Expect(mock => mock.CreateStoragePropertyDefinition(DomainObjectIDs.Official1))
            .Return(_property3);
            _dataStoragePropertyDefinitionFactoryStrictMock.Replay();

            var commandBuilderStub         = MockRepository.GenerateStub <IDbCommandBuilder> ();
            var expectedParametersWithType =
                new[]
            {
                new QueryParameterWithType(
                    new QueryParameter(_queryParameter1.Name, DomainObjectIDs.Order1.Value, _queryParameter1.ParameterType),
                    StoragePropertyDefinitionTestHelper.GetIDColumnDefinition(_property1).StorageTypeInfo),
                new QueryParameterWithType(_queryParameter2, _property2.ColumnDefinition.StorageTypeInfo),
                new QueryParameterWithType(
                    new QueryParameter(_queryParameter3.Name, DomainObjectIDs.Official1.ToString(), _queryParameter3.ParameterType),
                    StoragePropertyDefinitionTestHelper.GetSingleColumn(_property3.SerializedIDProperty).StorageTypeInfo)
            };

            _dbCommandBuilderFactoryStrictMock
            .Expect(
                stub => stub.CreateForQuery(Arg.Is("statement"), Arg <IEnumerable <QueryParameterWithType> > .List.Equal(expectedParametersWithType)))
            .Return(commandBuilderStub);
            _dbCommandBuilderFactoryStrictMock.Replay();

            var result = _factory.CreateForScalarQuery(_queryStub);

            _dataStoragePropertyDefinitionFactoryStrictMock.VerifyAllExpectations();
            _dbCommandBuilderFactoryStrictMock.VerifyAllExpectations();

            Assert.That(result, Is.TypeOf(typeof(ScalarValueLoadCommand)));
            var command = ((ScalarValueLoadCommand)result);

            Assert.That(command.DbCommandBuilder, Is.SameAs(commandBuilderStub));
        }
        public void CreateForSortedMultiIDLookup_TableDefinition_MultipleIDLookup_AndMultipleTables()
        {
            var expectedSelectedColumns1 = _tableDefinition1.GetAllColumns();
            var expectedComparedColumns1 = new ColumnValueTable(
                new[] { StoragePropertyDefinitionTestHelper.GetIDColumnDefinition(_tableDefinition1.ObjectIDProperty) },
                new[]
            {
                new ColumnValueTable.Row(new[] { _objectID1.Value }),
                new ColumnValueTable.Row(new[] { _objectID2.Value }),
            });

            _dbCommandBuilderFactoryStrictMock
            .Expect(
                stub => stub.CreateForSelect(
                    Arg.Is(_tableDefinition1),
                    Arg <IEnumerable <ColumnDefinition> > .List.Equal(expectedSelectedColumns1),
                    Arg <ColumnValueTable> .Matches(t => ColumnValueTableTestHelper.AreEqual(expectedComparedColumns1, t)),
                    Arg <IEnumerable <OrderedColumn> > .List.Equal(new OrderedColumn[0])))
            .Return(_dbCommandBuilder1Stub);

            var expectedSelectedColumns2 = _tableDefinition2.GetAllColumns();
            var expectedComparedColumns2 =
                new[] { new ColumnValue(StoragePropertyDefinitionTestHelper.GetIDColumnDefinition(_tableDefinition2.ObjectIDProperty), _objectID3.Value) };

            _dbCommandBuilderFactoryStrictMock
            .Expect(
                stub => stub.CreateForSelect(
                    Arg.Is(_tableDefinition2),
                    Arg <IEnumerable <ColumnDefinition> > .List.Equal(_tableDefinition2.GetAllColumns()),
                    Arg <IEnumerable <ColumnValue> > .List.Equal(expectedComparedColumns2),
                    Arg <IEnumerable <OrderedColumn> > .List.Equal(new OrderedColumn[0])))
            .Return(_dbCommandBuilder2Stub);

            _dbCommandBuilderFactoryStrictMock.Replay();

            _objectReaderFactoryStrictMock
            .Expect(
                mock => mock.CreateDataContainerReader(
                    Arg.Is((IRdbmsStorageEntityDefinition)_tableDefinition1),
                    Arg <IEnumerable <ColumnDefinition> > .List.Equal(expectedSelectedColumns1)))
            .Return(_dataContainerReader1Stub);
            _objectReaderFactoryStrictMock
            .Expect(
                mock => mock.CreateDataContainerReader(
                    Arg.Is((IRdbmsStorageEntityDefinition)_tableDefinition2),
                    Arg <IEnumerable <ColumnDefinition> > .List.Equal(expectedSelectedColumns2)))
            .Return(_dataContainerReader2Stub);
            _objectReaderFactoryStrictMock.Replay();

            var result = _factory.CreateForSortedMultiIDLookup(new[] { _objectID1, _objectID2, _objectID3 });

            _objectReaderFactoryStrictMock.VerifyAllExpectations();
            _dbCommandBuilderFactoryStrictMock.VerifyAllExpectations();
            Assert.That(result, Is.TypeOf(typeof(MultiDataContainerAssociateWithIDsCommand)));
            Assert.That(((MultiDataContainerAssociateWithIDsCommand)result).Command, Is.TypeOf(typeof(MultiObjectLoadCommand <DataContainer>)));

            var dbCommandBuilderTuples =
                ((MultiObjectLoadCommand <DataContainer>)((MultiDataContainerAssociateWithIDsCommand)result).Command).DbCommandBuildersAndReaders;

            Assert.That(dbCommandBuilderTuples.Length, Is.EqualTo(2));

            // Convert to Dictionary because the order of tuples is not defined
            var dbCommandBuilderDictionary = dbCommandBuilderTuples.ToDictionary(tuple => tuple.Item1, tuple => tuple.Item2);

            Assert.That(dbCommandBuilderDictionary.ContainsKey(_dbCommandBuilder1Stub), Is.True);
            Assert.That(dbCommandBuilderDictionary[_dbCommandBuilder1Stub], Is.SameAs(_dataContainerReader1Stub));
            Assert.That(dbCommandBuilderDictionary.ContainsKey(_dbCommandBuilder2Stub), Is.True);
            Assert.That(dbCommandBuilderDictionary[_dbCommandBuilder2Stub], Is.SameAs(_dataContainerReader2Stub));
        }