public void TestDirectoryIsNotNuked()
        {
            Assert.AreEqual(0, _directory.ListFiles().Length);

            DefaultDiskStorage storage    = GetStorageSupplier(1).Get();
            string             resourceId = "file1";

            byte[] CONTENT = Encoding.UTF8.GetBytes("content");

            // Create a file so we know version directory really exists
            IInserter inserter = storage.Insert(resourceId, null);

            WriteToResource(inserter, CONTENT);
            inserter.Commit(null);

            // Assign some previous date to the "now" used for file creation
            long lastModified = _directory.LastWriteTime.Ticks / TimeSpan.TicksPerMillisecond - 1000;

            _directory.LastWriteTime = new DateTime(lastModified * TimeSpan.TicksPerMillisecond);

            // Check it was changed
            Assert.AreEqual(lastModified * TimeSpan.TicksPerMillisecond, _directory.LastWriteTime.Ticks);

            // Create again, it shouldn't delete the directory
            GetStorageSupplier(1).Get();
            _directory.Refresh();

            // _directory exists...
            Assert.IsTrue(_directory.Exists);

            // And it's the same as before
            Assert.AreEqual(lastModified * TimeSpan.TicksPerMillisecond, _directory.LastWriteTime.Ticks);
        }
        private static FileBinaryResource WriteToStorage(
            DefaultDiskStorage storage,
            string resourceId,
            byte[] value)
        {
            IInserter inserter = storage.Insert(resourceId, null);

            WriteToResource(inserter, value);
            return((FileBinaryResource)inserter.Commit(null));
        }
 /// <summary>
 /// Commits the provided temp file to the cache, renaming it to match
 /// the cache's hashing convention.
 /// </summary>
 private IBinaryResource EndInsert(
     IInserter inserter,
     ICacheKey key,
     string resourceId)
 {
     lock (_lock)
     {
         IBinaryResource resource = inserter.Commit(key);
         _resourceIndex.Add(resourceId);
         _cacheStats.Increment(resource.GetSize(), 1);
         return(resource);
     }
 }
        private static FileInfo Write(
            DefaultDiskStorage storage,
            string resourceId,
            byte[] content)
        {
            IInserter  inserter = storage.Insert(resourceId, null);
            FileInfo   file     = ((DefaultDiskStorage.InserterImpl)inserter)._temporaryFile;
            FileStream fos      = file.Create();

            try
            {
                fos.Write(content, 0, content.Length);
            }
            finally
            {
                fos.Dispose();
            }

            return(((FileBinaryResource)inserter.Commit(null)).File);
        }