internal void InsertLanguageData(Workspace workspace, ResourceType resourceType) { fxLanguages languages = new fxLanguages(); fxLanguage language = languages.Choose(); AstoriaTestLog.TraceInfo("Language Data: " + language.GetType().Name); // do them one at a time so that if one fails, we know which using (SqlConnection sqlConn = new SqlConnection(this.MachineConnectionString)) { sqlConn.Open(); for (int i = 0; i < 5; i++) { using (SqlCommand sqlCmd = sqlConn.CreateCommand()) { sqlCmd.CommandTimeout = 0; sqlCmd.CommandText = GetInsertString(workspace, resourceType, language, TestUtil.Random); try { sqlCmd.ExecuteNonQuery(); } catch (SqlException error) { AstoriaTestLog.WriteLineIgnore("Error while executing: " + sqlCmd.CommandText); throw; } } } } }
private string GetInsertString(Workspace workspace, ResourceType resourceType, fxLanguage language, Random random) { string commandText = "INSERT INTO {0} ({1}) VALUES ({2});"; string tableName = resourceType.Name; string columns = ""; string values = ""; ResourceInstanceKey rik = ResourceInstanceUtil.CreateUniqueKey(workspace.ServiceContainer.ResourceContainers[resourceType.Name], resourceType); foreach (ResourceInstanceProperty rip in rik.KeyProperties) { columns += rip.Name + ","; string propertyValue = AstoriaUnitTests.Data.TypeData.XmlValueFromObject(((ResourceInstanceSimpleProperty)rip).PropertyValue); values += propertyValue + ","; } foreach (ResourceProperty prop in resourceType.Properties) { if (!prop.IsComplexType && !prop.IsNavigation && !(prop.Type is CollectionType) && prop.PrimaryKey == null) { columns += prop.Name + ","; if (prop.Type is ClrString) { int maxSize = (int)(prop.Facets["MaxSize"].Value.ClrValue); if( maxSize > 1000 ) maxSize = 1000; values += "'" + language.CreateData(random, maxSize).Replace("'", "''") + "',"; } else values += prop.Type.CreateValue().ToString() + ","; } } columns = columns.TrimEnd(','); values = values.TrimEnd(','); string fullTableName = String.Format("[{0}].[{1}].[{2}]", this.DatabaseName, "dbo", tableName); return string.Format(commandText, fullTableName, columns, values); }
private string GetInsertString(Workspace workspace, ResourceType resourceType, fxLanguage language, Random random) { string commandText = "INSERT INTO {0} ({1}) VALUES ({2});"; string tableName = resourceType.Name; string columns = ""; string values = ""; ResourceInstanceKey rik = ResourceInstanceUtil.CreateUniqueKey(workspace.ServiceContainer.ResourceContainers[resourceType.Name], resourceType); foreach (ResourceInstanceProperty rip in rik.KeyProperties) { columns += rip.Name + ","; string propertyValue = AstoriaUnitTests.Data.TypeData.XmlValueFromObject(((ResourceInstanceSimpleProperty)rip).PropertyValue); values += propertyValue + ","; } foreach (ResourceProperty prop in resourceType.Properties) { if (!prop.IsComplexType && !prop.IsNavigation && !(prop.Type is CollectionType) && prop.PrimaryKey == null) { columns += prop.Name + ","; if (prop.Type is ClrString) { int maxSize = (int)(prop.Facets["MaxSize"].Value.ClrValue); if (maxSize > 1000) { maxSize = 1000; } values += "'" + language.CreateData(random, maxSize).Replace("'", "''") + "',"; } else { values += prop.Type.CreateValue().ToString() + ","; } } } columns = columns.TrimEnd(','); values = values.TrimEnd(','); string fullTableName = String.Format("[{0}].[{1}].[{2}]", this.DatabaseName, "dbo", tableName); return(string.Format(commandText, fullTableName, columns, values)); }