Ejemplo n.º 1
0
        public void Get_Compressed_Gzip()
        {
            var mocks      = new MockRepository();
            var reqFactory = mocks.StrictMock <IHttpWebRequestFactory>();
            var request    = mocks.DynamicMock <IHttpWebRequest>();
            var response   = mocks.DynamicMock <IHttpWebResponse>();

            With.Mocks(mocks).Expecting(delegate
            {
                Expect.Call(reqFactory.Create(new UriBuilder().Uri))
                .IgnoreArguments()
                .Repeat.Once()
                .Return(request);
                Expect.Call(request.Headers)
                .Repeat.Any()
                .Return(new WebHeaderCollection());
                Expect.Call(response.ContentEncoding)
                .Repeat.Any()
                .Return("gzip");
                Expect.Call(response.Headers)
                .Repeat.Any()
                .Return(new WebHeaderCollection());
                Expect.Call(request.GetResponse())
                .Repeat.Once()
                .Return(response);
                Expect.Call(response.GetResponseStream())
                .Repeat.Once()
                .Return(CompressionUtils.GzipCompressStream("Testing compression"));
            }).Verify(delegate {
                var conn = new SolrConnection("http://localhost")
                {
                    HttpWebRequestFactory = reqFactory
                };
                Assert.AreEqual("Testing compression", conn.Get("", new Dictionary <string, string>()));
            });
        }