public void TestBasicOperations()
        {
            DefaultDiskStorage storage     = GetStorageSupplier(1).Get();
            string             resourceId1 = "R1";
            string             resourceId2 = "R2";

            // No file - get should fail
            IBinaryResource resource1 = storage.GetResource(resourceId1, null);

            Assert.IsNull(resource1);

            // Write out the file now
            byte[] key1Contents = new byte[] { 0, 1, 2 };
            WriteToStorage(storage, resourceId1, key1Contents);

            // Get should succeed now
            resource1 = storage.GetResource(resourceId1, null);
            Assert.IsNotNull(resource1);
            FileInfo underlyingFile = ((FileBinaryResource)resource1).File;

            CollectionAssert.AreEqual(key1Contents, Files.ToByteArray(underlyingFile));

            // Remove the file now - get should fail again
            underlyingFile.Delete();

            resource1 = storage.GetResource(resourceId1, null);
            Assert.IsNull(resource1);

            // No file
            IBinaryResource resource2 = storage.GetResource(resourceId2, null);

            Assert.IsNull(resource2);
        }
        public void TestEntryImmutable()
        {
            DefaultDiskStorage storage = GetStorageSupplier(1).Get();

            string resourceId1 = "resource1";

            byte[] value1 = new byte[100];
            value1[80] = 123;
            FileInfo file1 = WriteFileToStorage(storage, resourceId1, value1);

            Assert.AreEqual(100, file1.Length);
            ICollection <IEntry> entries = storage.GetEntries();
            IEntry   entry     = entries.FirstOrDefault();
            DateTime timestamp = entry.Timestamp;

            _clock.SetDateTime(DateTime.Now.AddHours(1));
            storage.GetResource(resourceId1, null);

            // Now the new timestamp show be higher, but the entry should have the same value
            ICollection <IEntry> newEntries = storage.GetEntries();
            IEntry newEntry = newEntries.FirstOrDefault();

            Assert.IsTrue(timestamp < newEntry.Timestamp);
            Assert.AreEqual(timestamp, entry.Timestamp);
        }
        public void TestEntryIds()
        {
            DefaultDiskStorage storage = GetStorageSupplier(1).Get();

            byte[] value1 = new byte[101];
            byte[] value2 = new byte[102];
            byte[] value3 = new byte[103];
            value1[80] = 123;
            value2[80] = 45;
            value3[80] = 67;
            WriteFileToStorage(storage, "resourceId1", value1);
            WriteFileToStorage(storage, "resourceId2", value2);
            WriteFileToStorage(storage, "resourceId3", value3);

            // Check that resources are retrieved by the right name, before testing getEntries
            IBinaryResource res1 = storage.GetResource("resourceId1", null);
            IBinaryResource res2 = storage.GetResource("resourceId2", null);
            IBinaryResource res3 = storage.GetResource("resourceId3", null);

            CollectionAssert.AreEqual(value1, res1.Read());
            CollectionAssert.AreEqual(value2, res2.Read());
            CollectionAssert.AreEqual(value3, res3.Read());

            // Obtain entries and sort by name
            List <IEntry> entries = new List <IEntry>(storage.GetEntries());

            entries.Sort((a, b) =>
            {
                return(a.Id.CompareTo(b.Id));
            });

            Assert.AreEqual(3, entries.Count);
            Assert.AreEqual("resourceId1", entries[0].Id);
            Assert.AreEqual("resourceId2", entries[1].Id);
            Assert.AreEqual("resourceId3", entries[2].Id);
            CollectionAssert.AreEqual(value1, entries[0].Resource.Read());
            CollectionAssert.AreEqual(value2, entries[1].Resource.Read());
            CollectionAssert.AreEqual(value3, entries[2].Resource.Read());
        }