public static void CopyAndAttachDatabase(TestContext context, string databaseName) { string destinationPath = CopyDatabase(context, databaseName); // Attach the copied database to SQL Server AttachDatabase(databaseName, destinationPath); }
/// <summary> /// Enters the specified context with the current thread. /// </summary> /// <remarks> /// <para> /// Conceptually this method pushes the specified context onto the context /// stack for the current thread. It then returns a cookie that can be used /// to restore the current thread's context to its previous value. /// </para> /// </remarks> /// <param name="context">The context to enter, or null to enter a scope /// without a context.</param> /// <returns>A cookie that can be used to restore the current thread's context to its previous value.</returns> /// <seealso cref="TestContextCookie"/> public static TestContextCookie EnterContext(TestContext context) { return new TestContextCookie(ContextTracker.EnterContext(context.inner)); }
public void SetUp() { previousContext = TestContext.CurrentContext; TestLog.WriteLine(TestContext.CurrentContext.Outcome); }
public void SetUp() { previousContext = TestContext.CurrentContext; TestLog.WriteLine(TestContext.CurrentContext.Outcome); Assert.Fail("Boom"); }
public RunTestDataItemAction(PatternTestExecutor executor, ITestCommand testCommand, PatternTestState testState, TestContext primaryContext, bool reusePrimaryTestStep, IDataItem bindingItem) { this.executor = executor; this.testCommand = testCommand; this.testState = testState; this.primaryContext = primaryContext; this.reusePrimaryTestStep = reusePrimaryTestStep; this.bindingItem = bindingItem; outcome = TestOutcome.Skipped; }
public RunTestAction(PatternTestExecutor executor, ITestCommand testCommand, TestContext parentContext, PatternTestActionsDecorator testActionsDecorator) : this(executor, testCommand, parentContext.TestStep, parentContext.Sandbox, testActionsDecorator) { this.parentContext = parentContext; }
private static void UpdateInterimOutcome(TestContext context, ref TestOutcome outcome, TestOutcome newOutcome) { outcome = outcome.CombineWith(newOutcome); context.SetInterimOutcome(outcome); }
private static string CopyDatabase(TestContext context, string databaseName) { // Find the target database file string targetDatabasePath = EnsureDatabaseExists(databaseName); // Create the test database directory if it does not exist string testDatabaseDirectory = Path.GetFullPath(String.Format(@"Databases\TestDatabases\{0}", context.Test.FullName)); if (!Directory.Exists(testDatabaseDirectory)) { Directory.CreateDirectory(testDatabaseDirectory); } // Copy the database to the test database directory string destinationRoot = Path.Combine(testDatabaseDirectory, databaseName); string databasePath = String.Concat(destinationRoot, ".mdf"); File.Copy(targetDatabasePath, databasePath); return databasePath; }
/// <summary> /// Gets the overlay manager for the specified test context. /// </summary> /// <param name="context">The test context.</param> /// <returns>The overlay manager.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="context"/> is null.</exception> public static OverlayManager GetOverlayManager(TestContext context) { if (context == null) throw new ArgumentNullException("context"); lock (context.Data) { OverlayManager overlayManager; if (! context.Data.TryGetValue(OverlayManagerKey, out overlayManager)) { overlayManager = new OverlayManager(); context.Data.SetValue(OverlayManagerKey, overlayManager); } return overlayManager; } }
private static void RecordTaskResult(TestContext context, Task task) { if (task.Result != null && ! task.Result.HasValue) { context.LogWriter.Warnings.WriteException(task.Result.Exception, String.Format("Task '{0}' failed.", task.Name)); FailureFlag = true; } }
private static void ReapTasks(TestContext context, TaskContainer container) { if (!container.JoinAll(JoinBeforeAbortTimeout)) { LogMessageAboutActiveTasks(context, container, String.Format("Some tasks failed to complete within {0} seconds of test termination: ", JoinBeforeAbortTimeout.TotalSeconds)); container.AbortAll(); if (!container.JoinAll(JoinAfterAbortTimeout)) { LogMessageAboutActiveTasks(context, container, String.Format("Some tasks failed to abort within {0} seconds of test termination: ", (JoinBeforeAbortTimeout + JoinAfterAbortTimeout).TotalSeconds)); } } }
private static void LogMessageAboutActiveTasks(TestContext context, TaskContainer container, string messagePrefix) { IList<Task> activeTasks = container.GetActiveTasks(); if (activeTasks.Count == 0) return; var message = new StringBuilder(messagePrefix); for (int i = 0; i < activeTasks.Count; i++) { if (i != 0) message.Append(", "); message.Append(activeTasks[i].Name); } context.LogWriter.Warnings.WriteLine(message.ToString()); }
private static TaskContainer CreateContainer(TestContext context) { var container = new TaskContainer(); context.Finishing += delegate { ReapTasks(context, container); }; container.TaskTerminated += delegate(object sender, TaskEventArgs e) { RecordTaskResult(context, e.Task); }; return container; }
public static void SetBrowserContext(TestContext testContext, BrowserContext browserContext) { if (testContext == null) throw new ArgumentNullException("testContext"); if (browserContext == null) testContext.Data.RemoveValue(BrowserContextKey); else testContext.Data.SetValue(BrowserContextKey, browserContext); }
public static BrowserContext GetBrowserContext(TestContext testContext) { if (testContext == null) throw new ArgumentNullException("testContext"); return testContext.Data.GetValueOrDefault(BrowserContextKey, null); }
/// <summary> /// Sets the default context for the specified thread. /// </summary> /// <remarks> /// <para> /// The default context for a thread is <see cref="GlobalContext" /> unless the thread's /// default context has been overridden with <see cref="SetThreadDefaultContext" />. /// </para> /// <para> /// Changing the default context of a thread is useful for capturing existing threads created /// outside of a test into a particular context. Among other things, this ensures that side-effects /// of the thread, such as writing text to the console, are recorded as part of the step /// represented by the specified context. /// </para> /// </remarks> /// <param name="thread">The thread.</param> /// <param name="context">The context to associate with the thread, or null to reset the /// thread's default context to inherit the <see cref="GlobalContext" /> once again.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="thread"/> is null.</exception> public static void SetThreadDefaultContext(Thread thread, TestContext context) { ContextTracker.SetThreadDefaultContext(thread, context.inner); }
/// <summary> /// Prepares a <see cref="TestContext" /> wrapper for the given inner context. /// </summary> /// <remarks> /// <para> /// The wrapper is cached for the duration of the lifetime of the inner context. /// </para> /// </remarks> /// <param name="inner">The new inner context.</param> /// <param name="sandbox">The sandbox to use, or null if none.</param> /// <returns>The wrapper context.</returns> /// <exception cref="ArgumentNullException">Thrown if <paramref name="inner"/> is null.</exception> internal static TestContext PrepareContext(ITestContext inner, Sandbox sandbox) { TestContext context = new TestContext(inner, sandbox); inner.Data.SetValue(GallioFrameworkContextKey, context); inner.Finishing += context.NotifyFinishing; return context; }
private AssertionContext(TestContext testContext) { this.testContext = testContext; scope = new Scope(this, AssertionFailureBehavior.LogAndThrow); }