Test service hosting implementation.
Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the TestRun type.
 /// </summary>
 /// <param name="serviceOptions">The service options to use.</param>
 /// <param name="runOptions">The test run options to apply.</param>
 public TestRun(TestServiceOptions serviceOptions, TestRunOptions runOptions)
 {
     _testServiceOptions = serviceOptions;
     TestService         = new TestService(_testServiceOptions);
     Options             = runOptions;
 }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the TestRun type.
 /// </summary>
 /// <param name="serviceOptions">The service options to use.</param>
 /// <param name="runOptions">The test run options to apply.</param>
 public TestRun(TestServiceOptions serviceOptions, TestRunOptions runOptions)
 {
     _testServiceOptions = serviceOptions;
     TestService = new TestService(_testServiceOptions);
     Options = runOptions;
 }
        public bool Run()
        {
            try
            {
                Failures = -1;
                string page = Options.Page;
                string path = Options.LocalPath;
                if (File.Exists(path))
                {
                    FileInfo fi = new FileInfo(path);
                    TestService.RootDirectory = fi.DirectoryName;
                    page = fi.Name;
                }
                else if (Directory.Exists(path))
                {
                    TestService.RootDirectory = path;
                    if (!File.Exists(Path.Combine(path, page)))
                    {
                        page = string.Empty;
                    }
                }
                TestService.TestRunPrefix = Options.Browser.ToString();
                TestService.Start();
                if (!string.IsNullOrEmpty(Options.TagExpression))
                {
                    TestService.TagExpression = Options.TagExpression;
                }
                if (!string.IsNullOrEmpty(Options.Log))
                {
                    TestService.LogFile = Options.Log;
                }

                WebBrowser = Options.BrowserInstance != null ? Options.BrowserInstance : WebBrowserFactory.Create(Options.Browser);

                Uri uri = new Uri(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        StandardLocalHostingUrl,
                        _testServiceOptions.MachineName,
                        _testServiceOptions.Port,
                        page,
                        Options.RunId));

                WebBrowser.Start(uri);

                while (TestService.IsRunning && WebBrowser.IsRunning && TestService.Result == null)
                {
                    Thread.Sleep(TimeSpan.FromMilliseconds(PollingThreadSleepMilliseconds));
                }

                TestRunResult result = TestService.Result;
                if (result != null)
                {
                    Total    = result.Total;
                    Log      = result.Log;
                    Failures = result.Failures;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                Thread.Sleep(TimeSpan.FromMilliseconds(FinalSleepDelayMilliseconds));
                WebBrowser.Close();
                TestService.Stop();
            }
            return(Failures == 0);
        }