Example #1
0
        public void Create_DefaultSchema_WithOrderings()
        {
            var tableDefinition = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table"));
            var builder         = new SelectDbCommandBuilder(
                tableDefinition,
                _selectedColumnsStub,
                _comparedColumnsStrictMock,
                _orderedColumnsStub,
                _sqlDialectStub);

            _sqlDialectStub.Stub(stub => stub.DelimitIdentifier("Table")).Return("[delimited Table]");

            _comparedColumnsStrictMock.Expect(stub => stub.AddParameters(_dbCommandStub, _sqlDialectStub));
            _comparedColumnsStrictMock
            .Expect(
                stub => stub.AppendComparisons(
                    Arg <StringBuilder> .Is.Anything,
                    Arg.Is(_dbCommandStub),
                    Arg.Is(_sqlDialectStub)))
            .WhenCalled(mi => ((StringBuilder)mi.Arguments[0]).Append("[ID] = @ID"));
            _comparedColumnsStrictMock.Replay();

            _orderedColumnsStub.Stub(stub => stub.IsEmpty).Return(false);
            _orderedColumnsStub
            .Stub(stub => stub.AppendOrderings(Arg <StringBuilder> .Is.Anything, Arg.Is(_sqlDialectStub)))
            .WhenCalled(mi => ((StringBuilder)mi.Arguments[0]).Append("[Name] ASC, [City] DESC"));

            var result = builder.Create(_commandExecutionContextStub);

            _comparedColumnsStrictMock.VerifyAllExpectations();
            Assert.That(
                result.CommandText,
                Is.EqualTo(
                    "SELECT [Column1], [Column2], [Column3] FROM [delimited Table] WHERE [ID] = @ID ORDER BY [Name] ASC, [City] DESC;"));
        }
Example #2
0
        public override void SetUp()
        {
            base.SetUp();

            _factoryStub = MockRepository.GenerateStub <IForeignKeyConstraintScriptElementFactory>();

            _builder = new ForeignKeyConstraintScriptBuilder(_factoryStub, new SqlCommentScriptElementFactory());

            _tableName   = new EntityNameDefinition(null, "Table");
            _constraint1 = new ForeignKeyConstraintDefinition("FK1", _tableName, new ColumnDefinition[0], new ColumnDefinition[0]);
            _constraint2 = new ForeignKeyConstraintDefinition("FK2", _tableName, new ColumnDefinition[0], new ColumnDefinition[0]);
            _constraint3 = new ForeignKeyConstraintDefinition("FK3", _tableName, new ColumnDefinition[0], new ColumnDefinition[0]);

            _tableDefinition1 = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                _tableName,
                null,
                new[] { _constraint1 });
            _tableDefinition2 = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                _tableName,
                null,
                new[] { _constraint2, _constraint3 });

            _fakeElement1 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement2 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement3 = MockRepository.GenerateStub <IScriptElement>();
        }
