WebServicePostRecording.cs 2.58 KB
//*************************************************************************************************
// WebServicePostRecording.cs
// Owner: Mahipal Kante
//
// WebTestRecorderPlugin Implementation:
// Web Test Plugin for adding references to the other Web Service plugins
// (Extraction/Validation rules etc) to the WebTest after completing recording. 
// This gets executed if user selects the plugin in the dialog that gets displayed 
// before a record session.
//
// Copyright(c) Microsoft Corporation, 2010
//*************************************************************************************************
using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.WebTesting;
using System.Diagnostics.CodeAnalysis;
using WebTest.WebService.Plugin.ResultTab;
using WebTest.WebService.Plugin.Runtime;

namespace WebTest.WebService.Plugin.MessageEditors
{
    [DisplayName("Plugin for Web Service Messages")]
    [Description("XPath extraction/validation rules that extract data from Web Service responses for various content types")]
    class WebServicePostRecording : WebTestRecorderPlugin
    {
        /// <summary>
        /// Parameters:
        ///   sender:
        ///     The source of the event.
        ///
        ///   e:
        ///     A Microsoft.VisualStudio.TestTools.WebTesting.PostWebTestRecordingEventArgs
        ///    that contains the event data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        [SuppressMessage("Microsoft.Security", "CA2109:ReviewVisibleEventHandlers")]
        public override void PostWebTestDynamicParameterDetection(object sender, PostWebTestRecordingEventArgs e)
        {
            Connect connect = Connect.GetInstance();
            if (connect != null)
            {
                connect.AddWebTestRecording(e.RecordedWebTest);
            }

            bool pluginFound = false;
            foreach (WebTestPluginReference pluginReference1 in e.RecordedWebTest.WebTestPluginReferences)
            {
                if (pluginReference1.Type.ToString().Equals(typeof(WebServicePlugin).ToString()))
                {
                    pluginFound = true;
                    break;
                }
            }

            if (!pluginFound)
            {
                WebTestPluginReference pluginReference = new WebTestPluginReference();
                pluginReference.Type = typeof(WebServicePlugin);
                e.RecordedWebTest.WebTestPluginReferences.Add(pluginReference);
            }

            // Mark it as modified
            e.RecordedWebTestModified = true;
        }
    }
}