public void AlterColumnType_NoArchive(DatabaseType dbType) { var db = GetCleanedServer(dbType); var tbl = db.CreateTable("MyTbl", new[] { new DatabaseColumnRequest("mycol", new DatabaseTypeRequest(typeof(string), 10)) }); Import(tbl, out var ti, out _); var ui = new UITests(); var activator = new TestActivateItems(ui, new MemoryDataExportRepository()); var myCol = tbl.DiscoverColumn("myCol"); //should have started out as 10 Assert.AreEqual(10, myCol.DataType.GetLengthIfString()); //we want the new type to be 50 long var newType = myCol.DataType.SQLType.Replace("10", "50"); activator.TypeTextResponse = newType; var cmd = new ExecuteCommandAlterColumnType(activator, ti.ColumnInfos.Single()); cmd.Execute(); //rediscover the col to get the expected new datatype myCol = tbl.DiscoverColumn("myCol"); Assert.AreEqual(newType, myCol.DataType.SQLType); Assert.AreEqual(newType, ti.ColumnInfos[0].Data_type); tbl.Drop(); }
public void AlterColumnType_WithArchive(DatabaseType dbType, bool changeArchive) { var db = GetCleanedServer(dbType); var tbl = db.CreateTable("MyTbl", new[] { new DatabaseColumnRequest("mycol", new DatabaseTypeRequest(typeof(string), 10)) }); var tblArchive = db.CreateTable("MyTbl_Archive", new[] { new DatabaseColumnRequest("mycol", new DatabaseTypeRequest(typeof(string), 10)) }); Import(tbl, out TableInfo ti, out _); var ui = new UITests(); var activator = new TestActivateItems(ui, new MemoryDataExportRepository()); var myCol = tbl.DiscoverColumn("myCol"); //should have started out as 10 Assert.AreEqual(10, myCol.DataType.GetLengthIfString()); string oldType = myCol.DataType.SQLType; //we want the new type to be 50 long var newType = oldType.Replace("10", "50"); activator.TypeTextResponse = newType; activator.YesNoResponse = changeArchive; var cmd = new ExecuteCommandAlterColumnType(activator, ti.ColumnInfos.Single()); cmd.Execute(); //rediscover the col to get the expected new datatype myCol = tbl.DiscoverColumn("myCol"); var myColArchive = tblArchive.DiscoverColumn("myCol"); Assert.AreEqual(newType, myCol.DataType.SQLType); Assert.AreEqual(newType, ti.ColumnInfos[0].Data_type); //if they changed the archive then the archive column should also match on Type otherwise it should have stayed the old Type Assert.AreEqual(changeArchive ? newType : oldType, myColArchive.DataType.SQLType); tbl.Drop(); tblArchive.Drop(); }