Example #3
0
        public void ResoveIDProperty()
        {
            var entityExpression = CreateEntityDefinition(typeof(Order), "o");
            var entityDefinition = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Test"));

            _rdbmsPersistenceModelProviderStub
            .Stub(stub => stub.GetEntityDefinition(_classDefinition))
            .Return(entityDefinition);

            var result = _storageSpecificExpressionResolver.ResolveIDProperty(entityExpression, _classDefinition);

            var ctor = MemberInfoFromExpressionUtility.GetConstructor(() => new ObjectID("ClassID", "value"));

            SqlExpressionTreeComparer.CheckAreEqualTrees(
                Expression.New(
                    ctor,
                    new[]
            {
                new NamedExpression("ClassID", new SqlColumnDefinitionExpression(typeof(string), "o", "ClassID", false)),
                new NamedExpression("Value", Expression.Convert(new SqlColumnDefinitionExpression(typeof(Guid), "o", "ID", true), typeof(object)))
            },
                    new[]
            {
                typeof(ObjectID).GetProperty("ClassID"),
                typeof(ObjectID).GetProperty("Value")
            }),
                result);
        }
        public override void SetUp()
        {
            base.SetUp();

            _rdbmsPersistenceModelProvider = new RdbmsPersistenceModelProvider();

            _dbCommandBuilderFactoryStrictMock = MockRepository.GenerateStrictMock <IDbCommandBuilderFactory>();
            _objectReaderFactoryStrictMock     = MockRepository.GenerateStrictMock <IObjectReaderFactory>();
            _dbCommandBuilderStub              = MockRepository.GenerateStub <IDbCommandBuilder> ();
            _dataContainerReaderStub           = MockRepository.GenerateStub <IObjectReader <DataContainer> > ();
            _objectIDReaderStub                = MockRepository.GenerateStub <IObjectReader <ObjectID> > ();
            _fakeStorageProviderCommandFactory = MockRepository.GenerateStub <IStorageProviderCommandFactory <IRdbmsProviderCommandExecutionContext> >();

            _factory = new RelationLookupCommandFactory(
                _fakeStorageProviderCommandFactory,
                _dbCommandBuilderFactoryStrictMock,
                _rdbmsPersistenceModelProvider,
                _objectReaderFactoryStrictMock);

            _tableDefinition     = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table1"));
            _unionViewDefinition = UnionViewDefinitionObjectMother.Create(
                TestDomainStorageProviderDefinition,
                new EntityNameDefinition(null, "ViewName"),
                _tableDefinition);

            _foreignKeyValue = CreateObjectID(_tableDefinition);
            _foreignKeyStoragePropertyDefinitionStrictMock = MockRepository.GenerateStrictMock <IRdbmsStoragePropertyDefinition>();

            _fakeComparedColumns = new[] { new ColumnValue(ColumnDefinitionObjectMother.IDColumn, _foreignKeyValue.Value) };
        }
        public override void SetUp()
        {
            base.SetUp();

            _tableDefinitionFinder = new TableDefinitionFinder(new RdbmsPersistenceModelProvider());

            _dbCommandBuilderFactoryStrictMock = MockRepository.GenerateStrictMock <IDbCommandBuilderFactory>();
            _objectReaderFactoryStrictMock     = MockRepository.GenerateStrictMock <IObjectReaderFactory>();
            _dbCommandBuilder1Stub             = MockRepository.GenerateStub <IDbCommandBuilder>();
            _dbCommandBuilder2Stub             = MockRepository.GenerateStub <IDbCommandBuilder>();
            _timestampReader1Stub     = MockRepository.GenerateStub <IObjectReader <Tuple <ObjectID, object> > > ();
            _timestampReader2Stub     = MockRepository.GenerateStub <IObjectReader <Tuple <ObjectID, object> > > ();
            _dataContainerReader1Stub = MockRepository.GenerateStub <IObjectReader <DataContainer> > ();
            _dataContainerReader2Stub = MockRepository.GenerateStub <IObjectReader <DataContainer> > ();

            _factory = new LookupCommandFactory(
                TestDomainStorageProviderDefinition,
                _dbCommandBuilderFactoryStrictMock,
                _objectReaderFactoryStrictMock,
                _tableDefinitionFinder);

            _tableDefinition1 = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition);
            _tableDefinition2 = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition);

            _objectID1 = CreateObjectID(_tableDefinition1);
            _objectID2 = CreateObjectID(_tableDefinition1);
            _objectID3 = CreateObjectID(_tableDefinition2);
        }
        public void Create_WithCustomSchema()
        {
            var tableDefinition = TableDefinitionObjectMother.Create(
                TestDomainStorageProviderDefinition, new EntityNameDefinition("customSchema", "Table"));
            var builder = new DeleteDbCommandBuilder(
                tableDefinition,
                _comparedColumnsSpecificationStrictMock,
                _sqlDialectStub);

            _sqlDialectStub.Expect(mock => mock.DelimitIdentifier("Table")).Return("[delimited Table]");
            _sqlDialectStub.Expect(mock => mock.DelimitIdentifier("customSchema")).Return("[delimited customSchema]");

            _comparedColumnsSpecificationStrictMock.Expect(stub => stub.AddParameters(_dbCommandStub, _sqlDialectStub));
            _comparedColumnsSpecificationStrictMock
            .Expect(
                stub => stub.AppendComparisons(
                    Arg <StringBuilder> .Is.Anything,
                    Arg.Is(_dbCommandStub),
                    Arg.Is(_sqlDialectStub)))
            .WhenCalled(mi => ((StringBuilder)mi.Arguments[0]).Append("[ID] = @ID"));
            _comparedColumnsSpecificationStrictMock.Replay();

            var result = builder.Create(_commandExecutionContextStub);

            _comparedColumnsSpecificationStrictMock.VerifyAllExpectations();
            Assert.That(result.CommandText, Is.EqualTo("DELETE FROM [delimited customSchema].[delimited Table] WHERE [ID] = @ID;"));
        }
        public void PersistenceModelIsLoaded()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Order), baseClass: null);

            classDefinition.SetRelationEndPointDefinitions(new RelationEndPointDefinitionCollection());
            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection());
            classDefinition.SetDerivedClasses(new ClassDefinition[0]);

            StubMockMappingLoader(new[] { classDefinition }, new RelationDefinition[0]);

            var persistenceModelLoaderMock = MockRepository.GenerateStrictMock <IPersistenceModelLoader>();

            persistenceModelLoaderMock
            .Expect(mock => mock.ApplyPersistenceModelToHierarchy(classDefinition))
            .WhenCalled(mi => classDefinition.SetStorageEntity(TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition)));
            persistenceModelLoaderMock
            .Expect(mock => mock.CreatePersistenceMappingValidator(classDefinition))
            .Return(new PersistenceMappingValidator());
            persistenceModelLoaderMock.Replay();

            _mockRepository.ReplayAll();

            new MappingConfiguration(_mockMappingLoader, persistenceModelLoaderMock);

            persistenceModelLoaderMock.VerifyAllExpectations();
        }
