Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andriybuday/3c084106811b220c8a74 to your computer and use it in GitHub Desktop.
Save andriybuday/3c084106811b220c8a74 to your computer and use it in GitHub Desktop.
using System;
using Microsoft.VisualStudio.TestTools.WebTesting;
namespace YourAppLoadTesting
{
public class AddCorrelationIdToReportPutRequest: WebTestPlugin
{
public string ApplyToRequestsThatContain { get; set; }
public string BodyStringParam { get; set; }
public override void PreRequest(object sender, PreRequestEventArgs e)
{
if (e.Request.Url.Contains(ApplyToRequestsThatContain) && e.Request.Method == "PUT")
{
var requestBody = new StringHttpBody();
requestBody.ContentType = "application/json; charset=utf-8";
requestBody.InsertByteOrderMark = false;
requestBody.BodyString = e.WebTest.Context[BodyStringParam].ToString().Replace("\"correlationId\":null",
string.Format("\"correlationId\":\"{0}\\\\0\"", Guid.NewGuid()));
e.Request.Body = requestBody;
}
base.PreRequest(sender, e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment