Ejemplo n.º 1
0
        public void TestRemovingCachedHeaders()
        {
            //setup a mock web server

            TrafficViewerFile serverdataStore = new TrafficViewerFile();

            serverdataStore.Profile.SetExclusions(new string[0] {
            });
            TrafficViewerFile mockSiteData = new TrafficViewerFile();
            string            testRequest  = "GET /a HTTP/1.1\r\nIf-Modified-Since: 10-10-2012\r\nIf-None-Match: 123\r\nProxy-Connection: keep-alive\r\nAccept-Encoding: gzip\r\n\r\n";
            string            testResponse = "HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n";

            mockSiteData.AddRequestResponse(testRequest, testResponse);
            MockProxy mockServer = new MockProxy(serverdataStore, mockSiteData);

            mockServer.Start();

            //setup a mock proxy

            TrafficViewerFile proxyDataStore = new TrafficViewerFile();

            proxyDataStore.Profile.SetExclusions(new string[1] {
                @".*\.gif"
            });
            ManualExploreProxy meProxy = new ManualExploreProxy("127.0.0.1", 17777, proxyDataStore);

            meProxy.Start();

            IHttpClient httpClient = GetHttpClient(ClientType.TrafficViewerHttpClient, meProxy.Port);             //need to use the traffic viewer client here
            //the webrequestclient does not allow requests to localhost through a proxy on localhost
            HttpRequestInfo testRequestInfo = new HttpRequestInfo(testRequest);

            testRequestInfo.Host = mockServer.Host;
            testRequestInfo.Port = mockServer.Port;


            httpClient.SendRequest(testRequestInfo);


            HttpRequestInfo savedReqInfo = new HttpRequestInfo(serverdataStore.LoadRequestData(0));

            Assert.IsNull(savedReqInfo.Headers["If-Modified-Since"]);
            Assert.IsNull(savedReqInfo.Headers["If-None-Match"]);
            Assert.IsNull(savedReqInfo.Headers["Accept-Encoding"]);
            Assert.IsNull(savedReqInfo.Headers["Proxy-Connection"]);

            meProxy.Stop();
            mockServer.Stop();
        }
        public void Test_NetworkSettings_ProxyUsesAProxy()
        {
            MockProxy mockProxy;
            string    testRequest  = "GET http://site.com/ HTTP/1.1\r\n\r\n";
            string    testResponse = "HTTP/1.1 200 OK\r\n\r\n";

            TrafficViewerFile dataStore = new TrafficViewerFile();

            mockProxy = SetupMockProxy(testRequest, testResponse, dataStore);


            mockProxy.Start();



            ManualExploreProxy meProxy = new ManualExploreProxy("127.0.0.1", 0, null);             //use a random port

            meProxy.NetworkSettings.WebProxy = new WebProxy(mockProxy.Host, mockProxy.Port);
            meProxy.Start();

            WebRequestClient client          = new WebRequestClient();
            INetworkSettings networkSettings = new DefaultNetworkSettings();

            networkSettings.WebProxy = new WebProxy(meProxy.Host, meProxy.Port);

            client.SetNetworkSettings(networkSettings);

            HttpRequestInfo testReqInfo = new HttpRequestInfo(testRequest);

            Assert.AreEqual(0, dataStore.RequestCount);

            HttpResponseInfo respInfo = client.SendRequest(testReqInfo);


            meProxy.Stop();
            mockProxy.Stop();

            //test that the request goes through the mock proxy by checking the data store

            Assert.AreEqual(200, respInfo.Status);
            Assert.AreEqual(1, dataStore.RequestCount);
        }