Ejemplo n.º 1
0
 public void BasicRunTest()
 {
     Configuration target = new Configuration(new[] { "-m" });
     Assert.IsTrue(target.Migrate);
     Assert.IsFalse(target.WriteHelp);
     Assert.IsFalse(target.List);
     Assert.IsFalse(target.Generate);
 }
Ejemplo n.º 2
0
 public GenerateSQL(Configuration configuration, Settings settings, ISqlFormatter sql_formatter, IFileWriter file_writer, IMigrationProvider migration_provider)
 {
     _configuration = configuration;
     _settings = settings;
     _sql_formatter = sql_formatter;
     _file_writer = file_writer;
     _migration_provider = migration_provider;
 }
Ejemplo n.º 3
0
 public void BasicGenerateErrorTest()
 {
     try {
         Configuration target = new Configuration(new[] {"-G"});
         Assert.IsTrue(false, "Configuration should have failed");
     } catch (Exception ex) {
         Assert.IsNotNull(ex);
     }
 }
Ejemplo n.º 4
0
 public Generator(Configuration configuration, Settings settings, IFileWriter file_writer)
 {
     if(!configuration.Generate) {
         throw new InvalidOperationException("Configuration not correctly set for Generator");
     }
     _file_writer = file_writer;
     _configuration = configuration;
     _settings = settings;
     set_generation_action();
 }
Ejemplo n.º 5
0
 public void GeneratorAddSingleColumnTest()
 {
     Configuration configuration = new Configuration(new[] { "-g", "addfirst_nametoUsers" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.True(file_writer.FileName.Contains("Users"));
     Assert.True(file_writer.FileName.Contains("AddColumn"));
     Assert.True(file_writer.FileContents.Contains("add_column"));
     Assert.True(file_writer.FileContents.Contains("up"));
     Assert.True(file_writer.FileContents.Contains("first_name"));
 }
Ejemplo n.º 6
0
        public void TestGeneratePlainSQLStringDown()
        {
            var json = "{\"down\":\"DELETE FROM [Control] WHERE ControlName LIKE '%Date Label'\"}";

            Configuration configuration = new Configuration(new[] { "-s", "1" });
            TestFileWriter file_writer = new TestFileWriter();
            ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings);
            TestSQLDatabaseProvider _database_provider = new TestSQLDatabaseProvider(configuration, Settings, formatter);

            dynamic migration_object = Helpers.DeserializeMigration(json);
            _database_provider.ExecuteDownCommand(migration_object);
            Assert.Equal("DELETE FROM [Control] WHERE ControlName LIKE '%Date Label'", _database_provider.LastCommand);
        }
Ejemplo n.º 7
0
 public void SqlFormatterAddIndexTest()
 {
     Configuration configuration = new Configuration(new[] { "-s", "6" });
     TestFileWriter file_writer = new TestFileWriter();
     ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings);
     IMigrationProvider migrations = new TestMigrationProvider();
     IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations);
     migrations.SetMigrationNumber(5); // add index
     target.Execute();
     Console.WriteLine(file_writer.FileContents);
     Assert.True(file_writer.FileName.Contains("6"));
     Assert.True(file_writer.FileContents.Contains("CREATE NONCLUSTERED INDEX [IX_categories_title_slug] ON [categories] ( [title] ASC, [slug] ASC )"));
 }
