/// <summary> /// Validates the schema against the database and throws exceptions if differences exist. /// </summary> /// <param name="schemaFilename">The schema filename.</param> /// <exception cref="System.InvalidOperationException">Differences exist between the schema file and the database that must be resolved before running test(s). /// </exception> protected void ValidateSchemaAgainstDatabase(string schemaFilename) { ValidateConnectionString(DatabaseConnectionString); ValidateSupportFileExists(schemaFilename); ISchemaValidator validator; switch (_databaseClientType) { case DatabaseClientType.SqlClient: validator = new SqlClientSchemaValidator(schemaFilename, DatabaseConnectionString); break; case DatabaseClientType.SqliteClient: case DatabaseClientType.OleDBClient: case DatabaseClientType.MySqlClient: case DatabaseClientType.SqlCeClient: case DatabaseClientType.OracleClient: validator = new NullSchemaValidator(); break; default: throw new InvalidOperationException(string.Format("Unsupported Database client type: {0}", _databaseClientType.ToString())); } SchemaComparisonReport compareResults = validator.Validate(); foreach (string errorReport in compareResults.Errors) { System.Diagnostics.Debug.WriteLine(string.Format("SCHEMA_VALIDATION_ERROR ({0}): {1}", schemaFilename, errorReport)); } foreach (string warnReport in compareResults.Warnings) { System.Diagnostics.Debug.WriteLine(string.Format("SCHEMA_VALIDATION_WARNING ({0}): {1}", schemaFilename, warnReport)); } foreach (string infoReport in compareResults.Information) { System.Diagnostics.Debug.WriteLine(string.Format("SCHEMA_VALIDATION_INFO ({0}): {1}", schemaFilename, infoReport)); } if (compareResults.Errors.Count > 0) { throw new InvalidOperationException(string.Format("Cannot validate XSD Schema file {0} against existing database schema.\nTests cannot continue else data may be lost.\nCorrect errors in schema file and attempt tests again.", schemaFilename)); } }
/// <summary> /// Validates the schema against the database and throws exceptions if differences exist. /// </summary> /// <param name="schemaFilename">The schema filename.</param> /// <exception cref="System.InvalidOperationException">Differences exist between the schema file and the database that must be resolved before running test(s). /// </exception> protected void ValidateSchemaAgainstDatabase(string schemaFilename) { ValidateConnectionString(DatabaseConnectionString); ValidateSupportFileExists(schemaFilename); ISchemaValidator validator; switch (_databaseClientType) { case DatabaseClientType.SqlClient: validator = new SqlClientSchemaValidator(schemaFilename, DatabaseConnectionString); break; case DatabaseClientType.SqliteClient: case DatabaseClientType.OleDBClient: case DatabaseClientType.MySqlClient: case DatabaseClientType.SqlCeClient: case DatabaseClientType.OracleClient: validator = new NullSchemaValidator(); break; default: throw new InvalidOperationException(string.Format("Unsupported Database client type: {0}", _databaseClientType.ToString())); } SchemaComparisonReport compareResults = validator.Validate(); foreach (string errorReport in compareResults.Errors) { System.Diagnostics.Debug.WriteLine(string.Format("SCHEMA_VALIDATION_ERROR ({0}): {1}", schemaFilename, errorReport)); } foreach (string warnReport in compareResults.Warnings) { System.Diagnostics.Debug.WriteLine(string.Format("SCHEMA_VALIDATION_WARNING ({0}): {1}", schemaFilename, warnReport)); } foreach (string infoReport in compareResults.Information) { System.Diagnostics.Debug.WriteLine(string.Format("SCHEMA_VALIDATION_INFO ({0}): {1}", schemaFilename, infoReport)); } if (compareResults.Errors.Count > 0) throw new InvalidOperationException(string.Format("Cannot validate XSD Schema file {0} against existing database schema.\nTests cannot continue else data may be lost.\nCorrect errors in schema file and attempt tests again.", schemaFilename)); }