コード例 #1
0
    /// <summary>
    /// Creates a new TestPage visual that in turn will setup and begin a 
    /// unit test run.
    /// </summary>
    /// <param name="settings">Test harness settings to be applied.</param>
    /// <returns>A new RootVisual.</returns>
    /// <remarks>Assumes the calling assembly is a test assembly.</remarks>
    public static UIElement CreateTestPage(UnitTestSettings settings)
    {
      UnitTestSystem system = new UnitTestSystem();

      Type testPageType = typeof(TestPage);

      Type testPageInterface = typeof(ITestPage);
      if (settings.TestPanelType != null && testPageInterface.IsAssignableFrom(settings.TestPanelType))
      {
        testPageType = settings.TestPanelType;
      }

      object testPage;
      try
      {
        // Try creating with an instance of the test harness
        testPage = Activator.CreateInstance(testPageType, settings.TestHarness);
      }
      catch
      {
        // Fall back to a standard instance only
        testPage = Activator.CreateInstance(testPageType);
      }

      PrepareTestService(settings, () => system.Run(settings));

      // NOTE: A silent failure would be if the testPanel is not a
      // UIElement, and it returns anyway.
      return testPage as UIElement;
    }
コード例 #2
0
    public void Run(UnitTestSettings settings)
    {
      // Avoid having the Run method called twice
      if (_harness != null)
      {
        return;
      }

      _harness = settings.TestHarness;
      if (_harness == null)
      {
        throw new InvalidOperationException(Properties.UnitTestMessage.UnitTestSystem_Run_NoTestHarnessInSettings);
      }

      if (settings.TestService == null && !settings.TestServiceSetterCalled)
      {
        SetTestService(settings);
      }

      _harness.Settings = settings;
      _harness.TestHarnessCompleted += (sender, args) => OnTestHarnessCompleted(args);

      if (settings.StartRunImmediately)
      {
        _harness.Run();
      }
    }
コード例 #3
0
 /// <summary>
 /// A partial method for PrepareDefaultLogManager.
 /// </summary>
 /// <param name="settings">The test harness settings.</param>
 public static void PrepareCustomLogProviders(UnitTestSettings settings)
 {
   // TODO: Consider what to do on this one...
   // Should probably update to use the newer log system with events,
   // and then after that figure out when it applies... perhaps only
   // when someone first requests to use it.
   ////if (HtmlPage.IsEnabled)
   ////{
   ////settings.LogProviders.Add(new TextFailuresLogProvider());
   ////}
 }
コード例 #4
0
        /// <summary>
        /// Initializes the test service and its contained providers.
        /// </summary>
        /// <param name="inputSettings">The run settings.</param>
        /// <param name="complete">Action to call once the test service is
        /// initialized and ready to continue the run's execution.</param>
        private static void PrepareTestService(UnitTestSettings inputSettings, Action complete)
        {
            TestServiceProvider testService = inputSettings.TestService;

            if (testService != null && testService.Initialized == false)
            {
                Action after = delegate
                {
                    MergeSettingsAndParameters(testService, inputSettings);
                    complete();
                };
                testService.InitializeCompleted += delegate(object sender, EventArgs e) { after(); };
                testService.Initialize();
            }
            else
            {
                complete();
            }
        }
コード例 #5
0
        /// <summary>
        /// Tries to instantiate and initialize a VSTT provider. Requires that
        /// XLinq is available and included in the application package.
        /// </summary>
        /// <param name="settings">The test harness settings object.</param>
        private static void TryAddVisualStudioLogProvider(UnitTestSettings settings)
        {
            VisualStudioLogProvider trx = new VisualStudioLogProvider();

            settings.LogProviders.Add(trx);
        }
コード例 #6
0
 /// <summary>
 /// Create a default settings object for unit testing.
 /// </summary>
 /// <param name="callingAssembly">The assembly reflection object.</param>
 /// <returns>A unit test settings instance.</returns>
 private static UnitTestSettings CreateDefaultSettings(Assembly callingAssembly)
 {
   UnitTestSettings settings = new UnitTestSettings();
   if (callingAssembly != null)
   {
     settings.TestAssemblies.Add(callingAssembly);
   }
   SetStandardLogProviders(settings);
   settings.TestHarness = new UnitTestHarness();
   // Sets initial but user can override
   SetTestService(settings);
   return settings;
 }