Example #8
0
        public override void SetUp()
        {
            base.SetUp();

            _factory = new SqlFilterViewScriptElementFactory();

            var tableDefinitionWithCustomSchema = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition("SchemaName", "TableName1"));
            var tableDefinitionWithDefaultSchema = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition(null, "TableName2"));

            var property1 = SimpleStoragePropertyDefinitionObjectMother.CreateStorageProperty("Column1");
            var property2 = SimpleStoragePropertyDefinitionObjectMother.CreateStorageProperty("Column2");

            _filterViewDefinitionWithCustomSchema = FilterViewDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition("SchemaName", "FilterView1"),
                tableDefinitionWithCustomSchema,
                new[] { "ClassID1" },
                ObjectIDStoragePropertyDefinitionObjectMother.ObjectIDProperty,
                SimpleStoragePropertyDefinitionObjectMother.TimestampProperty,
                new[] { property1 });
            _filterViewDefinitionWithDefaultSchema = FilterViewDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition(null, "FilterView2"),
                tableDefinitionWithDefaultSchema,
                new[] { "ClassID1", "ClassID2" },
                ObjectIDStoragePropertyDefinitionObjectMother.ObjectIDProperty,
                SimpleStoragePropertyDefinitionObjectMother.TimestampProperty,
                new[] { property1, property2 });
        }
        public override void SetUp()
        {
            base.SetUp();

            _tableViewElementFactoryStub  = MockRepository.GenerateStub <IViewScriptElementFactory <TableDefinition> >();
            _unionViewElementFactoryStub  = MockRepository.GenerateStub <IViewScriptElementFactory <UnionViewDefinition> >();
            _filterViewElementFactoryStub = MockRepository.GenerateStub <IViewScriptElementFactory <FilterViewDefinition> >();
            _emptyViewElementFactoryStub  = MockRepository.GenerateStub <IViewScriptElementFactory <EmptyViewDefinition> >();

            _builder = new ViewScriptBuilder(
                _tableViewElementFactoryStub,
                _unionViewElementFactoryStub,
                _filterViewElementFactoryStub,
                _emptyViewElementFactoryStub,
                new SqlCommentScriptElementFactory());

            _tableDefinition1      = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _tableDefinition2      = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _unionViewDefinition1  = UnionViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _unionViewDefinition2  = UnionViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _filterViewDefinition1 = FilterViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _filterViewDefinition2 = FilterViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _emptyViewDefinition1  = EmptyViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _emptyViewDefinition2  = EmptyViewDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);

            _fakeElement1 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement2 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement3 = MockRepository.GenerateStub <IScriptElement>();
        }
        public void AdjustForTable()
        {
            var instance = AllSelectedColumnsSpecification.Instance;

            Assert.That(
                () => instance.AdjustForTable(TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition)),
                Throws.TypeOf <NotSupportedException>());
        }
