Skip to content

Instantly share code, notes, and snippets.

@ridomin
Last active December 18, 2015 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ridomin/5781078 to your computer and use it in GitHub Desktop.
Save ridomin/5781078 to your computer and use it in GitHub Desktop.
SkipExternals allows you to skip dependant requests that are not in your domain. You have to specify the inclueded domain as a contextParameter
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.WebTesting;
namespace IntegrationTests
{
public class SkipExternals : WebTestRequestPlugin
{
public override void PostRequest(object sender, PostRequestEventArgs e)
{
SkipExternalsUrls(e);
}
private void SkipExternalsUrls(PostRequestEventArgs e)
{
Uri baseUri = new Uri((string)e.WebTest.Context["targetServer"]);
List<WebTestRequest> toRemove = new List<WebTestRequest>();
foreach (WebTestRequest r in e.Request.DependentRequests)
{
Uri currentUri = new Uri(r.Url);
if (baseUri.DnsSafeHost != currentUri.DnsSafeHost)
{
toRemove.Add(r);
}
}
foreach (WebTestRequest wtr in toRemove)
{
e.Request.DependentRequests.Remove(wtr);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment