Ejemplo n.º 1
0
 public void Test_Not_Cacheable_No_Content()
 {
     var cachingHandler = new CachingHandler();
     var response = new HttpResponseMessage(HttpStatusCode.OK);
     response.Headers.CacheControl = new CacheControlHeaderValue(){Public = true};
     Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.NotCacheable);
 }
 public void Test_NoCache_IsCacheable_And_NotStale_But_MustRevalidate()
 {
     var cachingHandler = new CachingHandler();
     var response = new HttpResponseMessage(HttpStatusCode.OK);
     response.Headers.CacheControl = new CacheControlHeaderValue() { Public = true, NoCache = true};
     response.Content = new ByteArrayContent(new byte[256]);
     response.Content.Headers.Expires = DateTimeOffset.Now.AddHours(1); // resource is not stale
     Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.MustRevalidate);
 }
Ejemplo n.º 3
0
		public void Setup()
		{
			_mockRepository = new MockRepository();
			_cacheStore = _mockRepository.StrictMock<ICacheStore>();
			_messageHandler = new DummyMessageHandler();
            _cachingHandler = new CachingHandler(_cacheStore)
		                             {
		                                 InnerHandler = _messageHandler
		                             };
            _client = new HttpClient(_cachingHandler);
		}
Ejemplo n.º 4
0
		public void Test_Stale_By_Expires()
		{
			var cachingHandler = new CachingHandler();
            cachingHandler.MustRevalidateByDefault = false;

			var response = new HttpResponseMessage(HttpStatusCode.OK);
			response.Headers.CacheControl = new CacheControlHeaderValue() { Public = true };
			response.Content = new ByteArrayContent(new byte[256]);
			response.Content.Headers.Expires = DateTimeOffset.UtcNow.AddDays(-1);
			Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.Stale);
		}
Ejemplo n.º 5
0
		public void Test_Stale_By_Age()
		{
			var cachingHandler = new CachingHandler();
            var response = new HttpResponseMessage(HttpStatusCode.OK);
			response.Headers.CacheControl = new CacheControlHeaderValue()
			                                	{
			                                		Public = true,
													MaxAge = TimeSpan.FromSeconds(200)
			                                	};
			response.Headers.Date = DateTimeOffset.UtcNow.AddDays(-1);
			response.Content = new ByteArrayContent(new byte[256]);
			Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.MustRevalidate);
		}
Ejemplo n.º 6
0
 public void TestMemoryLeak()
 {
     var memorySize64 = Process.GetCurrentProcess().PrivateMemorySize64;
     for (int i = 0; i < 200; i++)
     {
         var store = new CachingHandler();
         //Thread.Sleep(1);
         store.Dispose();
         GC.Collect();
         GC.WaitForPendingFinalizers();
         if(Process.GetCurrentProcess().PrivateMemorySize64 - memorySize64 > 2 * 1024 * 1024)
             Assert.Fail("Memory leak");
     }
 }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            ThreadPool.SetMinThreads(200, 200);
            var crawler = new Crawler();
            var fileStore = new FileStore(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Cache"));
            var cachingHandler = new CachingHandler(fileStore)
                {
                    InnerHandler = new HttpClientHandler()
                };

            crawler.Requester = new HttpClient(cachingHandler);
            if(ConfigurationManager.ConnectionStrings["UrlStore"]!=null)
                crawler.Store = new UrlStore();
            crawler.Crawl("http://YAHOO.COM");
            Console.Read();
        }
Ejemplo n.º 8
0
 public void DoesNotDisposeVaryHeaderStoreIfPassedToIt()
 {
     var mockcs = new Moq.Mock<ICacheStore>();
     var mockvh = new Moq.Mock<IVaryHeaderStore>(MockBehavior.Strict);
     var handler = new CachingHandler(mockcs.Object, mockvh.Object);
     handler.Dispose();
     mockvh.Verify();
 }
Ejemplo n.º 9
0
	    public void DoesNotDisposeCacheStoreIfPassedToIt()
        {
            var mock = new Moq.Mock<ICacheStore>(MockBehavior.Strict);
            var handler = new CachingHandler(mock.Object);
            handler.Dispose();
            mock.Verify();
        }
Ejemplo n.º 10
0
        public void DefaultExceptionPolicy_Throws_CacheStore_Exceptions()
        {
            // setup 
            var request = new HttpRequestMessage(HttpMethod.Put, DummyUrl);
            var responseFromServer = GetOkMessage();
            _messageHandler.Response = responseFromServer;
            _cacheStore = new FaultyCacheStore();
            _cachingHandler = new CachingHandler(_cacheStore)
            {
                InnerHandler = _messageHandler
            };
            _client = new HttpClient(_cachingHandler);


            // run
            var task = _client.SendAsync(request);
            var responseReturned = task.Result;

        }
Ejemplo n.º 11
0
        public void IgnoreExceptionPolicy_Ignores_CacheStore_Exceptions()
        {
            // setup 
            var request = new HttpRequestMessage(HttpMethod.Put, DummyUrl);
            var responseFromServer = GetOkMessage();
            _messageHandler.Response = responseFromServer;
           _cacheStore = new FaultyCacheStore();
           _cachingHandler = new CachingHandler(_cacheStore)
           {
               InnerHandler = _messageHandler
           };
            _cachingHandler.ExceptionHandler = CachingHandler.IgnoreExceptionPolicy;
           _client = new HttpClient(_cachingHandler);


            // run
            var task = _client.SendAsync(request);
            var responseReturned = task.Result;

            // verify
            Assert.AreEqual(responseFromServer, responseReturned);
        }
Ejemplo n.º 12
0
 public void Test_Not_Cacheable_StatusCode(HttpStatusCode code)
 {
     var cachingHandler = new CachingHandler();
     var response = new HttpResponseMessage(code);
     Assert.AreEqual(cachingHandler.ResponseValidator(response), ResponseValidationResult.NotCacheable);
 }