Example #11
0
        public override void SetUp()
        {
            base.SetUp();

            _rdbmsPersistenceModelProviderStub = MockRepository.GenerateStub <IRdbmsPersistenceModelProvider>();
            _finder = new TableDefinitionFinder(_rdbmsPersistenceModelProviderStub);

            _tableDefinition = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table"));
        }
        public void SetUp()
        {
            _validationRule          = new ClassAboveTableIsAbstractValidationRule();
            _abstractClassDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(DerivedValidationDomainObjectClass), isAbstract: true);
            _concreteClassDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(DerivedValidationDomainObjectClass), isAbstract: false);
            var storageProviderDefinition = new UnitTestStorageProviderStubDefinition("DefaultStorageProvider");

            _tableDefinition     = TableDefinitionObjectMother.Create(storageProviderDefinition, new EntityNameDefinition(null, "TableName"));
            _unionViewDefinition = UnionViewDefinitionObjectMother.Create(storageProviderDefinition);
            _emptyViewDefinition = EmptyViewDefinitionObjectMother.Create(storageProviderDefinition);
        }
Example #13
0
        public void AdjustForTable()
        {
            var table = TableDefinitionObjectMother.Create(
                TestDomainStorageProviderDefinition,
                new[] { new SimpleStoragePropertyDefinition(typeof(int), _column1) });

            var result = _specification.AdjustForTable(table);

            Assert.That(result, Is.TypeOf <SelectedColumnsSpecification>());
            Assert.That(((SelectedColumnsSpecification)result).SelectedColumns, Is.EqualTo(new[] { _column1, null, null }));
        }
        private IPersistenceModelLoader CreatePersistenceModelLoaderStub()
        {
            var persistenceModelLoaderStub = _mockRepository.Stub <IPersistenceModelLoader>();

            persistenceModelLoaderStub
            .Stub(stub => stub.ApplyPersistenceModelToHierarchy(Arg <ClassDefinition> .Is.Anything))
            .WhenCalled(
                mi => ((ClassDefinition)mi.Arguments[0]).SetStorageEntity(TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition)));
            persistenceModelLoaderStub
            .Stub(stub => stub.CreatePersistenceMappingValidator(Arg <ClassDefinition> .Is.Anything))
            .Return(new PersistenceMappingValidator());
            return(persistenceModelLoaderStub);
        }
        public override void SetUp()
        {
            base.SetUp();

            _emptyClassDefinitions    = new ClassDefinition[0];
            _emptyRelationDefinitions = new RelationDefinition[0];

            _memberInformationNameResolver = new ReflectionBasedMemberInformationNameResolver();
            _mockRepository    = new MockRepository();
            _mockMappingLoader = _mockRepository.StrictMock <IMappingLoader>();

            _fakeStorageEntityDefinition = TableDefinitionObjectMother.Create(
                DomainObjectsConfiguration.Current.Storage.DefaultStorageProviderDefinition, new EntityNameDefinition(null, "Test"));
        }
        public override void SetUp()
        {
            base.SetUp();

            _tableScriptfactoryStub = MockRepository.GenerateStub <ITableScriptElementFactory>();
            _builder = new TableScriptBuilder(_tableScriptfactoryStub, new SqlCommentScriptElementFactory());

            _tableDefinition1 = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _tableDefinition2 = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);
            _tableDefinition3 = TableDefinitionObjectMother.Create(SchemaGenerationFirstStorageProviderDefinition);

            _fakeElement1 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement2 = MockRepository.GenerateStub <IScriptElement>();
            _fakeElement3 = MockRepository.GenerateStub <IScriptElement>();
        }
        public static ClassDefinition CreateClassDefinitionWithTable(
            StorageProviderDefinition storageProviderDefinition,
            string id                 = null,
            Type classType            = null,
            bool isAbstract           = false,
            ClassDefinition baseClass = null,
            Type storageGroupType     = null,
            IPersistentMixinFinder persistentMixinFinder = null,
            IDomainObjectCreator instanceCreator         = null)
        {
            var classDefinition = CreateClassDefinition(id, classType, isAbstract, baseClass, storageGroupType, persistentMixinFinder, instanceCreator);

            classDefinition.SetStorageEntity(TableDefinitionObjectMother.Create(storageProviderDefinition));
            return(classDefinition);
        }
        public override void SetUp()
        {
            base.SetUp();

            _tableDefinition      = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition);
            _filterViewDefinition = FilterViewDefinitionObjectMother.Create(
                TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "FilterView"), _tableDefinition);
            _unionViewDefinition = UnionViewDefinitionObjectMother.Create(
                TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "UnionView"), new[] { _tableDefinition });
            _emptyViewDefinition = EmptyViewDefinitionObjectMother.Create(TestDomainStorageProviderDefinition);

            _mockRepository      = new MockRepository();
            _voidReceiverMock    = _mockRepository.StrictMock <IVisitorCallReceiver> ();
            _nonVoidReceiverMock = _mockRepository.StrictMock <IVisitorCallReceiver <string> > ();
        }
        public override void SetUp()
        {
            base.SetUp();

            _dbCommandBuilderFactoryStrictMock = MockRepository.GenerateStrictMock <IDbCommandBuilderFactory>();
            _rdbmsPersistenceModelProvider     = new RdbmsPersistenceModelProvider();
            _tableDefinitionFinderStrictMock   = MockRepository.GenerateStrictMock <ITableDefinitionFinder>();

            _factory = new SaveCommandFactory(
                _dbCommandBuilderFactoryStrictMock,
                _rdbmsPersistenceModelProvider,
                _tableDefinitionFinderStrictMock);

            _tableDefinition1 = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table1"));
        }
