How do I automate a web proxy in .NET for unit tests (including set up and tear down)?

女生的网名这么多〃 提交于 2019-12-11 07:09:39

问题


Following Jonathan Holland's suggestion in his comment for my previous question: Is there any way in .NET to programmatically listen to HTTP traffic? I've made a separate (but not exactly a duplicate) question for what I really want to know:

How do I automate a web proxy in .NET for unit tests (including set up and tear down) for spying on HTTP traffic that comes from the browser (particularly images, scripts, and XmlHttpRequests on the requested page)?

I prefer to have zero set-up (so no Fiddler installed on Windows) where everything can be unpacked from an assembly, deployed, and then removed without a trace, so to speak.


回答1:


WebAii 2.0 has a built-in HTTP proxy:

http://www.artoftest.com/community/blogs/09-03-25/WebAii_2_0_Beta_Released.aspx




回答2:


Roll your own pass-through proxy, then have your test harness issue configuration commands on the admin port of the proxy. The proxy will dutifully route any normal connection to the specified ip:port, with minimal "setup."




回答3:


If you want to take control of a browser-like request and look at requests and headers from a stimulated web browser to your localhost, you can use System.Net.WebClient

If you want a .NET solution, where you use complete proxy detection, then have a look at this MSDN article: http://msdn.microsoft.com/en-us/magazine/cc300743.aspx. It explains how to integrate with a proxy like Fiddler

Before using any of these solutions, I strongly recommend that you review your unit tests and what you're trying to accomplish. A full proxy solution is often times out of the scope of unit tests and you may want to scale your tests down a bit.

However, if you are writing integration tests, then these solutions should serve you well.




回答4:


I'm not sure if it's what you're looking for, but here is an example of ASP.NET unit testing using selenium. http://www.stevetrefethen.com/blog/AutomatedTestingOfASPNETWebApplicationsUsingSelenium.aspx



来源:https://stackoverflow.com/questions/137425/how-do-i-automate-a-web-proxy-in-net-for-unit-tests-including-set-up-and-tear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!