コード例 #1
0
        /// <summary>
        /// Gets the element which currently has focus.
        /// </summary>
        /// <typeparam name="T">The type of element which is expected to have focus.</typeparam>
        /// <param name="app">The Ultraviolet test application.</param>
        /// <returns>The element which currently has focus.</returns>
        protected T GetElementWithFocus <T>(IUltravioletTestApplication app) where T : UIElement
        {
            var screen = app.Ultraviolet.GetUI().GetScreens().Peek();

            if (screen == null)
            {
                return(null);
            }

            var view = screen.View as PresentationFoundationView;

            if (view == null)
            {
                return(null);
            }

            return(view.ElementWithFocus as T);
        }
コード例 #2
0
        /// <summary>
        /// Destroys the specified test application.
        /// </summary>
        /// <param name="application">The test application to destroy.</param>
        protected static void DestroyUltravioletApplication(IUltravioletTestApplication application)
        {
            try
            {
                if (application != null)
                {
                    application.Dispose();
                }
            }
            catch (Exception e1)
            {
                try
                {
                    var context = (UltravioletContext)typeof(UltravioletContext).GetField("current",
                                                                                          BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
                    if (context != null)
                    {
                        context.Dispose();
                    }
                }
                catch (Exception e2)
                {
                    var error = new StringBuilder();
                    error.AppendLine($"An exception occurred while destroying the Ultraviolet application, and test framework failed to perform a clean teardown.");
                    error.AppendLine();
                    error.AppendLine($"Exception which occurred during cleanup:");
                    error.AppendLine();
                    error.AppendLine(e1.ToString());
                    error.AppendLine();
                    error.AppendLine($"Exception which occurred during teardown:");
                    error.AppendLine();
                    error.AppendLine(e2.ToString());

                    try
                    {
                        File.WriteAllText($"uv-test-error-{DateTime.Now:yyyy-MM-dd-HH-mm-ss-fff}.txt", error.ToString());
                    }
                    catch (IOException) { }
                }
                throw;
            }
        }
コード例 #3
0
        /// <summary>
        /// Destroys the specified test application.
        /// </summary>
        /// <param name="application">The test application to destroy.</param>
        protected static void DestroyUltravioletApplication(IUltravioletTestApplication application)
        {
            try
            {
                if (application != null)
                {
                    application.Dispose();
                }
            }
            catch (Exception e1)
            {
                try
                {
                    var context = (UltravioletContext)typeof(UltravioletContext).GetField("current",
                        BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
                    if (context != null)
                    {
                        context.Dispose();
                    }
                }
                catch (Exception e2)
                {
                    var error = new StringBuilder();
                    error.AppendLine($"An exception occurred while destroying the Ultraviolet application, and test framework failed to perform a clean teardown.");
                    error.AppendLine();
                    error.AppendLine($"Exception which occurred during cleanup:");
                    error.AppendLine();
                    error.AppendLine(e1.ToString());
                    error.AppendLine();
                    error.AppendLine($"Exception which occurred during teardown:");
                    error.AppendLine();
                    error.AppendLine(e2.ToString());

                    try
                    {
                        File.WriteAllText($"uv-test-error-{DateTime.Now:yyyy-MM-dd-HH-mm-ss-fff}.txt", error.ToString());
                    }
                    catch (IOException) { }
                }
                throw;
            }
        }
コード例 #4
0
 /// <summary>
 /// Destroys the specified test application.
 /// </summary>
 /// <param name="application">The test application to destroy.</param>
 protected static void DestroyUltravioletApplication(IUltravioletTestApplication application)
 {
     try
     {
         if (application != null)
         {
             application.Dispose();
         }
     }
     catch
     {
         var context = (UltravioletContext)typeof(UltravioletContext).GetField("current",
             BindingFlags.NonPublic | BindingFlags.Static).GetValue(null);
         if (context != null)
         {
             context.Dispose();
         }
         throw;
     }
 }
コード例 #5
0
 /// <summary>
 /// Wraps the element with keyboard focus for evaluation.
 /// </summary>
 /// <param name="app">The test application.</param>
 /// <returns>The wrapped element.</returns>
 protected ObjectResult <T> TheElementWithFocus <T>(IUltravioletTestApplication app) where T : UIElement
 {
     return(TheResultingObject(GetElementWithFocus <T>(app)));
 }
コード例 #6
0
 /// <summary>
 /// Wraps the element with keyboard focus for evaluation.
 /// </summary>
 /// <param name="app">The test application.</param>
 /// <returns>The wrapped element.</returns>
 protected ObjectResult <UIElement> TheElementWithFocus(IUltravioletTestApplication app)
 {
     return(TheResultingObject(GetElementWithFocus <UIElement>(app)));
 }
コード例 #7
0
 /// <summary>
 /// Specifies that the application should configure the Presentation Foundation.
 /// </summary>
 /// <returns>The Ultraviolet test application.</returns>
 public static IUltravioletTestApplication WithPresentationFoundationConfigured(this IUltravioletTestApplication @this)
 {
     return(@this.WithPlugin(new PresentationFoundationPlugin()));
 }