Example #1
0
        /// <summary>
        /// Thread worker that creates the AutomatedApplication implementation and
        /// starts the application. If InProcessSeparateThreadAndAppDomain is specified
        /// then the AutomatedApplication implementation is created in a new AppDomain.
        /// </summary>
        private void ApplicationStartWorker()
        {
            AppDomain testAppDomain = null;

            if (ApplicationSettings.InProcessApplicationType == InProcessApplicationType.InProcessSeparateThreadAndAppDomain)
            {
                var setup = new AppDomainSetup();
                setup.ApplicationBase     = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                testAppDomain             = AppDomain.CreateDomain("Automated Application Domain", null, setup);
                ApplicationImplementation = ApplicationSettings.ApplicationImplementationFactory.Create(ApplicationSettings, testAppDomain);
            }
            else
            {
                ApplicationImplementation = ApplicationSettings.ApplicationImplementationFactory.Create(ApplicationSettings, null);
            }

            ApplicationImplementation.MainWindowOpened += this.OnMainWindowOpened;
            ApplicationImplementation.Exited           += this.OnExit;
            ApplicationImplementation.FocusChanged     += this.OnFocusChanged;
            ApplicationImplementation.Start();

            if (testAppDomain != null)
            {
                // run has completed, now unload this appdomain
                AppDomain.Unload(testAppDomain);
                testAppDomain             = null;
                ApplicationImplementation = null;
            }
        }
Example #2
0
        /// <summary>
        /// Creates and starts the test application.
        /// </summary>
        /// <remarks>
        /// Depending on the AutomatedApplicationType
        /// this can be on the same thread or on a separate thread.
        /// </remarks>
        public override void Start()
        {
            if (IsApplicationRunning)
            {
                throw new InvalidOperationException("Cannot start an application instance if it is already running.");
            }

            IsApplicationRunning = true;

            if (ApplicationSettings.InProcessApplicationType == InProcessApplicationType.InProcessSeparateThread ||
                ApplicationSettings.InProcessApplicationType == InProcessApplicationType.InProcessSeparateThreadAndAppDomain)
            {
                var mainApplicationThread = new Thread(ApplicationStartWorker);
                mainApplicationThread.SetApartmentState(ApartmentState.STA);
                mainApplicationThread.Start();
            }
            else if (ApplicationSettings.InProcessApplicationType == InProcessApplicationType.InProcessSameThread)
            {
                ApplicationImplementation = ApplicationSettings.ApplicationImplementationFactory.Create(ApplicationSettings, null);
                ApplicationImplementation.MainWindowOpened += this.OnMainWindowOpened;
                ApplicationImplementation.Exited           += this.OnExit;
                ApplicationImplementation.FocusChanged     += this.OnFocusChanged;
                ApplicationImplementation.Start();
            }
            else
            {
                throw new InvalidOperationException(string.Format(
                                                        CultureInfo.CurrentCulture,
                                                        "Unable to start automated application with AutomatedApplicationType: {0}",
                                                        ApplicationSettings.InProcessApplicationType));
            }
        }
Example #3
0
        /// <summary>
        /// Creates and starts the automated application.
        /// </summary>
        public override void Start()
        {
            if (IsApplicationRunning)
            {
                throw new InvalidOperationException("Cannot start an application instance if it is already running.");
            }

            IsApplicationRunning      = true;
            ApplicationImplementation = ApplicationSettings.ApplicationImplementationFactory.Create(ApplicationSettings, null);
            ApplicationImplementation.MainWindowOpened += this.OnMainWindowOpened;
            ApplicationImplementation.FocusChanged     += this.OnFocusChanged;
            ApplicationImplementation.Exited           += this.OnExit;
            ApplicationImplementation.Start();
        }
Example #4
0
        /// <summary>
        /// Thread worker that creates the AutomatedApplication implementation and
        /// starts the application. If InProcessSeparateThreadAndAppDomain is specified
        /// then the AutomatedApplication implementation is created in a new AppDomain.
        /// </summary>
        private void ApplicationStartWorker()
        {
            AppDomain testAppDomain = null;

            //



            ApplicationImplementation = ApplicationSettings.ApplicationImplementationFactory.Create(ApplicationSettings, null);
            //}

            ApplicationImplementation.MainWindowOpened += this.OnMainWindowOpened;
            ApplicationImplementation.Exited           += this.OnExit;
            ApplicationImplementation.FocusChanged     += this.OnFocusChanged;
            ApplicationImplementation.Start();

            if (testAppDomain != null)
            {
                // run has completed, now unload this appdomain
                AppDomain.Unload(testAppDomain);
                testAppDomain             = null;
                ApplicationImplementation = null;
            }
        }