Exemple #1
0
 private static void TestBasicSqlPadBehavior(VisualTestContext context)
 {
     try
     {
         AssertBasicSqlPadBehavior();
     }
     finally
     {
         Editor.IsModified = false;
     }
 }
 private static void TestMethodWrapper(VisualTestContext context)
 {
     try
     {
         context.TestMethodInfo.Invoke(null, new object[] { context });
     }
     catch (Exception e)
     {
         throw new ApplicationException(e.ToString());
     }
     finally
     {
         context.Application.Shutdown();
     }
 }
        private static void RunSqlPad()
        {
            var app = new App();

            app.InitializeComponent();

            var tempDirectoryName = TestFixture.SetupTestDirectory();

            ConfigurationProvider.SetUserDataFolder(tempDirectoryName);

            var sqlPadDirectory = Path.GetDirectoryName(new Uri(typeof(Snippets).Assembly.CodeBase).LocalPath);

            ConfigurationProvider.SetSnippetsFolder(Path.Combine(sqlPadDirectory, Snippets.SnippetDirectoryName));
            ConfigurationProvider.SetCodeGenerationItemFolder(Path.Combine(sqlPadDirectory, Snippets.CodeGenerationItemDirectoryName));
            DocumentPage.IsParsingSynchronous = true;

            var testClassName = (string)AppDomain.CurrentDomain.GetData(DomainParameterTestClassName);
            var testClassType = Type.GetType(testClassName);

            if (testClassType == null)
            {
                throw new ArgumentException($"Test class '{testClassName}' was not found. ");
            }

            var testMethodName = (string)AppDomain.CurrentDomain.GetData(DomainParameterTestMethodName);
            var testMethodInfo = testClassType.GetMethod(testMethodName, BindingFlags.Static | BindingFlags.NonPublic);

            if (testMethodInfo == null)
            {
                throw new ArgumentException($"Test method '{testMethodName}' was not found. ");
            }

            var testContext =
                new VisualTestContext
            {
                Application            = app,
                TestTemporaryDirectory = tempDirectoryName,
                TestMethodInfo         = testMethodInfo
            };

            app.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action <VisualTestContext>(TestMethodWrapper), testContext);
            app.Run();

            Directory.Delete(tempDirectoryName, true);
        }