public void WebTransferCache_PurgeDownloadWhileOpen() { // Verify that open download files are not purged even though // they exceed the age limit. WebTransferCache cache; WebTransferFile downloadFile; ClearFolder(); cache = new WebTransferCache(new Uri("http://test.com"), folder, "", TimeSpan.FromSeconds(10), TimeSpan.FromMinutes(10)); cache.SetSleepTime(TimeSpan.FromSeconds(0.5)); cache.Start(); try { downloadFile = cache.GetCommittedFile(Guid.Empty, ".pdf"); using (downloadFile.GetStream()) { Thread.Sleep(5000); cache.GetCommittedFile(downloadFile.ID, ".pdf"); // File should still be there Thread.Sleep(1000); cache.GetCommittedFile(downloadFile.ID, ".pdf"); // File should still be there Thread.Sleep(7000); cache.GetCommittedFile(downloadFile.ID, ".pdf"); // File should still be there } // The file is closed now. Wait a bit and verify that it gets purged. Thread.Sleep(2000); try { cache.GetCommittedFile(downloadFile.ID, ".pdf"); Assert.Fail("Expected the file to be purged."); } catch (FileNotFoundException) { // Expected } } finally { cache.Stop(); } }
public void WebTransferCache_PurgeUpload() { // Verify that upload files are purged properly as they age. WebTransferCache cache; WebTransferFile downloadFile; WebTransferFile uploadFile; ClearFolder(); cache = new WebTransferCache(new Uri("http://test.com"), folder, "", TimeSpan.FromMinutes(10), TimeSpan.FromSeconds(10)); cache.SetSleepTime(TimeSpan.FromSeconds(0.5)); cache.Start(); try { downloadFile = cache.GetCommittedFile(Guid.Empty, ".pdf"); uploadFile = cache.GetUploadFile(Guid.Empty, ".pdf"); Thread.Sleep(5000); cache.GetUploadFile(uploadFile.ID, ".pdf"); // File should still be there Thread.Sleep(1000); cache.GetUploadFile(uploadFile.ID, ".pdf"); // File should still be there Thread.Sleep(7000); // File should have been purged try { cache.GetUploadFile(uploadFile.ID, ".pdf"); Assert.Fail("Expected the file to be purged."); } catch (FileNotFoundException) { // Expected } cache.GetCommittedFile(downloadFile.ID, ".pdf"); // File should still be there } finally { cache.Stop(); } }