A
download MyTest.cs
Language: C#
License: MSVSSDK
LOC: 98
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.
 
***************************************************************************/
//*************************************************************************************************
// MyTest.cs
//
// This file defines the MyTest test.
//
// Copyright(c) Microsoft Corporation, 2004
//*************************************************************************************************

namespace Microsoft.VisualStudio.TestTools.Samples
{
    using System;
    using System.ComponentModel;
    using System.Collections;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using System.Runtime.InteropServices;
    using Microsoft.VisualStudio.TestTools.Common;
    using Microsoft.VisualStudio.TestTools.Exceptions;
    using Microsoft.VisualStudio.TestTools.TestManagement;
    using Microsoft.VisualStudio.TestTools.Vsip;

    /// <summary>
    /// MyTest ITestElement implementation.
    /// Deriving from TestElement provides base implementations for many
    /// of the required methods.
    /// The important things to implement for your own test element are:
    /// - TestType with a GUID that uniquely identifies your test type.
    /// - Copy constructor that implements a deep copy for cloning.
    /// - Adapter property that returns the assembly and the class that
    ///   implements ITestAdapter for this test type.
    /// </summary>
    [Guid("3451566B-E89A-4b09-AC24-6CB67CFB8A04")]
    [Serializable]
    internal sealed class MyTest: TestElement, IHostedTest
    {
        #region TestType instance

        // Each test type has a GUID that identifies it.
        public static readonly Guid Guid = new Guid("3451566B-E89A-4b09-AC24-6CB67CFB8A04");
        public static readonly TestType MyTestType = new TestType(MyTest.Guid);

        #endregion

        #region Constructors

        /// <summary>
        /// Constructor. Needed for persistence only.
        /// </summary>
        private MyTest()
        {
        }

        /// <summary>
        /// Constructor used to create a new test element. This constructor is
        /// typically called from the TIP.
        /// </summary>
        /// <param name="name">The name of the test</param>
        /// <param name="desc">The description of the test</param>
        /// <param name="strCommandLine">The command line for this test</param>
        public MyTest(string name, string description, string commandLine) : base(name, description)
        {
            m_commandLine = commandLine;
        }

        /// <summary>
        /// Copy constructor. Useful for implementing the Clone method.
        /// </summary>
        /// <param name="copy">The MyTest to copy from</param>
        public MyTest(MyTest copy):base(copy)
        {
            m_commandLine = copy.m_commandLine;
            m_hostType = copy.m_hostType;
        }

        #endregion

        #region Properties

        /// <summary>
        /// The environment variable name of the process exit value for successful test.
        /// </summary>
        public const string PassedCodeVarName = "PassCode";

        /// <value>
        /// The Command Line to use for the test. This is the only
        /// Data specific to this Sample.
        /// </value>
        [UserVisibleProperty("{15B9F228-6FAF-4d06-848F-4E294EF192AC}")]
        [TestCaseManagementDisplayName(typeof(Properties.Resources), "CommandLineDisplayName")]
        [DefaultValue("")]
        public string CommandLine
        {
            get { return m_commandLine; }
            set { m_commandLine = value; }
        }

        #endregion

        #region TestElement overrides

        /// <value>
        /// Indicate whether this test element is read-only or not.
        /// </value>
        public override bool ReadOnly
        {
            get { return false; }
            set { throw new InvalidOperationException(); }
        }

        /// <value>
        /// Return the test type associated with this test element.
        /// </value>
        public override TestType TestType
        {
            get { return MyTestType; }
        }

        /// <summary>
        /// Because TestElements can eventually be handed off for execution,
        /// they must be capable of deep copies so that later edits don't
        /// mess up an in-progress execution.
        ///
        /// This means that all specific TestTypes (like UnitTest, Stress & Load Test, etc),
        /// must be capable of making independent clones of themselves. This interface is
        /// present to enforce this contract, but no default behavior is in place because there
        /// is no way for TestElement to instantiate a copy of itself (abstract class). 
        ///
        /// Nonetheless, a helper does exist for copying the methods of the TestElement class:
        /// the copy c'tor for this class. A derived class can create its own copy c'tor and 
        /// call the base c'tor during construction, and the appropriate methods will be copied.
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            return new MyTest(this);
        }

        /// <summary>
        /// Specify where the adapter for this test element is located.
        /// </summary>
        public override string Adapter
        {
            get { return typeof(MyTestAdapter).AssemblyQualifiedName; }
        }

        /// <summary>
        /// Indicate whether this test element can be aggregated by other types of test elements.
        /// One example of this is if this test element can be a part of an ordered test.
        /// </summary>
        /// <returns>True if this test element can be aggregated.</returns>
        public override bool CanBeAggregated
        {
            get { return true; }
        }

        /// <summary>
        /// Indicate whether this test element is a candidate for being included in a load test.
        /// </summary>
        /// <returns>True if this test element can be included in a load test.</returns>
        public override bool IsLoadTestCandidate
        {
            get { return true; }
        }

        /// <summary>
        /// TODO: Need a summary here.
        /// </summary>
        /// <value></value>
        public override string ControllerPlugin
        {
            get { return null; }
        }

        #endregion

        #region IHostedTest

        /// <summary>
        /// A string that describes the type of host the test should run in.
        /// For MyTest, the possible host type is "My Test".
        /// </summary>
        string IHostedTest.HostType
        {
            get
            {
                return m_hostType;
            }
            set
            {
                m_hostType = value;
            }
        }

        #endregion

        #region Private data

        // The command line is specific to this sample.
        // The [PersistenceElementName] is the XML element name that will be used
        // when tests of this type are persisted on disk (Results Files, VSMDI et al)
        [PersistenceElementName("CommandLine")]
        private string m_commandLine;
        [PersistenceElementName("HostType")]
        private string m_hostType;

        #endregion
    }
}

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