示例#1
0
        public static IDatabase <byte[], byte[]> UseIODatabase
        (
            [CanBeNull] this DatabaseBuilder builder,
            [NotNull] IDatabaseIODevice databaseIODevice,
            [NotNull] out IOptimalTokenSource optimalTokenSource
        )
        {
            var iodb = new IODatabase(databaseIODevice);

            optimalTokenSource = iodb.DatabaseIODevice.OptimalTokenSource;
            return(iodb);
        }
示例#2
0
        public void Enumerates()
        {
            var mdbiod = new MockDatabaseIODevice();
            var iodb   = new IODatabase(mdbiod);

            bool first = true;

            int i = 0;

            foreach (var item in iodb)
            {
                if (first)
                {
                    // 1 because it's enumerated by 1 already

                    mdbiod.ItemOn
                    .Should()
                    .Be(1, "Reset() called by the IODatabase");

                    first = false;
                }

                item.Key
                .Should()
                .BeEquivalentTo(mdbiod.Data[i].Key);

                var lazyItem = mdbiod.Data[i].Value;

                lazyItem.Loaded
                .Should()
                .BeFalse();

                item.Value.Load()
                .Should()
                .BeEquivalentTo(lazyItem.Value);

                lazyItem.Loaded
                .Should()
                .BeTrue();

                i++;
            }
        }
示例#3
0
        public void Inserts()
        {
            var mdbiod = new MockDatabaseIODevice();
            var iodb   = new IODatabase(mdbiod);

            var inserting = new KeyValuePair <byte[], byte[]>[]
            {
                new KeyValuePair <byte[], byte[]>
                (
                    key: Encoding.UTF8.GetBytes("test"),
                    value: Encoding.UTF8.GetBytes("value")
                )
            };

            iodb.InsertRange(inserting);

            mdbiod.Inserted
            .Should()
            .BeEquivalentTo(inserting);
        }
示例#4
0
        public void WorksIGuess()
        {
            var st = new StringTransformer();

            // using (var fs = File.Open("copy.db", FileMode.OpenOrCreate))
            using (var ms = new MemoryStream())
            {
                using (var lowlevelDBIODevice = new StringDB5_0_0LowlevelDatabaseIODevice(ms, true))
                    using (var dbIODevice = new DatabaseIODevice(lowlevelDBIODevice))
                        using (var iodb = new IODatabase(dbIODevice))
                            using (var db = new TransformDatabase <byte[], byte[], string, string>(iodb, st, st))
                            {
                                db.Insert("test", "value");
                                db.InsertRange(new KeyValuePair <string, string>[]
                                {
                                    new KeyValuePair <string, string>("a,", "c,"),
                                    new KeyValuePair <string, string>("b,", "d,"),
                                });

                                File.WriteAllBytes("sdb.db", ms.ToArray());

                                db.EnumerateAggressively(2)
                                .Should()
                                .BeEquivalentTo
                                (
                                    new KeyValuePair <string, string>[]
                                {
                                    new KeyValuePair <string, string>("test", "value"),
                                    new KeyValuePair <string, string>("a,", "c,"),
                                    new KeyValuePair <string, string>("b,", "d,"),
                                }
                                );
                            }

                ms.Seek(0, SeekOrigin.Begin);
                // ms.CopyTo(fs);
            }
        }