コード例 #1
0
        public void WebTransferCache_DeleteFileWhenOpen()
        {
            // Verify that an open file will not be deleted and no exception
            // is thrown.  This simulates the case where the website is in the
            // process of downloading the file.

            WebTransferCache cache;
            WebTransferFile  file;

            ClearFolder();

            cache = new WebTransferCache(new Uri("http://test.com"), folder, "", TimeSpan.FromMinutes(10), TimeSpan.FromSeconds(10));
            cache.Start();

            try
            {
                file = cache.GetCommittedFile(Guid.Empty, ".pdf");
                cache.GetCommittedFile(file.ID, ".pdf");    // File should still be there

                using (file.GetStream())
                {
                    cache.DeleteFile(file.ID, ".pdf");
                    cache.GetCommittedFile(file.ID, ".pdf"); // Shouldn't throw an exception
                }
            }
            finally
            {
                cache.Stop();
            }
        }
コード例 #2
0
        public void WebTransferCache_DeleteFileByUri()
        {
            // Verify that we can delete a cached file via its URI.

            WebTransferCache cache;
            WebTransferFile  file;
            Uri uri;

            ClearFolder();

            cache = new WebTransferCache(new Uri("http://test.com"), folder, "", TimeSpan.FromMinutes(10), TimeSpan.FromSeconds(10));
            cache.Start();

            try
            {
                file = cache.GetCommittedFile(Guid.Empty, ".pdf");
                uri  = cache.GetCommittedFile(file.ID, ".pdf").Uri; // File should still be there

                cache.DeleteFile(uri);

                // File should have been deleted

                try
                {
                    cache.GetCommittedFile(file.ID, ".pdf");
                    Assert.Fail("Expected the file to be deleted.");
                }
                catch (FileNotFoundException)
                {
                    // Expected
                }

                // Verify that some error cases don't throw exceptions.

                cache.DeleteFile(uri);                                                              // File already deleted
                cache.DeleteFile(new Uri("http://test.com"));                                       // No segments in URI
                cache.DeleteFile(new Uri("http://test.com/hello.htm"));                             // Invalid GUID
                cache.DeleteFile(new Uri("http://test.com/6ED48410-A140-434c-B294-0CE81042EEA9"));  // No file extension
            }
            finally
            {
                cache.Stop();
            }
        }
コード例 #3
0
        public void WebTransferCache_DeleteFileNoExist()
        {
            // Verify that we can delete a file that doesn't exist without an exception.

            WebTransferCache cache;

            ClearFolder();

            cache = new WebTransferCache(new Uri("http://test.com"), folder, "", TimeSpan.FromMinutes(10), TimeSpan.FromSeconds(10));
            cache.Start();

            try
            {
                cache.DeleteFile(Guid.NewGuid(), ".pdf");
            }
            finally
            {
                cache.Stop();
            }
        }
コード例 #4
0
        public void WebTransferCache_DeleteFileByID()
        {
            // Verify that we can delete a cached file via its ID.

            WebTransferCache cache;
            WebTransferFile  file;

            ClearFolder();

            cache = new WebTransferCache(new Uri("http://test.com"), folder, "", TimeSpan.FromMinutes(10), TimeSpan.FromSeconds(10));
            cache.Start();

            try
            {
                file = cache.GetCommittedFile(Guid.Empty, ".pdf");
                cache.GetCommittedFile(file.ID, ".pdf");    // File should still be there

                cache.DeleteFile(file.ID, ".pdf");

                // File should have been deleted

                try
                {
                    cache.GetCommittedFile(file.ID, ".pdf");
                    Assert.Fail("Expected the file to be deleted.");
                }
                catch (FileNotFoundException)
                {
                    // Expected
                }
            }
            finally
            {
                cache.Stop();
            }
        }