Skip to content

Instantly share code, notes, and snippets.

@tysonstewart
Created October 5, 2012 18:35
Show Gist options
  • Save tysonstewart/3841578 to your computer and use it in GitHub Desktop.
Save tysonstewart/3841578 to your computer and use it in GitHub Desktop.
Example of data source plugin for Visual Studio Webtests
using System.ComponentModel;
using Hudl.WebApp.Tests.TestsCore.DataSources;
using Microsoft.VisualStudio.TestTools.WebTesting;
namespace Hudl.WebApp.Tests.TestsCore.Plugins
{
[DisplayName("Annotations DataSource")]
[Description("Reads Annotation IDs from the context and assigns values to context parameters.")]
public class AnnotationsDataSourcePlugin : WebTestPlugin
{
[DisplayName("DataSource Context Parameter Name")]
[Description("The name of the context parameter which holds the DataSource object.")]
[DefaultValue("AnnotationsDataSource")]
public string DataSourceContextParameterName { get; set; }
[DisplayName("AnnotationId Context Parameter Name")]
[Description("The name of the context parameter which will be assigned the annotation ID value.")]
[DefaultValue("AnnotationId")]
public string AnnotationIdContextParameterName { get; set; }
public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
base.PreWebTest(sender, e);
var webTextContext = e.WebTest.Context;
var annotationsDataSource = webTextContext[DataSourceContextParameterName] as IDataSource<long>;
var annotationId = annotationsDataSource.GetNext();
webTextContext[AnnotationIdContextParameterName] = annotationId;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment