public void CreateForeignKeyConstraints()
        {
            var orderClassDefinition   = Configuration.GetTypeDefinition(typeof(Order));
            var customerClassDefintion = Configuration.GetTypeDefinition(typeof(Customer));

            _infrastructureStoragePropertyDefintionProviderMock
            .Expect(mock => mock.GetObjectIDStoragePropertyDefinition())
            .Return(_fakeObjectIDStoragePropertyDefinition);
            _infrastructureStoragePropertyDefintionProviderMock.Replay();

            var customerProperty        = orderClassDefinition.MyPropertyDefinitions["Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer"];
            var expectedComparedColumns = ((IRdbmsStoragePropertyDefinition)customerProperty.StoragePropertyDefinition).GetColumnsForComparison();

            _storageNameProviderMock
            .Expect(mock => mock.GetForeignKeyConstraintName(
                        Arg.Is(orderClassDefinition),
                        Arg <IEnumerable <ColumnDefinition> > .List.Equal(expectedComparedColumns)))
            .Return("FakeConstraintName");
            _storageNameProviderMock
            .Expect(mock => mock.GetTableName(customerClassDefintion))
            .Return(new EntityNameDefinition(null, "FakeTableName"));
            _storageNameProviderMock.Replay();

            var foreignKeyConstraintDefinitions = _factory.CreateForeignKeyConstraints(orderClassDefinition).ToArray();

            _infrastructureStoragePropertyDefintionProviderMock.VerifyAllExpectations();
            _storageNameProviderMock.VerifyAllExpectations();

            //OrderItem and OrderTicket endpoints are virtual and Official endpoint has different storage provider
            Assert.That(foreignKeyConstraintDefinitions.Length, Is.EqualTo(1));
            var foreignKeyConstraint = foreignKeyConstraintDefinitions[0];

            Assert.That(foreignKeyConstraint.ReferencedTableName.EntityName, Is.EqualTo("FakeTableName"));
            Assert.That(foreignKeyConstraint.ReferencedTableName.SchemaName, Is.Null);
            Assert.That(foreignKeyConstraint.ConstraintName, Is.EqualTo("FakeConstraintName"));
            Assert.That(foreignKeyConstraint.ReferencingColumns, Is.EqualTo(expectedComparedColumns));
            Assert.That(foreignKeyConstraint.ReferencedColumns, Is.EqualTo(_fakeObjectIDStoragePropertyDefinition.GetColumnsForComparison()));
        }
Пример #2
0
        public void CreateTableDefinition_WithoutPrimaryKey()
        {
            _storagePropertyDefinitionResolverMock
            .Expect(mock => mock.GetStoragePropertiesForHierarchy(_testModel.TableClassDefinition1))
            .Return(new IRdbmsStoragePropertyDefinition[0]);
            _storagePropertyDefinitionResolverMock.Replay();

            _foreignKeyConstraintDefinitionFactoryMock
            .Expect(mock => mock.CreateForeignKeyConstraints(_testModel.TableClassDefinition1))
            .Return(new ForeignKeyConstraintDefinition[0]);
            _foreignKeyConstraintDefinitionFactoryMock.Replay();

            _storageNameProviderMock
            .Expect(mock => mock.GetTableName(_testModel.TableClassDefinition1))
            .Return(new EntityNameDefinition(null, "FakeTableName"));
            _storageNameProviderMock
            .Expect(mock => mock.GetViewName(_testModel.TableClassDefinition1))
            .Return(new EntityNameDefinition(null, "FakeViewName"));
            _storageNameProviderMock.Replay();

            // no primary key columns!
            _infrastructureStoragePropertyDefinitionProviderMock
            .Expect(mock => mock.GetObjectIDStoragePropertyDefinition())
            .Return(new ObjectIDStoragePropertyDefinition(
                        SimpleStoragePropertyDefinitionObjectMother.CreateStorageProperty(),
                        SimpleStoragePropertyDefinitionObjectMother.CreateStorageProperty()));
            _infrastructureStoragePropertyDefinitionProviderMock
            .Expect(mock => mock.GetTimestampStoragePropertyDefinition())
            .Return(_fakeTimestampStorageProperty);

            _infrastructureStoragePropertyDefinitionProviderMock.Replay();

            var result = _factory.CreateTableDefinition(_testModel.TableClassDefinition1);

            Assert.That(result, Is.TypeOf <TableDefinition>().With.Property("Constraints").Empty);
        }