download MyTestWizard.cs
Language: C#
License: MSVSSDK
LOC: 70
Project Info
C# Example.MyTestTypeSample
Server: Visual Studio SDK
Type: filesystem
...xtensibility\MyTest\MyTest\
   assembly.cs
   MyHostAdapter.cs
   ...pterRunConfigControl.cs
   ...nfigControl.Designer.cs
   ...erRunConfigControl.resx
   MyTest.cs
   MyTest.csproj
   MyTestAdapter.cs
   MyTestAssertHelper.cs
   MyTestEditorControl.cs
   ...itorControl.Designer.cs
   MyTestEditorControl.resx
   MyTestEditorFactory.cs
   MyTestPackage.cs
   MyTestResourceIds.cs
   MyTestResult.cs
   MyTestResultViewControl.cs
   ...ViewControl.designer.cs
   ...tResultViewControl.resx
   MyTestResultViewWindow.cs
   MyTestRunConfigControl.cs
   ...nfigControl.Designer.cs
   ...stRunConfigControl.resx
   MyTestTip.cs
   MyTestTuip.cs
   MyTestWizard.cs

/***************************************************************************
 
Copyright (c) Microsoft Corporation. All rights reserved.
This code is licensed under the Visual Studio SDK license terms.
THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
 
***************************************************************************/
//*************************************************************************************************
// MyTestWizard.cs
//
// This file defines the MyTest wizard for creating new tests.
//
// Copyright(c) Microsoft Corporation, 2004
//*************************************************************************************************

namespace Microsoft.VisualStudio.TestTools.Samples
{
	using System;
	using System.Diagnostics;
	using System.Diagnostics.CodeAnalysis;
	using System.IO;
	using System.Reflection;
	using System.Globalization;
	using System.Runtime.InteropServices;
	using System.Windows.Forms;

	using Microsoft.VisualStudio.TemplateWizard;

	/// <summary>
	/// MyTest wizard implementation. This class executes a wizard
	/// when the user selects that item in the new test dialog.
	/// This is through implementing the IWizard interface.
	/// Useing the VSTemplate file in your project items, you specify
	/// the assembly & class that is to be used for the wizards -- these
	/// files should point to this class & assembly.
	/// </summary>
	// Suppress AvoidUninstantiatedInternalClasses.
	// MyTestWizard is created late-bound.
	[SuppressMessage("Microsoft.Performance", "CA1812")]
	internal sealed class MyTestWizard : IWizard
	{
		#region IWizard implementation

		/// <summary>
		/// This method is called when the wizard is started.
		/// It provides an oppertunity to accept additional parameters
		/// from the Test Items dialog.
		/// </summary>
		/// <param name="automationObject">The EnvDTE object for the IDE which is invoking the wizard</param>
		/// <param name="replacementsDictionary">
		/// The replacements that will take place in this template/wizard combination. Assigning a value to
		/// the key in this will ensure that value is replace in the template
		/// </param>
		/// <param name="runKind">The type of run - project, item</param>
		/// <param name="customParams">Any custom paramters you may have setup for the wizard</param>
		public void RunStarted(object automationObject, System.Collections.Generic.Dictionary<string, string> replacementsDictionary, WizardRunKind runKind, object[] customParams)
		{
			// Get the automation object we're going to use
			m_automation = automationObject as EnvDTE._DTE;
			MyTestAssertHelper.ParameterNotNull(automationObject, "automationObject");

			// There must be an active project to add this test to.
			m_project = ActiveProject;
			if (m_project == null)
				throw new WizardCancelledException();

			// Let the user choose the EXE to launch for this test
			// by showing them the open file dialog, filtered to EXEs
			OpenFileDialog dlg = new OpenFileDialog();
			dlg.Title = Properties.Resources.ChooseEXEDialogTitle;
			dlg.Filter = Properties.Resources.ChoosEXEFilter;
			
			// The user Selected a file correctly
			if (dlg.ShowDialog() == DialogResult.OK)
			{
				replacementsDictionary["$exe-to-launch$"] = dlg.FileName;
			}
			else
			{
				// If the wizard is cancelled, throw this exception.
				throw new WizardBackoutException();
			}
		}

		public void ProjectFinishedGenerating(EnvDTE.Project project)
		{ }

		public void ProjectItemFinishedGenerating(EnvDTE.ProjectItem projectItem)
		{ }

		/// <summary>
		/// If the wizard should use the normal template relacement technique
		/// this method should return true for the path passed in/
		/// </summary>
		/// <param name="filePath">Path for which the item is querying</param>
		/// <returns>True to use normal technique, false otherwise</returns>
		public bool ShouldAddProjectItem(string filePath)
		{ return true;	}

		public void BeforeOpeningFile(EnvDTE.ProjectItem projectItem)
		{ }

		public void RunFinished()
		{ }

		#endregion

		#region Helpers

		/// <summary>
		/// Property for the automation object.
		/// </summary>
		private EnvDTE._DTE Automation
		{ get { return m_automation; }	}

		/// <summary>
		/// Return the selected project that is the target project in the solution explorer.
		/// There should only be one active project, so assert if there is == 1.
		/// </summary>
		private EnvDTE.Project ActiveProject
		{
			get
			{
				EnvDTE.Project activeProject = null;
				Array projects = Automation.ActiveSolutionProjects as Array;

				if (projects != null && projects.Length > 0)
				{
					// For adding new test, only one project should be selected
					Debug.Assert(projects.Length == 1);
					activeProject = projects.GetValue(0) as EnvDTE.Project;
					Debug.Assert(activeProject != null, "Active project is null or type-wrong.");
				}
				return activeProject;
			}
		}

		#endregion

		#region Private data

		private EnvDTE._DTE m_automation;
		private EnvDTE.Project m_project;

		#endregion
	}
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us