/// <summary> /// Initializes a new instance of the <see cref="DatabaseManager"/> class. /// </summary> /// <param name="logger">The logger.</param> /// <param name="response">The service response to use, instead of a new instance.</param> public DatabaseManager(ILog logger, ServiceResponse response) { if (logger == null) { throw new ArgumentNullException("logger"); } _logger = logger; _response = response ?? new ServiceResponse(); }
private void CheckServiceResponse(ServiceResponse response) { if (response.HasErrors) { _log.Error(response.ErrorsAsString()); throw new BootstrappingException(response.ErrorsAsString()); } if (response.HasInfo) { _log.Info(response.InfoAsString()); } }
/// <summary> /// Destroys the database, if it exists. /// </summary> /// <returns>A <see cref="ServiceResponse"/> with the results of the operation.</returns> public ServiceResponse DestroyDatabase() { var info = CreateDatabaseInfo(); if (!DatabaseManager.DatabaseExists(info)) { var existsResponse = new ServiceResponse(); existsResponse.AddInfo(@"Test database {0}\{1} doesn't exist; nothing to destroy.", info.ServerName, info.DatabaseName); return existsResponse; } var response = _databaseManager.DestroyDatabase(info, null, _publicUserName); return response; }
/// <summary> /// Creates the testing database if it doesn't already exist. /// </summary> /// <returns>A <see cref="ServiceResponse"/> with the results of the operation.</returns> public ServiceResponse CreateDatabase() { var info = CreateDatabaseInfo(); if (DatabaseManager.DatabaseExists(info)) { var existsResponse = new ServiceResponse(); existsResponse.AddInfo(@"Test database {0}\{1} already exists.", info.ServerName, info.DatabaseName); return existsResponse; } var response = _databaseManager.CreateDatabase(info, _publicUserName, _publicPassword, _component, _scriptPath, null); // adds auditing tables to test schema _databaseManager.UpdateDatabaseSchema(info, _publicUserName, "DatabaseScripts.resources", CreateScriptLoader(@"..\..\..\..\..\..\Source\Framework\Auditing\Server\obj\Debug")); return response; }
/// <summary> /// Merges the service response with the given response. /// </summary> /// <param name="response">The response.</param> /// <returns>The <see cref="ServiceResponse"/>.</returns> public ServiceResponse Merge(ServiceResponse response) { if (this != response) { foreach (KeyValuePair<Guid, string> message in response.ErrorMessages) { if (!_errorMessages.ContainsKey(message.Key)) { _errorMessages.Add(message.Key, message.Value); } } foreach (KeyValuePair<Guid, string> message in response.InfoMessages) { if (!_infoMessages.ContainsKey(message.Key)) { _infoMessages.Add(message.Key, message.Value); } } } return this; }