Example #20
0
        public override void SetUp()
        {
            base.SetUp();

            _sqlDialectStub = MockRepository.GenerateStub <ISqlDialect>();
            _factory        = new SqlDbCommandBuilderFactory(_sqlDialectStub);

            _tableDefinition = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table"));

            _column1      = ColumnDefinitionObjectMother.CreateColumn("Column1");
            _column2      = ColumnDefinitionObjectMother.CreateColumn("Column2");
            _columnValue1 = new ColumnValue(_column1, new object());
            _columnValue2 = new ColumnValue(_column2, new object());

            _orderColumn1 = new OrderedColumn(_column1, SortOrder.Ascending);
            _orderColumn2 = new OrderedColumn(_column2, SortOrder.Descending);
        }
Example #21
0
        public override void SetUp()
        {
            base.SetUp();

            _rdbmsPersistenceModelProviderStub  = MockRepository.GenerateStub <IRdbmsPersistenceModelProvider>();
            _rdbmsStoragePropertyDefinitionStub = MockRepository.GenerateStub <IRdbmsStoragePropertyDefinition>();

            _storageSpecificExpressionResolver = new StorageSpecificExpressionResolver(
                _rdbmsPersistenceModelProviderStub);

            _classDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Order));
            _classDefinition.SetStorageEntity(
                TableDefinitionObjectMother.Create(
                    TestDomainStorageProviderDefinition,
                    new EntityNameDefinition(null, "Order"),
                    new EntityNameDefinition(null, "OrderView")));
        }
Example #22
0
        public override void SetUp()
        {
            base.SetUp();

            _factory = new SqlTableScriptElementFactory();

            var column1   = new ColumnDefinition("Column1", StorageTypeInformationObjectMother.CreateVarchar100StorageTypeInformation(false), false);
            var column2   = new ColumnDefinition("Column2", StorageTypeInformationObjectMother.CreateBitStorageTypeInformation(true), false);
            var property1 = new SimpleStoragePropertyDefinition(typeof(string), column1);
            var property2 = new SimpleStoragePropertyDefinition(typeof(bool), column2);

            var idColumn         = new ColumnDefinition("ID", StorageTypeInformationObjectMother.CreateUniqueIdentifierStorageTypeInformation(false), true);
            var classIDColumn    = new ColumnDefinition("ClassID", StorageTypeInformationObjectMother.CreateVarchar100StorageTypeInformation(true), false);
            var objectIDProperty = new ObjectIDStoragePropertyDefinition(
                new SimpleStoragePropertyDefinition(typeof(object), idColumn),
                new SimpleStoragePropertyDefinition(typeof(string), classIDColumn));
            var timestampColumn   = new ColumnDefinition("Timestamp", StorageTypeInformationObjectMother.CreateDateTimeStorageTypeInformation(true), false);
            var timestampProperty = new SimpleStoragePropertyDefinition(typeof(object), timestampColumn);

            _tableDefinitionWithoutPrimaryKeyConstraint = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition("SchemaName", "EntityName"),
                null,
                objectIDProperty,
                timestampProperty,
                property1);

            _tableDefinitionWithClusteredPrimaryKeyConstraint = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition("SchemaName", "EntityName"),
                null,
                objectIDProperty,
                timestampProperty,
                new[] { property1, property2 },
                new ITableConstraintDefinition[] { new PrimaryKeyConstraintDefinition("PKName", true, new[] { column1 }) });

            _tableDefinitionWithNonClusteredPrimaryKeyConstraint = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition(null, "EntityName"),
                null,
                objectIDProperty,
                timestampProperty,
                new[] { property1, property2 },
                new ITableConstraintDefinition[] { new PrimaryKeyConstraintDefinition("PKName", false, new[] { column1, column2 }) });
        }
Example #23
0
        public void ResolveJoin_LeftSideHoldsForeignKey()
        {
            // Order.Customer
            var propertyDefinition = CreatePropertyDefinitionAndAssociateWithClass(_classDefinition, "Customer", "Customer");

            var columnDefinition = ColumnDefinitionObjectMother.CreateGuidColumn("Customer");

            _rdbmsStoragePropertyDefinitionStub.Stub(stub => stub.GetColumnsForComparison()).Return(new[] { columnDefinition });
            _rdbmsStoragePropertyDefinitionStub.Stub(stub => stub.PropertyType).Return(typeof(ObjectID));

            var leftEndPointDefinition = new RelationEndPointDefinition(propertyDefinition, false);

            _rdbmsPersistenceModelProviderStub
            .Stub(stub => stub.GetStoragePropertyDefinition(leftEndPointDefinition.PropertyDefinition))
            .Return(_rdbmsStoragePropertyDefinitionStub);

            // Customer.Order
            var customerClassDefinition = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Customer));
            var customerTableDefinition = TableDefinitionObjectMother.Create(
                TestDomainStorageProviderDefinition,
                new EntityNameDefinition(null, "CustomerTable"),
                new EntityNameDefinition(null, "CustomerView"));

            _rdbmsPersistenceModelProviderStub
            .Stub(stub => stub.GetEntityDefinition(customerClassDefinition))
            .Return(customerTableDefinition);

            var rightEndPointDefinition = new AnonymousRelationEndPointDefinition(customerClassDefinition);

            var originatingEntity = CreateEntityDefinition(typeof(Order), "o");

            var result = _storageSpecificExpressionResolver.ResolveJoin(originatingEntity, leftEndPointDefinition, rightEndPointDefinition, "c");

            Assert.That(result, Is.Not.Null);
            Assert.That(result.ItemType, Is.EqualTo(typeof(Customer)));
            Assert.That(result.ForeignTableInfo, Is.TypeOf(typeof(ResolvedSimpleTableInfo)));
            Assert.That(((ResolvedSimpleTableInfo)result.ForeignTableInfo).TableName, Is.EqualTo("CustomerView"));
            Assert.That(((ResolvedSimpleTableInfo)result.ForeignTableInfo).TableAlias, Is.EqualTo("c"));

            var expected = Expression.Equal(
                new SqlColumnDefinitionExpression(typeof(Guid), "o", "Customer", false),
                new SqlColumnDefinitionExpression(typeof(Guid), "c", "ID", true));

            SqlExpressionTreeComparer.CheckAreEqualTrees(expected, result.JoinCondition);
        }
