/// <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;
            }
        }
Ejemplo n.º 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;
            }
        }
 /// <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;
     }
 }