public void Can_create_count_query_command_trees_when_sql_azure_execution_strategy() { ResetDatabase(); try { MutableResolver.AddResolver <Func <IDbExecutionStrategy> >( key => (Func <IDbExecutionStrategy>)(() => new SqlAzureExecutionStrategy())); var historyRepository = new HistoryRepository(Mock.Of <InternalContextForMock>(), ConnectionString, ProviderFactory, "MyKey", null, HistoryContext.DefaultFactory); var commandTrees = historyRepository.CreateDiscoveryQueryTrees(); foreach (var commandTree in commandTrees) { Assert.NotNull(commandTree); Assert.Equal(DataSpace.SSpace, commandTree.DataSpace); Assert.Equal(0, commandTree.Parameters.Count()); } } finally { MutableResolver.ClearResolvers(); } }
public void Can_create_count_query_command_tree() { ResetDatabase(); var historyRepository = new HistoryRepository(Mock.Of <InternalContextForMock>(), ConnectionString, ProviderFactory, "MyKey", null, HistoryContext.DefaultFactory); var commandTrees = historyRepository.CreateDiscoveryQueryTrees(); foreach (var commandTree in commandTrees) { Assert.NotNull(commandTree); Assert.Equal(DataSpace.SSpace, commandTree.DataSpace); Assert.Equal(0, commandTree.Parameters.Count()); } }
public void Generate_can_handle_update_database_operations() { var migrationSqlGenerator = new SqlCeMigrationSqlGenerator(); var providerInvariantName = ProviderRegistry.SqlCe4_ProviderInfo.ProviderInvariantName; var historyRepository = new HistoryRepository( new SqlCeConnectionFactory(providerInvariantName) .CreateConnection("Foo").ConnectionString, DbProviderFactories.GetFactory(providerInvariantName), "MyKey", null); var updateDatabaseOperation = new UpdateDatabaseOperation(historyRepository.CreateDiscoveryQueryTrees().ToList()); updateDatabaseOperation.AddMigration("M1", new []{ new DropColumnOperation("Customers", "Foo") }); var sql = migrationSqlGenerator.Generate(new[] { updateDatabaseOperation }, "2008").Join(s => s.Sql, Environment.NewLine); Assert.Equal(@"ALTER TABLE [Customers] DROP COLUMN [Foo]", sql); }
public void Generate_can_handle_update_database_operations() { var migrationSqlGenerator = new SqlServerMigrationSqlGenerator(); var historyRepository = new HistoryRepository( Mock.Of<InternalContextForMock>(), new SqlConnectionFactory().CreateConnection("Foo").ConnectionString, DbProviderFactories.GetFactory(ProviderRegistry.Sql2008_ProviderInfo.ProviderInvariantName), "MyKey", null, HistoryContext.DefaultFactory, schemas: new[] { "dbo", "foo", "bar" }); var updateDatabaseOperation = new UpdateDatabaseOperation(historyRepository.CreateDiscoveryQueryTrees().ToList()); updateDatabaseOperation.AddMigration( "V1", new MigrationOperation[] { new DropColumnOperation("Customers", "Foo"), new CreateProcedureOperation("Foo", "Bar") }); updateDatabaseOperation.AddMigration( "V2", new MigrationOperation[] { new AddColumnOperation("Customers", new ColumnModel(PrimitiveTypeKind.String) { Name = "C" }), new CreateProcedureOperation("bar", "baz") }); var sql = migrationSqlGenerator.Generate(new[] { updateDatabaseOperation }, "2008").Join(s => s.Sql, Environment.NewLine); Assert.Equal(@"DECLARE @CurrentMigration [nvarchar](max) IF object_id('[dbo].[__MigrationHistory]') IS NOT NULL SELECT @CurrentMigration = (SELECT TOP (1) [Project1].[MigrationId] AS [MigrationId] FROM ( SELECT [Extent1].[MigrationId] AS [MigrationId] FROM [dbo].[__MigrationHistory] AS [Extent1] WHERE [Extent1].[ContextKey] = N'MyKey' ) AS [Project1] ORDER BY [Project1].[MigrationId] DESC) IF object_id('[foo].[__MigrationHistory]') IS NOT NULL SELECT @CurrentMigration = (SELECT TOP (1) [Project1].[MigrationId] AS [MigrationId] FROM ( SELECT [Extent1].[MigrationId] AS [MigrationId] FROM [foo].[__MigrationHistory] AS [Extent1] WHERE [Extent1].[ContextKey] = N'MyKey' ) AS [Project1] ORDER BY [Project1].[MigrationId] DESC) IF object_id('[bar].[__MigrationHistory]') IS NOT NULL SELECT @CurrentMigration = (SELECT TOP (1) [Project1].[MigrationId] AS [MigrationId] FROM ( SELECT [Extent1].[MigrationId] AS [MigrationId] FROM [bar].[__MigrationHistory] AS [Extent1] WHERE [Extent1].[ContextKey] = N'MyKey' ) AS [Project1] ORDER BY [Project1].[MigrationId] DESC) IF @CurrentMigration IS NULL SET @CurrentMigration = '0' IF @CurrentMigration < 'V1' BEGIN DECLARE @var0 nvarchar(128) SELECT @var0 = name FROM sys.default_constraints WHERE parent_object_id = object_id(N'Customers') AND col_name(parent_object_id, parent_column_id) = 'Foo'; IF @var0 IS NOT NULL EXECUTE('ALTER TABLE [Customers] DROP CONSTRAINT [' + @var0 + ']') ALTER TABLE [Customers] DROP COLUMN [Foo] EXECUTE(' CREATE PROCEDURE [Foo] AS BEGIN Bar END ') END IF @CurrentMigration < 'V2' BEGIN ALTER TABLE [Customers] ADD [C] [nvarchar](max) EXECUTE(' CREATE PROCEDURE [bar] AS BEGIN baz END ') END ", sql); }
public void Can_create_count_query_command_tree() { ResetDatabase(); var historyRepository = new HistoryRepository(Mock.Of<InternalContextForMock>(), ConnectionString, ProviderFactory, "MyKey", null, HistoryContext.DefaultFactory); var commandTrees = historyRepository.CreateDiscoveryQueryTrees(); foreach (var commandTree in commandTrees) { Assert.NotNull(commandTree); Assert.Equal(DataSpace.SSpace, commandTree.DataSpace); Assert.Equal(0, commandTree.Parameters.Count()); } }
public void Can_create_count_query_command_trees_when_sql_azure_execution_strategy() { ResetDatabase(); try { MutableResolver.AddResolver<Func<IDbExecutionStrategy>>( key => (Func<IDbExecutionStrategy>)(() => new SqlAzureExecutionStrategy())); var historyRepository = new HistoryRepository(Mock.Of<InternalContextForMock>(), ConnectionString, ProviderFactory, "MyKey", null, HistoryContext.DefaultFactory); var commandTrees = historyRepository.CreateDiscoveryQueryTrees(); foreach (var commandTree in commandTrees) { Assert.NotNull(commandTree); Assert.Equal(DataSpace.SSpace, commandTree.DataSpace); Assert.Equal(0, commandTree.Parameters.Count()); } } finally { MutableResolver.ClearResolvers(); } }