Example #24
0
        public void Create_DefaultSchema()
        {
            var tableDefinition = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table"));
            var builder         = new InsertDbCommandBuilder(tableDefinition, _insertedColumnsSpecificationStub, _sqlDialectStub);

            _sqlDialectStub.Stub(stub => stub.DelimitIdentifier("Table")).Return("[delimited Table]");

            _insertedColumnsSpecificationStub
            .Stub(stub => stub.AppendColumnNames(Arg <StringBuilder> .Is.Anything, Arg.Is(_dbCommandStub), Arg.Is(_sqlDialectStub)))
            .WhenCalled(mi => ((StringBuilder)mi.Arguments[0]).Append("[Column1], [Column2], [Column3]"));
            _insertedColumnsSpecificationStub
            .Stub(stub => stub.AppendColumnValues(Arg <StringBuilder> .Is.Anything, Arg.Is(_dbCommandStub), Arg.Is(_sqlDialectStub)))
            .WhenCalled(mi => ((StringBuilder)mi.Arguments[0]).Append("5, 'test', true"));

            var result = builder.Create(_commandExecutionContextStub);

            Assert.That(result.CommandText, Is.EqualTo("INSERT INTO [delimited Table] ([Column1], [Column2], [Column3]) VALUES (5, 'test', true);"));
        }
        public void SetUp()
        {
            _validationRule = new TableNamesAreDistinctWithinConcreteTableInheritanceHierarchyValidationRule();

            _baseOfBaseClass   = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(BaseOfBaseValidationDomainObjectClass));
            _derivedBaseClass1 = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(BaseValidationDomainObjectClass), baseClass: _baseOfBaseClass);
            _derivedClass      = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(DerivedValidationDomainObjectClass), baseClass: _derivedBaseClass1);

            _baseOfBaseClass.SetDerivedClasses(new[] { _derivedBaseClass1 });
            _derivedBaseClass1.SetDerivedClasses(new[] { _derivedClass });
            _derivedClass.SetDerivedClasses(new ClassDefinition[0]);

            var storageProviderDefinition = new UnitTestStorageProviderStubDefinition("DefaultStorageProvider");

            _tableDefinition1    = TableDefinitionObjectMother.Create(storageProviderDefinition, new EntityNameDefinition(null, "TableName1"));
            _tableDefinition2    = TableDefinitionObjectMother.Create(storageProviderDefinition, new EntityNameDefinition(null, "TableName2"));
            _unionViewDefinition = UnionViewDefinitionObjectMother.Create(storageProviderDefinition);
        }
Example #26
0
        public void ResolveTable_TableDefinitionWithSchemaName()
        {
            var tableDefinition = TableDefinitionObjectMother.Create(
                TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table"), new EntityNameDefinition("schemaName", "TableView"));

            _classDefinition.SetStorageEntity(tableDefinition);

            _rdbmsPersistenceModelProviderStub
            .Stub(stub => stub.GetEntityDefinition(_classDefinition))
            .Return(_classDefinition.StorageEntityDefinition as IRdbmsStorageEntityDefinition);

            var result = (ResolvedSimpleTableInfo)_storageSpecificExpressionResolver.ResolveTable(_classDefinition, "o");

            Assert.That(result, Is.Not.Null);
            Assert.That(result.TableName, Is.EqualTo("schemaName.TableView"));
            Assert.That(result.TableAlias, Is.EqualTo("o"));
            Assert.That(result.ItemType, Is.EqualTo(typeof(Order)));
        }
        public override void SetUp()
        {
            base.SetUp();

            _factory = new SqlTableViewScriptElementFactory();

            _tableDefinitionWithCustomSchema = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition("SchemaName", "Table1"),
                new EntityNameDefinition("SchemaName", "View1"),
                ObjectIDStoragePropertyDefinitionObjectMother.ObjectIDProperty,
                SimpleStoragePropertyDefinitionObjectMother.TimestampProperty,
                SimpleStoragePropertyDefinitionObjectMother.CreateStorageProperty("Column1"));
            _tableDefinitionWithDefaultSchema = TableDefinitionObjectMother.Create(
                SchemaGenerationFirstStorageProviderDefinition,
                new EntityNameDefinition(null, "Table2"),
                new EntityNameDefinition(null, "View2"),
                ObjectIDStoragePropertyDefinitionObjectMother.ObjectIDProperty,
                SimpleStoragePropertyDefinitionObjectMother.TimestampProperty,
                SimpleStoragePropertyDefinitionObjectMother.CreateStorageProperty("Column1"));
        }
Example #28
0
        public void ResolveEntity()
        {
            var objectIDProperty  = ObjectIDStoragePropertyDefinitionObjectMother.ObjectIDProperty;
            var timestampProperty = SimpleStoragePropertyDefinitionObjectMother.TimestampProperty;

            var foreignKeyProperty = SimpleStoragePropertyDefinitionObjectMother.CreateGuidStorageProperty("ForeignKey");
            var simpleProperty     = SimpleStoragePropertyDefinitionObjectMother.CreateStringStorageProperty("Column1");

            var tableDefinition = TableDefinitionObjectMother.Create(
                TestDomainStorageProviderDefinition,
                new EntityNameDefinition(null, "Test"),
                null,
                objectIDProperty,
                timestampProperty,
                foreignKeyProperty,
                simpleProperty);

            _rdbmsPersistenceModelProviderStub
            .Stub(stub => stub.GetEntityDefinition(_classDefinition))
            .Return(tableDefinition);

            var result = _storageSpecificExpressionResolver.ResolveEntity(_classDefinition, "o");

            var expectedIdColumn         = new SqlColumnDefinitionExpression(typeof(Guid), "o", "ID", true);
            var expectedClassIdColumn    = new SqlColumnDefinitionExpression(typeof(string), "o", "ClassID", false);
            var expectedTimestampColumn  = new SqlColumnDefinitionExpression(typeof(DateTime), "o", "Timestamp", false);
            var expectedForeignKeyColumn = new SqlColumnDefinitionExpression(typeof(Guid), "o", "ForeignKey", false);
            var expectedColumn           = new SqlColumnDefinitionExpression(typeof(string), "o", "Column1", false);

            Assert.That(result.Type, Is.SameAs(typeof(Order)));
            Assert.That(result.TableAlias, Is.EqualTo("o"));
            Assert.That(result.Name, Is.Null);
            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedIdColumn, result.GetIdentityExpression());
            Assert.That(result.Columns, Has.Count.EqualTo(5));
            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedIdColumn, result.Columns[0]);
            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedClassIdColumn, result.Columns[1]);
            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedTimestampColumn, result.Columns[2]);
            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedForeignKeyColumn, result.Columns[3]);
            SqlExpressionTreeComparer.CheckAreEqualTrees(expectedColumn, result.Columns[4]);
        }
Example #29
0
        public void CreateUnionViewDefinition()
        {
            var fakeUnionEntity1 = TableDefinitionObjectMother.Create(_storageProviderDefinition);
            var fakeUnionEntity2 = TableDefinitionObjectMother.Create(_storageProviderDefinition);

            _storagePropertyDefinitionResolverMock
            .Expect(mock => mock.GetStoragePropertiesForHierarchy(_testModel.BaseBaseClassDefinition))
            .Return(new[] { _fakeStorageProperty1 });
            _storagePropertyDefinitionResolverMock.Replay();

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

            MockStandardProperties();

            _infrastructureStoragePropertyDefinitionProviderMock.Replay();

            var result = _factory.CreateUnionViewDefinition(
                _testModel.BaseBaseClassDefinition, new IRdbmsStorageEntityDefinition[] { fakeUnionEntity1, fakeUnionEntity2 });

            _storagePropertyDefinitionResolverMock.VerifyAllExpectations();
            _infrastructureStoragePropertyDefinitionProviderMock.VerifyAllExpectations();
            _storageNameProviderMock.VerifyAllExpectations();
            CheckUnionViewDefinition(
                result,
                _storageProviderID,
                "FakeViewName",
                new[] { fakeUnionEntity1, fakeUnionEntity2 },
                new IRdbmsStoragePropertyDefinition[]
            {
                _fakeObjectIDStorageProperty,
                _fakeTimestampStorageProperty,
                _fakeStorageProperty1
            },
                new IIndexDefinition[0],
                new EntityNameDefinition[0]);
        }
        public override void SetUp()
        {
            base.SetUp();

            _originalSelectedColumnsStub = MockRepository.GenerateStub <ISelectedColumnsSpecification> ();
            _comparedColumnsStrictMock   = MockRepository.GenerateStrictMock <IComparedColumnsSpecification>();
            _fullSelectedColumnsStub     = MockRepository.GenerateStub <ISelectedColumnsSpecification> ();
            _orderedColumnsStub          = MockRepository.GenerateStub <IOrderedColumnsSpecification> ();

            _sqlDialectStub = MockRepository.GenerateStub <ISqlDialect>();
            _sqlDialectStub.Stub(stub => stub.StatementDelimiter).Return(";");

            _dbCommandStub = MockRepository.GenerateStub <IDbCommand>();

            _commandExecutionContextStub = MockRepository.GenerateStub <IRdbmsProviderCommandExecutionContext>();
            _commandExecutionContextStub.Stub(stub => stub.CreateDbCommand()).Return(_dbCommandStub);

            Guid.NewGuid();

            _table1 = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table1"));
            _table2 = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition(null, "Table2"));
            _table3 = TableDefinitionObjectMother.Create(TestDomainStorageProviderDefinition, new EntityNameDefinition("customSchema", "Table3"));
        }