public void LocalPathWithoutQuery_SpecialCharactersDecodedCorrectly(string urlEnd, string expectedResult)
{
var listener = new HttpListener();
// Nothing special about 33579. It is a simply a random number we hope is unused.
// Note: if you get errors indicating the port is in use,
// it is likely the listener.Stop() line below wasn't called somehow.
var urlPrefix = "http://localhost:33579/";
listener.Prefixes.Add(urlPrefix);
var reqThread = new Thread(() =>
{
Thread.Sleep(100);
WebRequest req = WebRequest.Create(urlPrefix + urlEnd);
req.GetResponse();
});
reqThread.Start();
try
{
listener.Start();
var context = listener.GetContext(); // This waits for a request.
var requestInfo = new RequestInfo(context);
Assert.AreEqual(expectedResult, requestInfo.LocalPathWithoutQuery);
}
finally
{
listener.Stop();
reqThread.Join();
}
}