A
download MyTestRunConfigControl.cs
Language: C#
License: MSVSSDK
LOC: 129
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.
 
***************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Diagnostics;
using System.Windows.Forms;
using Microsoft.VisualStudio.TestTools.Common;
using Microsoft.VisualStudio.TestTools.Vsip;

namespace Microsoft.VisualStudio.TestTools.Samples
{
    /// <summary>
    /// UI control for my test run configuartion. Hosted inside test run config editor.
    /// </summary>
    public partial class MyTestRunConfigControl : UserControl, IRunConfigurationCustomEditor
    {
        #region Private Data

        MyTestRunConfig m_config = new MyTestRunConfig();

        #endregion

        #region Contructor

        public MyTestRunConfigControl()
        {
            InitializeComponent();
            foreach (ProcessWindowStyle style in Enum.GetValues(typeof(ProcessWindowStyle)))
            {
                m_windowStyleComboBox.Items.Add(style);
            }
            m_windowStyleComboBox.SelectedItem = m_config.WindowStyle;
            m_windowStyleComboBox.SelectedIndexChanged += new EventHandler(WindowStyleComboBox_SelectedIndexChanged);
        }

        #endregion

        #region Event Handlers

        void WindowStyleComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            m_config.WindowStyle = (ProcessWindowStyle)m_windowStyleComboBox.SelectedItem;
            // Report dirty event so that the editor knows we need to save it.
            if (null != DataGetDirty)
            {
                DataGetDirty(this, EventArgs.Empty);
            }
        }

        #endregion

        #region IRunConfigurationEditor

        /// <summary>
        /// Initialize the editor to a default state based on given test run.
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <param name="run">Obselete. Always null.</param>
        void IRunConfigurationEditor.Initialize(System.IServiceProvider serviceProvider, TestRun run)
        {
            // Nothing to do here.
        }


        /// <summary>
        /// Fire this event when data are modified in this editor.
        /// </summary>
        public event EventHandler DataGetDirty;


        /// <summary>
        /// Handle the event that core (non-host and not-test-specific) run config data are modified outside this editor.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="dirtyEventArgs">contains run config object that is changed outside</param>
        void IRunConfigurationEditor.OnCommonDataDirty(object sender, CommonRunConfigurationDirtyEventArgs dirtyEventArgs)
        {
            // My test config does not depend on other data contained in the run config.
        }


        /// <summary>
        /// Desciption about this editor is displayed in the help panel of the main run config editor.
        /// </summary>
        string IRunConfigurationEditor.Description
        {
            get
            {
                return "Test run config for my test type.";
            }
        }


        /// <summary>
        /// The keyword that is hooked up with the help topic.
        /// </summary>
        string IRunConfigurationEditor.HelpKeyword
        {
            get
            {
                return null;
            }
        }


        /// Verify the data in the editor. Prompt the user when neccessary.
        /// </summary>
        /// <returns>true if the data are correct and don't need correction; otherwise, false.</returns>
        bool IRunConfigurationEditor.VerifyData()
        {
            // The following code shows how to verify data.
            if (m_config.WindowStyle == ProcessWindowStyle.Hidden)
            {
                MessageBox.Show("This is just to demonstrate how to verify test-type-specific run config.\r\n\r\nHidden style does not work for my test type. Please choose another one.");
                return false;
            }
            else
            {
                return true;
            }
        }


        #endregion

        #region IRunConfigurationCustomEditor


        /// <summary>
        /// The test type that this editor is for.
        /// </summary>
        TestType IRunConfigurationCustomEditor.TestType
        {
            get
            {
                return MyTest.MyTestType;
            }
        }

        /// <summary>
        /// Called by editor to load existing my test config into this control.
        /// </summary>
        /// <param name="data"></param>
        void IRunConfigurationCustomEditor.SetData(ITestTypeSpecificRunConfigurationData data)
        {
            MyTestRunConfig config = (MyTestRunConfig)data;
            m_config = config;
            m_windowStyleComboBox.SelectedItem = config.WindowStyle;
        }


        /// <summary>
        /// Called by editor to get the current my test config from this control.
        /// </summary>
        /// <returns></returns>
        ITestTypeSpecificRunConfigurationData IRunConfigurationCustomEditor.GetData()
        {
            return m_config;
        }

        #endregion
    }


    /// <summary>
    /// Test run level configuration information of my test type.
    /// The information is accessible to my test adapter.
    /// Must be Serializable.
    /// </summary>
    [Serializable]
    public class MyTestRunConfig : ITestTypeSpecificRunConfigurationData, ICloneable
    {
        #region Private Data

        private ProcessWindowStyle m_windowStyle = ProcessWindowStyle.Normal;

        #endregion

        #region Properties

        /// <summary>
        /// The window style in which the exe process will be launched for my test type.
        /// </summary>
        public ProcessWindowStyle WindowStyle
        {
            get
            {
                return m_windowStyle;
            }
            set
            {
                m_windowStyle = value;
            }
        }

        string ITestTypeSpecificRunConfigurationData.RunConfigurationInformation
        {
            get
            {
                return m_windowStyle.ToString();;
            }
        }

        #endregion

        #region ICloneable

        object ICloneable.Clone()
        {
            MyTestRunConfig copy = new MyTestRunConfig();
            copy.WindowStyle = m_windowStyle;
            return copy;
        }

        #endregion
    }
}

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