Ejemplo n.º 8
0
 public void GeneratorAddReferenceColumnTest()
 {
     Configuration configuration = new Configuration(new[] { "-g", "AddUserToOrders", "User:reference" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.True(file_writer.FileName.Contains("AddColumn_Orders_UserId"));
     Assert.True(file_writer.FileContents.Contains("add_column"));
     Assert.True(file_writer.FileContents.Contains("up"));
     Assert.True(file_writer.FileContents.Contains("\"name\":\"User\",\"type\":\"reference\"}]"));
     Assert.True(file_writer.FileContents.Contains("remove_column"));
     Assert.True(file_writer.FileContents.Contains("\"column\":\"UserId\""));
 }
Ejemplo n.º 9
0
 public void SqlFormatterAddColumnTest()
 {
     Configuration configuration = new Configuration(new[] { "-s", "3" });
     TestFileWriter file_writer = new TestFileWriter();
     ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings);
     IMigrationProvider migrations = new TestMigrationProvider();
     IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations);
     migrations.SetMigrationNumber(3); // add col
     target.Execute();
     Console.WriteLine(file_writer.FileContents);
     Assert.True(file_writer.FileName.Contains("3"));
     Assert.True(file_writer.FileContents.Contains("ALTER TABLE [tname]"));
     Assert.True(file_writer.FileContents.Contains("ADD [name]"));
     Assert.True(file_writer.FileContents.Contains("nvarchar(255)"));
 }
Ejemplo n.º 10
0
 public void SqlFormatterAddColumnReferenceTest()
 {
     Configuration configuration = new Configuration(new[] { "-s", "9" });
     TestFileWriter file_writer = new TestFileWriter();
     ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings);
     IMigrationProvider migrations = new TestMigrationProvider();
     IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations);
     //migrations.SetMigrationNumber(9); // add col
     target.Execute();
     Console.WriteLine(file_writer.FileContents);
     Assert.True(file_writer.FileName.Contains("9"));
     Assert.True(file_writer.FileContents.Contains("FK_orders_user_userid"));
     Assert.True(file_writer.FileContents.Contains("ALTER TABLE [Orders] ADD [UserId] INT NOT NULL"));
     Assert.True(file_writer.FileContents.Contains("ALTER TABLE [Orders] ADD CONSTRAINT [FK_orders_user_userid] FOREIGN KEY ([UserId]) REFERENCES [User] ([Id]) ON DELETE NO ACTION ON UPDATE NO ACTION"));
 }
Ejemplo n.º 11
0
 public void SqlFormatterAddTableReferenceTest()
 {
     Configuration configuration = new Configuration(new[] { "-s", "10" });
     TestFileWriter file_writer = new TestFileWriter();
     ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings);
     IMigrationProvider migrations = new TestMigrationProvider();
     IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations);
     //migrations.SetMigrationNumber(10); // add col
     target.Execute();
     Console.WriteLine(file_writer.FileContents);
     Assert.True(file_writer.FileName.Contains("10"));
     Assert.True(file_writer.FileContents.Contains("FK_applicationcontrol_applicationpage_applicationpageid"));
     Assert.True(file_writer.FileContents.Contains("FK_applicationcontrol_application_applicationid"));
     Assert.True(file_writer.FileContents.Contains("FOREIGN KEY ([ApplicationPageId]) REFERENCES [ApplicationPage] ([Id])"));
     Assert.True(file_writer.FileContents.Contains("FOREIGN KEY ([ApplicationId]) REFERENCES [Application] ([Id])"));
 }
