public void Get_Compressed_Deflate() { 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("deflate"); 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.DeflateCompressStream("Testing compression")); }).Verify(delegate { var conn = new SolrConnection("http://localhost") { HttpWebRequestFactory = reqFactory }; Assert.AreEqual("Testing compression", conn.Get("", new Dictionary <string, string>())); }); }