public override object Execute(object o, System.Collections.IList args) { // get info DbRestoreInfoAttribute info = DbRestoreInfoAttribute.GetInfo(o.GetType()); // create factory IDbFactory factory = info.CreateFactory(); // create admin DbAdministratorBase admin = factory.CreateAdmin(info.ConnectionString, info.DatabaseName); // restore before if before if (this.parent.Schedule == TestSchedule.BeforeTest) { admin.RestoreDatabase(info.BackupDevice, info.BackupDestination); } // do the thing try { return(this.Invoker.Execute(o, args)); } finally { if (this.parent.Schedule == TestSchedule.AfterTest) { admin.RestoreDatabase(info.BackupDevice, info.BackupDestination); } } }
/// <summary> /// Gets the custom attributes on the attribute /// </summary> /// <param name="t">The attribute <see cref="Type"/>.</param> /// <returns>The custom attributes (database information) for the backup</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="t"/> is null</exception> /// <exception cref="MissingDbInfoException">Thrown if no database information can be found attached to the attribute taggign the class</exception> public static DbRestoreInfoAttribute GetInfo(Type t) { if (t == null) { throw new ArgumentNullException("t"); } // get database information DbRestoreInfoAttribute info = (DbRestoreInfoAttribute)TypeHelper.TryGetFirstCustomAttribute(t, typeof(DbRestoreInfoAttribute)); if (info == null) { throw new MbUnit.Framework.Exceptions.MissingDbInfoException(t); } return(info); }