Last active
December 18, 2015 12:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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