Ejemplo n.º 12
0
 public void GeneratorDropIndexTest()
 {
     Configuration configuration = new Configuration(new[] { "-g", "removeindexfromUsers", "first_name", "last_name" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.True(file_writer.FileName.Contains("Users"));
     Assert.True(file_writer.FileName.Contains("RemoveIndex"));
     Assert.True(file_writer.FileContents.Contains("remove_index"));
     Assert.True(file_writer.FileContents.Contains("up"));
     Assert.True(file_writer.FileContents.Contains("first_name"));
     Assert.True(file_writer.FileContents.Contains("last_name"));
 }
Ejemplo n.º 13
0
 public void GeneratorChangeSingleColumnTest()
 {
     Configuration configuration = new Configuration(new[] { "-g", "ChangeUsers", "first_name:string" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.True(file_writer.FileName.Contains("Users"));
     Assert.True(file_writer.FileName.Contains("ChangeColumn"));
     Assert.True(file_writer.FileContents.Contains("change_column"));
     Assert.True(file_writer.FileContents.Contains("up"));
     Assert.True(file_writer.FileContents.Contains("first_name"));
     Assert.True(file_writer.FileContents.Contains("down"));
 }
Ejemplo n.º 14
0
 public void GeneratorAddTableNoColumnsSpecified()
 {
     Configuration configuration = new Configuration(new[] { "-g","Users" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.True(file_writer.FileName.Contains("Users"));
     Assert.True(file_writer.FileContents.Contains("create_table"));
     Assert.True(file_writer.FileContents.Contains("drop_table"));
     Assert.True(file_writer.FileContents.Contains("column_name_here"));
 }
Ejemplo n.º 15
0
 public void SqlFormatterDropTableTest()
 {
     Configuration configuration = new Configuration(new[] { "-s", "2" });
     TestFileWriter file_writer = new TestFileWriter();
     ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings);
     IMigrationProvider migrations = new TestMigrationProvider();
     IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations);
     migrations.SetMigrationNumber(2); // drop table
     target.Execute();
     Console.WriteLine(file_writer.FileContents);
     Assert.True(file_writer.FileName.Contains("2"));
     Assert.True(file_writer.FileContents.Contains("DROP TABLE [tname]"));
 }
Ejemplo n.º 16
0
 public void GeneratorAddSingleColumnTestDuplicateTo()
 {
     Configuration configuration = new Configuration(new[] { "-g", "addcustomernametoUsers" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.Null(file_writer.FileContents);
 }
Ejemplo n.º 17
0
 public void GeneratorRemoveColumn()
 {
     Configuration configuration = new Configuration(new[] { "-g", "Removefirst_nameFromUsers" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.True(file_writer.FileName.Contains("Users"));
     Assert.True(file_writer.FileName.Contains("RemoveColumn"));
     Assert.True(file_writer.FileContents.Contains("remove_column"));
     Assert.True(file_writer.FileContents.Contains("up"));
     Assert.True(file_writer.FileContents.Contains("first_name"));
 }
Ejemplo n.º 18
0
 public JsonFileMigrationProvider(Configuration configuration, Settings settings, IDatabaseProvider database_provider)
 {
     _configuration = configuration;
     _settings = settings;
     _database_provider = database_provider;
 }
Ejemplo n.º 19
0
 public TestSQLDatabaseProvider(Configuration configuration, Settings settings, ISqlFormatter sql_formatter)
     : base(configuration, settings, sql_formatter)
 {
 }
Ejemplo n.º 20
0
 public void SqlFormatterAddTableTest()
 {
     Configuration configuration = new Configuration(new[] { "-s", "1" });
     TestFileWriter file_writer = new TestFileWriter();
     ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings);
     IMigrationProvider migrations = new TestMigrationProvider();
     IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations);
     migrations.SetMigrationNumber(1); // create table
     target.Execute();
     Console.WriteLine(file_writer.FileContents);
     Assert.True(file_writer.FileName.Contains("1"));
     Assert.True(file_writer.FileContents.Contains("CREATE TABLE [tname]"));
     Assert.True(file_writer.FileContents.Contains("[first_name] nvarchar(255)"));
     Assert.True(file_writer.FileContents.Contains("[last_name] decimal"));
     Assert.True(file_writer.FileContents.Contains("CreatedOn datetime DEFAULT getutcdate() NOT NULL"));
     Assert.True(file_writer.FileContents.Contains("Id"));
     Assert.True(file_writer.FileContents.Contains("PRIMARY KEY"));
 }
Ejemplo n.º 21
0
 public void GeneratorDropTable()
 {
     Configuration configuration = new Configuration(new[] { "-g", "DropUsers" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.True(file_writer.FileName.Contains("Users"));
     Assert.True(file_writer.FileName.Contains("DropTable"));
     Assert.True(file_writer.FileContents.Contains("drop_table"));
     Assert.True(file_writer.FileContents.Contains("up"));
     Assert.True(file_writer.FileContents.Contains("Users"));
 }
Ejemplo n.º 22
0
 public SQLCEDatabaseProvider(Configuration configuration, Settings settings, ISqlFormatter sql_formatter)
 {
     _configuration = configuration;
     _settings = settings;
     _sql_formatter = sql_formatter;
 }
Ejemplo n.º 23
0
 public void GeneratorFileTest()
 {
     Configuration configuration = new Configuration(new[] { "-g", "File", "mysqlfile" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.True(file_writer.FileName.Contains("File"));
     Assert.True(file_writer.FileContents.Contains("file"));
     Assert.True(file_writer.FileContents.Contains("mysqlfile"));
     Assert.True(file_writer.FileContents.Contains("up"));
 }
Ejemplo n.º 24
0
 public Help(Configuration configuration)
 {
     _configuration = configuration;
 }
Ejemplo n.º 25
0
 public void GeneratorSqlTest()
 {
     Configuration configuration = new Configuration(new[] { "-g", "SQL", "CREATE TABLE Users (ID {pk}, first_name {string} NOT NULL, price_paid {money})" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.True(file_writer.FileName.Contains("SQL"));
     Assert.True(file_writer.FileContents.Contains("CREATE TABLE Users (ID {pk}, first_name {string} NOT NULL, price_paid {money})"));
     Assert.True(file_writer.FileContents.Contains("up"));
     Assert.True(file_writer.FileContents.Contains("down"));
     Assert.True(file_writer.FileContents.Contains("\"down\":\"\""));
 }
Ejemplo n.º 26
0
 public SourceEditor(Configuration configuration, IMigrationProvider migration_provider, MigrationViewer viewer)
 {
     _migration_provider = migration_provider;
     _configuration = configuration;
     list_viewer = viewer;
 }
Ejemplo n.º 27
0
 public void BasicSqlTest2()
 {
     Configuration target = new Configuration(new[] { "--Sql" });
     Assert.IsTrue(target.Sql);
     Assert.IsFalse(target.WriteHelp);
     Assert.IsFalse(target.Migrate);
 }
Ejemplo n.º 28
0
 public void GeneratorAddTableMultipleColumn()
 {
     Configuration configuration = new Configuration(new[] { "-g", "Users", "first_name:string", "last_name:string" });
     TestFileWriter file_writer = new TestFileWriter();
     IHumpbackCommand target = new Generator(configuration, Settings, file_writer);
     target.Execute();
     Assert.True(file_writer.FileName.Contains("Users"));
     Assert.True(file_writer.FileContents.Contains("create_table"));
     Assert.True(file_writer.FileContents.Contains("up"));
     Assert.True(file_writer.FileContents.Contains("down"));
     Assert.True(file_writer.FileContents.Contains("drop_table"));
     Assert.True(file_writer.FileContents.Contains("first_name"));
     Assert.True(file_writer.FileContents.Contains("last_name"));
     Assert.True(file_writer.FileContents.Contains("timestamps"));
 }
Ejemplo n.º 29
0
 public MigrationViewer(Configuration configuration, IMigrationProvider migration_provider)
 {
     _migration_provider = migration_provider;
     _configuration = configuration;
 }
Ejemplo n.º 30
0
 public void SqlFormatterDropIndexTest()
 {
     Configuration configuration = new Configuration(new[] { "-s", "7" });
     TestFileWriter file_writer = new TestFileWriter();
     ISqlFormatter formatter = new SQLServerFormatter(configuration, Settings);
     IMigrationProvider migrations = new TestMigrationProvider();
     IHumpbackCommand target = new GenerateSQL(configuration, Settings, formatter, file_writer, migrations);
     migrations.SetMigrationNumber(6); // add index
     target.Execute();
     Console.WriteLine(file_writer.FileContents);
     Assert.True(file_writer.FileName.Contains("7"));
     Assert.True(file_writer.FileContents.Contains("DROP INDEX [categories].[IX_categories_title_slug]"));
 }