WebTestPlugin: AddDaysToCurrentDate

A simple WebTestPlugin that Adds specified number of days to the current date.

[Description("WebTestPlugin that adds a specified number of days to the current date and stores the new date in a Context Parameter that you specify. Overrides PreWebTest")]

public class AddDaysToCurrentDate : WebTestPlugin

{

public AddDaysToCurrentDate()

{

DaysToAdd = 1;

ContextParameterName = "FutureDate";

}

public override void PreWebTest(object sender, PreWebTestEventArgs e)

{

//TODO: Adjust the date format to obtain output needed. Search C# DateTime.Now Formats for examples and msdn documentation

//Example: FutureDate=Saturday, August 18, 10:49:21, 2012

//e.WebTest.Context[ContextParameterName] = DateTime.Now.AddDays(DaysToAdd).ToString("dddd, MMMM dd, HH:mm:ss, yyyy");

e.WebTest.Context[ContextParameterName] = DateTime.Now.AddDays(DaysToAdd).ToString();

}

[Description("Number of days to add to the current date. Default value is 1.")]

[DefaultValue(1)]

public double DaysToAdd { get; set; }

[Description("Context Parameter that will hold the new date value. Default value is 'FutureDate'.")]

[DefaultValue("FutureDate")]

public string ContextParameterName { get; set; }

}