コード例 #1
0
        public void TestBasicOperation()
        {
            var item = Encoding.UTF8.GetBytes("this is an item");
            var key  = new BlobKey();
            var key2 = new BlobKey();

            _store.StoreBlob(item, key);
            _store.StoreBlob(item, key2);
            key.Should().Be(key2, "because keys should be deterministic");

            var readItem = _store.BlobForKey(key);

            readItem.Should().Equal(item, "beacuse the contents of a key should be read back correctly from disk");
            Verify(key, item);

            var path = _store.PathForKey(key);

            _encrypt.Should().Be(path == null, "because only plaintext attachments should return a path");
        }
コード例 #2
0
        public void TestReopen()
        {
            var item = Encoding.UTF8.GetBytes("this is an item");
            var key  = new BlobKey();

            _store.StoreBlob(item, key);

            var store2   = new BlobStore(_storePath, _store.EncryptionKey);
            var readItem = store2.BlobForKey(key);

            readItem.Should().Equal(item, "because the contents of a key should be the same in the second store");

            readItem = _store.BlobForKey(key);
            readItem.Should().Equal(item, "because the contents of a key should be the same in the first store");
            Verify(key, item);
        }
コード例 #3
0
        public virtual void TestStreamAttachmentBlobStoreWriter()
        {
            BlobStore       attachments = database.GetAttachments();
            BlobStoreWriter blobWriter  = new BlobStoreWriter(attachments);
            string          testBlob    = "foo";

            blobWriter.AppendData(Sharpen.Runtime.GetBytesForString(new string(testBlob)));
            blobWriter.Finish();
            string sha1Base64Digest = "sha1-C+7Hteo/D9vJXQ3UfzxbwnXaijM=";

            NUnit.Framework.Assert.AreEqual(blobWriter.SHA1DigestString(), sha1Base64Digest);
            NUnit.Framework.Assert.AreEqual(blobWriter.MD5DigestString(), "md5-rL0Y20zC+Fzt72VPzMSk2A=="
                                            );
            // install it
            blobWriter.Install();
            // look it up in blob store and make sure it's there
            BlobKey blobKey = new BlobKey(sha1Base64Digest);

            byte[] blob = attachments.BlobForKey(blobKey);
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(Sharpen.Runtime.GetBytesForString(testBlob
                                                                                          , Sharpen.Extensions.GetEncoding("UTF-8")), blob));
        }