public void Manages_database() { var settings = new ConnectionSettings("server", "db", true, null, null); var scriptDirectory = @"c:\scripts"; var taskAttributes = new TaskAttributes(settings, scriptDirectory); taskAttributes.RequestedDatabaseAction= RequestedDatabaseAction.Create; var mocks = new MockRepository(); var taskObserver = mocks.StrictMock<ITaskObserver>(); var generator = mocks.StrictMock<ILogMessageGenerator>(); var factory = mocks.StrictMock<IDatabaseActionExecutorFactory>(); var creator = mocks.StrictMock<IDatabaseActionExecutor>(); var updater = mocks.StrictMock<IDatabaseActionExecutor>(); var executors = new IDatabaseActionExecutor[] { creator, updater }; using (mocks.Record()) { Expect.Call(generator.GetInitialMessage(taskAttributes)).Return("starting..."); taskObserver.Log("starting..."); Expect.Call(factory.GetExecutors(RequestedDatabaseAction.Create)).Return(executors); creator.Execute(taskAttributes, taskObserver); updater.Execute(taskAttributes, taskObserver); } using (mocks.Playback()) { ISqlDatabaseManager manager = new SqlDatabaseManager(generator, factory); manager.Upgrade(taskAttributes, taskObserver); } mocks.VerifyAll(); }
/// <summary> /// <para>Runs AliaSQL against a database</para> /// <para>Default action is Update but it can be set to other AliaSQL actions</para> /// <para>Default script directory is ~/App_Data/scripts/ but it can bet set to any physical path</para> /// <para>-If database does not exist it will be created</para> /// <para>-Script directory path must exist</para> /// <para>Returns an object with a success boolean and a result string</para> /// </summary> /// <param name="connectionString"></param> /// <param name="action"></param> /// <param name="scriptDirectory"></param> /// <returns>Returns an object with a success boolean and a result string</returns> public AliaSqlResult UpdateDatabase(string connectionString, RequestedDatabaseAction action = RequestedDatabaseAction.Update, string scriptDirectory = "") { if (scriptDirectory == "") { scriptDirectory = Path.Combine(AppDomain.CurrentDomain.GetData("DataDirectory").ToString(), "scripts"); } if (!Directory.Exists(scriptDirectory)) { throw new ArgumentException("There are no scripts in the defined data directory."); } if (action == RequestedDatabaseAction.Update && !PendingChanges(connectionString, scriptDirectory).Any()) { return new AliaSqlResult { Result = "No pending changes", Success = true }; } var result = new AliaSqlResult { Success = true }; var manager = new SqlDatabaseManager(); var taskAttributes = new TaskAttributes(_connectionStringGenerator.GetConnectionSettings(connectionString), scriptDirectory) { RequestedDatabaseAction = action, }; try { manager.Upgrade(taskAttributes, this); foreach (var property in _properties) { Log(property.Key + ": " + property.Value); } result.Result = sb.ToString(); } catch (Exception exception) { result.Success = false; var ex = exception; do { Log("Failure: " + ex.Message); if (ex.Data["Custom"] != null) Log(ex.Data["Custom"].ToString()); ex = ex.InnerException; } while (ex != null); } result.Result = sb.ToString(); return result; }
public bool UpdateDatabase(ConnectionSettings settings, string scriptDirectory, RequestedDatabaseAction action) { var manager = new SqlDatabaseManager(); var taskAttributes = new TaskAttributes(settings, scriptDirectory) { RequestedDatabaseAction = action, }; try { manager.Upgrade(taskAttributes, this); foreach (var property in _properties) { Log(property.Key +": " + property.Value); } return true; } catch (Exception exception) { var ex = exception; do { Log("Failure: " + ex.Message); if (ex.Data["Custom"] != null) Log(ex.Data["Custom"].ToString()); ex = ex.InnerException; } while (ex != null); } if (Debugger.IsAttached) System.Console.ReadLine(); return false; }
public void Should_create_a_new_instance_without_IoC() { var manager = new SqlDatabaseManager(); }