Example #1
0
 public void WriteTest()
 {
     var store = new FakeBinaryStore();
     var entryWriter = new EntryWriter(store);
     entryWriter.Write(TestEntry);
     Assert.AreEqual(22, store.Length);
 }
Example #2
0
        public void AddTest()
        {
            bool isFragmented;
            var store = new FakeBinaryStore();
            var tableOfContent = TableOfContent.From(store, out isFragmented);

            tableOfContent.Add(new Int32Key(1), 0, 200);

            Assert.AreEqual(22, store.Length);
            Assert.AreEqual(22, store.CurrentOffset);
        }
Example #3
0
        public void WriteRemoveTest()
        {
            var entryData = EntryBinaryConverter.Instance.Convert(TestEntry);
            var store = new FakeBinaryStore(entryData);
            var entryWriter = new EntryWriter(store);

            var data = store.Stream.ToArray();
            Assert.AreEqual(1, data[EntryBinaryConverter.IsActiveValueOffset]);

            entryWriter.WriteRemove(TestEntry);
            Assert.AreEqual(22, store.Length);

            data = store.Stream.ToArray();
            Assert.AreEqual(0, data[EntryBinaryConverter.IsActiveValueOffset]);
        }
Example #4
0
        public void RemoveTest()
        {
            var entry = new Entry { Key = new Int32Key(1), ValueOffset = 0, ValueLength = 200 };
            var store = new FakeBinaryStore(EntryBinaryConverter.Instance.Convert(entry));

            bool isFragmented;
            var key = new Int32Key(1);
            var tableOfContent = TableOfContent.From(store, out isFragmented);
            Assert.IsFalse(isFragmented);
            Assert.IsTrue(tableOfContent.Contains(key));
            Assert.IsTrue(tableOfContent.TryRemove(key));
            Assert.IsFalse(tableOfContent.Contains(key));

            tableOfContent = TableOfContent.From(store, out isFragmented);
            Assert.IsTrue(isFragmented);
            Assert.IsFalse(tableOfContent.Contains(key));
        }
Example #5
0
        public void AddMultileAndRemoveTest()
        {
            var entry = new Entry { Key = new Int32Key(1), ValueOffset = 0, ValueLength = 200 };
            var store = new FakeBinaryStore(EntryBinaryConverter.Instance.Convert(entry));

            bool isFragmented;
            var tableOfContent = TableOfContent.From(store, out isFragmented);
            Assert.IsFalse(isFragmented);
            tableOfContent.Add(new Int32Key(2), 200, 215);
            tableOfContent.Add(new Int32Key(3), 415, 215);
            tableOfContent.Add(new Int32Key(4), 630, 230);
            tableOfContent.Add(new Int32Key(5), 860, 640);
            tableOfContent.Add(new Int32Key(6), 1500, 500);

            Assert.AreEqual(22 * 6, store.Length);
            Assert.AreEqual(22 * 6, store.CurrentOffset);

            var key1 = new Int32Key(1);
            var key2 = new Int32Key(2);
            var key3 = new Int32Key(3);

            Assert.IsTrue(tableOfContent.Contains(key1));
            Assert.IsTrue(tableOfContent.Contains(key2));
            Assert.IsTrue(tableOfContent.Contains(key3));
            Assert.IsTrue(tableOfContent.TryRemove(key2));
            Assert.IsTrue(tableOfContent.Contains(key1));
            Assert.IsFalse(tableOfContent.Contains(key2));
            Assert.IsTrue(tableOfContent.Contains(key3));

            Assert.IsTrue(tableOfContent.TryRemove(key3));
            Assert.IsTrue(tableOfContent.Contains(key1));
            Assert.IsFalse(tableOfContent.Contains(key2));
            Assert.IsFalse(tableOfContent.Contains(key3));

            tableOfContent = TableOfContent.From(store, out isFragmented);
            Assert.IsTrue(isFragmented);
            Assert.IsTrue(tableOfContent.Contains(key1));
            Assert.IsFalse(tableOfContent.Contains(key2));
            Assert.IsFalse(tableOfContent.Contains(key3));
        }