コード例 #7
0
 /// <summary>
 /// Tries to instantiate and initialize a VSTT provider. Requires that 
 /// XLinq is available and included in the application package.
 /// </summary>
 /// <param name="settings">The test harness settings object.</param>
 private static void TryAddVisualStudioLogProvider(UnitTestSettings settings)
 {
   VisualStudioLogProvider trx = new VisualStudioLogProvider();
   settings.LogProviders.Add(trx);
 }
コード例 #8
0
    /// <summary>
    /// Prepares the default log manager.
    /// </summary>
    /// <param name="settings">The test harness settings.</param>
    public static void SetStandardLogProviders(UnitTestSettings settings)
    {
      // Debug provider
      DebugOutputProvider debugger = new DebugOutputProvider();
      debugger.ShowAllFailures = true;
      settings.LogProviders.Add(debugger);

      // Visual Studio log provider
      try
      {
        TryAddVisualStudioLogProvider(settings);
      }
      catch
      {
      }

      PrepareCustomLogProviders(settings);
    }
コード例 #9
0
        /// <summary>
        /// Creates a new TestPage visual that in turn will setup and begin a
        /// unit test run.
        /// </summary>
        /// <returns>A new RootVisual.</returns>
        /// <remarks>Assumes the calling assembly is a test assembly.</remarks>
        public static UIElement CreateTestPage()
        {
            UnitTestSettings settings = CreateDefaultSettings(Assembly.GetCallingAssembly());

            return(CreateTestPage(settings));
        }
コード例 #10
0
 /// <summary>
 /// A partial method for setting the TestService.
 /// </summary>
 /// <param name="settings">The test harness settings.</param>
 public static void SetTestService(UnitTestSettings settings)
 {
     // REVIEW Following line commented because TestService need to be reviewed.
     //settings.TestService = new WindowsPhoneTestService(settings);
 }
コード例 #11
0
 /// <summary>
 /// Merge any settings provided by a test service with the parameters
 /// that were passed inside the TestHarnessSettings.
 /// </summary>
 /// <param name="testService">The test service.</param>
 /// <param name="inputSettings">The run settings.</param>
 private static void MergeSettingsAndParameters(TestServiceProvider testService, UnitTestSettings inputSettings)
 {
     if (testService != null && testService.HasService(TestServiceFeature.RunSettings))
     {
         SettingsProvider settings = testService.GetService <SettingsProvider>(TestServiceFeature.RunSettings);
         foreach (string key in settings.Settings.Keys)
         {
             if (inputSettings.Parameters.ContainsKey(key))
             {
                 Debug.WriteLine("MergeSettingsAndParameters: Overwriting " + key + " key during merge.");
             }
             inputSettings.Parameters[key] = settings.Settings[key];
         }
     }
 }
コード例 #12
0
 /// <summary>
 /// A partial method for setting the TestService.
 /// </summary>
 /// <param name="settings">The test harness settings.</param>
 public static void SetTestService(UnitTestSettings settings)
 {
   // REVIEW Following line commented because TestService need to be reviewed.
   //settings.TestService = new WindowsPhoneTestService(settings);
 }
コード例 #13
0
 /// <summary>
 /// Initializes the test service and its contained providers.
 /// </summary>
 /// <param name="inputSettings">The run settings.</param>
 /// <param name="complete">Action to call once the test service is 
 /// initialized and ready to continue the run's execution.</param>
 private static void PrepareTestService(UnitTestSettings inputSettings, Action complete)
 {
   TestServiceProvider testService = inputSettings.TestService;
   if (testService != null && testService.Initialized == false)
   {
     Action after = delegate
     {
       MergeSettingsAndParameters(testService, inputSettings);
       complete();
     };
     testService.InitializeCompleted += delegate(object sender, EventArgs e) { after(); };
     testService.Initialize();
   }
   else
   {
     complete();
   }
 }
コード例 #14
0
 /// <summary>
 /// Merge any settings provided by a test service with the parameters 
 /// that were passed inside the TestHarnessSettings.
 /// </summary>
 /// <param name="testService">The test service.</param>
 /// <param name="inputSettings">The run settings.</param>
 private static void MergeSettingsAndParameters(TestServiceProvider testService, UnitTestSettings inputSettings)
 {
   if (testService != null && testService.HasService(TestServiceFeature.RunSettings))
   {
     SettingsProvider settings = testService.GetService<SettingsProvider>(TestServiceFeature.RunSettings);
     foreach (string key in settings.Settings.Keys)
     {
       if (inputSettings.Parameters.ContainsKey(key))
       {
         Debug.WriteLine("MergeSettingsAndParameters: Overwriting " + key + " key during merge.");
       }
       inputSettings.Parameters[key] = settings.Settings[key];
     }
   }
 }