public void TestRemoveById()
        {
            DefaultDiskStorage storage = GetStorageSupplier(1).Get();

            string resourceId1 = "resource1";

            byte[] value1 = new byte[100];
            WriteFileToStorage(storage, resourceId1, value1);
            string resourceId2 = "resource2";

            byte[] value2 = new byte[100];
            WriteFileToStorage(storage, resourceId2, value2);
            string resourceId3 = "resource3";

            byte[] value3 = new byte[100];
            WriteFileToStorage(storage, resourceId3, value3);

            Assert.IsTrue(storage.Contains(resourceId1, null));
            Assert.IsTrue(storage.Contains(resourceId2, null));
            Assert.IsTrue(storage.Contains(resourceId3, null));

            storage.Remove(resourceId2);
            Assert.IsTrue(storage.Contains(resourceId1, null));
            Assert.IsFalse(storage.Contains(resourceId2, null));
            Assert.IsTrue(storage.Contains(resourceId3, null));

            storage.Remove(resourceId1);
            Assert.IsFalse(storage.Contains(resourceId1, null));
            Assert.IsFalse(storage.Contains(resourceId2, null));
            Assert.IsTrue(storage.Contains(resourceId3, null));

            storage.Remove(resourceId3);
            Assert.IsFalse(storage.Contains(resourceId1, null));
            Assert.IsFalse(storage.Contains(resourceId2, null));
            Assert.IsFalse(storage.Contains(resourceId3, null));
        }
        public void TestRemoveWithIterator()
        {
            DefaultDiskStorage storage = GetStorageSupplier(1).Get();

            string resourceId1 = "resource1";

            byte[] value1 = new byte[100];
            value1[80] = 101;
            string resourceId2 = "resource2";

            byte[] value2 = new byte[104];
            value2[80] = 102;
            string resourceId3 = "resource3";

            byte[] value3 = new byte[106];
            value3[80] = 103;

            DateTime time1 = DateTime.Now;

            WriteFileToStorage(storage, resourceId1, value1);

            DateTime time2 = time1.AddMilliseconds(1000);

            _clock.SetDateTime(time2);
            WriteFileToStorage(storage, resourceId2, value2);

            _clock.SetDateTime(time2.AddMilliseconds(1000));
            WriteFileToStorage(storage, resourceId3, value3);

            IList <FileSystemInfo> files = FindNewFiles(_directory, new HashSet <FileSystemInfo>(), /*recurse*/ true);

            // There should be 1 file per entry
            Assert.AreEqual(3, files.Count);

            // Now delete entry2
            ICollection <IEntry> entries = storage.GetEntries();

            foreach (var item in entries)
            {
                if (Math.Abs((item.Timestamp - time2).TotalMilliseconds) < 500)
                {
                    storage.Remove(item);
                }
            }

            Assert.IsFalse(storage.Contains(resourceId2, null));
            IList <FileSystemInfo> remaining = FindNewFiles(
                _directory, new HashSet <FileSystemInfo>(), /*recurse*/ true);

            // 2 entries remain
            Assert.AreEqual(2, remaining.Count);

            // None of them with timestamp close to time2
            IList <IEntry> entries1 = new List <IEntry>(storage.GetEntries());

            Assert.AreEqual(2, entries1.Count);

            // First
            IEntry entry = entries1[0];

            Assert.IsFalse(Math.Abs((entry.Timestamp - time2).TotalMilliseconds) < 500);

            // Second
            entry = entries1[1];
            Assert.IsFalse(Math.Abs((entry.Timestamp - time2).TotalMilliseconds) < 500);
        }