diff --git a/Tests/terminalAzureTests/Integration/Write_To_Sql_Server_v1_Tests.cs b/Tests/terminalAzureTests/Integration/Write_To_Sql_Server_v1_Tests.cs index 35a3e1cadc..408bf01f55 100644 --- a/Tests/terminalAzureTests/Integration/Write_To_Sql_Server_v1_Tests.cs +++ b/Tests/terminalAzureTests/Integration/Write_To_Sql_Server_v1_Tests.cs @@ -169,13 +169,13 @@ await HttpPostAsync( Assert.NotNull(responseActionDTO.CrateStorage); var crateStorage = Crate.FromDto(responseActionDTO.CrateStorage); //There will be no DesignTimeCrate only Configuration crate - Assert.AreEqual(1, crateStorage.Count); + Assert.AreEqual(2, crateStorage.Count); Assert.AreEqual(1, crateStorage.CratesOfType().Count()); var controls = crateStorage.CrateContentsOfType().Single(); AssertConfigureControls(controls); //Check that Error message is shown var connStringTextBox = (TextBox)controls.Controls[0]; - Assert.AreEqual("Incorrect Connection String", connStringTextBox.Value); + Assert.AreEqual("This is incorrect database connection string!", connStringTextBox.Value); } /// diff --git a/terminalAzure/Activities/Write_To_Sql_Server_v1.cs b/terminalAzure/Activities/Write_To_Sql_Server_v1.cs index b240b436c0..56e6a845fd 100644 --- a/terminalAzure/Activities/Write_To_Sql_Server_v1.cs +++ b/terminalAzure/Activities/Write_To_Sql_Server_v1.cs @@ -35,7 +35,7 @@ public class Write_To_Sql_Server_v1 : ExplicitTerminalActivity protected override ActivityTemplateDTO MyTemplate => ActivityTemplateDTO; - public Write_To_Sql_Server_v1(ICrateManager crateManager, IDbProvider dbProvider) + public Write_To_Sql_Server_v1(ICrateManager crateManager, IDbProvider dbProvider) : base(crateManager) { _dbProvider = dbProvider; @@ -52,8 +52,6 @@ public override Task Initialize() //if the user provides a connection string, this action attempts to connect to the sql server and get its columns and tables public override Task FollowUp() { - //Verify controls, make sure that TextBox with value exists - ValidateControls(); //In all followup calls, update data fields of the configuration store try { @@ -71,16 +69,16 @@ public override Task FollowUp() var textSourceControls = ConfigurationControls.Controls.OfType(); foreach (var control in textSourceControls.ToList()) { - RemoveControl(control.Name); + RemoveControl(control.Name); } var columns = GetTableColumns(dropDownControl.Value); foreach (var column in columns) { - if(identityColumn != column.ColumnName) + if (identityColumn != column.ColumnName) { var textSource = UiBuilder.CreateSpecificOrUpstreamValueChooser(column.ColumnName, column.ColumnName); - + if (column.isNullable == false) { textSource.Required = true; @@ -94,7 +92,7 @@ public override Task FollowUp() //this needs to be updated to hold Crates instead of FieldDefinitionDTO // Storage.Add("Sql Table Columns", new KeyValueListCM(contentsList.Select(col => new KeyValueDTO { Key = col, Value = col }))); } - catch(Exception e) + catch (Exception e) { AddErrorToControl(); } @@ -224,7 +222,7 @@ private void ListTableColumns(string connectionString, string tableName, Action< //public List GetFieldMappings() //{ // var connStringField = ConfigurationControls.Controls.First(); - + // return (List)_dbProvider.ConnectToSql(connStringField.Value, (command) => // { // command.CommandText = FieldMappingQuery; @@ -246,24 +244,50 @@ private void ListTableColumns(string connectionString, string tableName, Action< // }); //} - private void ValidateControls() + protected override Task Validate() { - if (Storage.Count == 0) + + var connStringField = ConfigurationControls.Controls.FirstOrDefault(); + if(connStringField != null) { - throw new TerminalCodedException(TerminalErrorCode.SQL_SERVER_CONNECTION_STRING_MISSING); + if (string.IsNullOrEmpty(connStringField.Value)) + { + ValidationManager.SetError("Connection string can't be empty", connStringField); + } + else + { + try + { + var columns = GetTables(); + } + catch (Exception e) + { + ValidationManager.SetError(e.Message, connStringField); + } + } } + - if (ConfigurationControls == null) + var dropDownControl = ConfigurationControls.Controls.OfType().FirstOrDefault(); + if(dropDownControl != null) { - throw new TerminalCodedException(TerminalErrorCode.SQL_SERVER_CONNECTION_STRING_MISSING); + if (string.IsNullOrEmpty(dropDownControl?.Value) && dropDownControl.ListItems.Count > 0) + { + ValidationManager.SetError("Table must be selected", dropDownControl); + } } - var connStringField = ConfigurationControls.Controls.First(); - if (string.IsNullOrEmpty(connStringField?.Value)) + var textSourceControls = ConfigurationControls.Controls.OfType(); + foreach (var control in textSourceControls) { - throw new TerminalCodedException(TerminalErrorCode.SQL_SERVER_CONNECTION_STRING_MISSING); + if (control.Required == true && string.IsNullOrEmpty(control.TextValue)) + { + ValidationManager.SetError("Column is not nullable", control); + } } + return Task.FromResult(0); } + private void AddErrorToControl() { var connStringTextBox = GetControl("connection_string"); @@ -361,7 +385,7 @@ private IEnumerable CreateTable() var values = new List(); foreach (var control in textSourceControls) { - if(!string.IsNullOrEmpty(control.TextValue)) + if (!string.IsNullOrEmpty(control.TextValue)) { values.Add(new FieldValue(control.Name, control.TextValue)); }