public void InsertsProperly()
        {
            var ipm = new InsertsProperlyMock();

            var diod = new DatabaseIODevice(ipm);

            diod.Insert(new KeyValuePair <byte[], byte[]>[3]
            {
                new KeyValuePair <byte[], byte[]>(Encoding.UTF8.GetBytes("key"), Encoding.UTF8.GetBytes("value")),
                new KeyValuePair <byte[], byte[]>(Encoding.UTF8.GetBytes("key2"), Encoding.UTF8.GetBytes("value2")),
                new KeyValuePair <byte[], byte[]>(Encoding.UTF8.GetBytes("key33"), Encoding.UTF8.GetBytes("value33"))
            });

            diod.Insert(new KeyValuePair <byte[], byte[]>[3]
            {
                new KeyValuePair <byte[], byte[]>(Encoding.UTF8.GetBytes("key"), Encoding.UTF8.GetBytes("value")),
                new KeyValuePair <byte[], byte[]>(Encoding.UTF8.GetBytes("key2"), Encoding.UTF8.GetBytes("value2")),
                new KeyValuePair <byte[], byte[]>(Encoding.UTF8.GetBytes("key33"), Encoding.UTF8.GetBytes("value33"))
            });

            File.WriteAllBytes("examine.txt", ipm.Stream.ToArray());

            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);

            WriteBytes(bw, "key");
            bw.Write(0x30L);
            WriteBytes(bw, "key2");
            bw.Write(0x35L);
            WriteBytes(bw, "key33");
            bw.Write(0x3BL);
            WriteBytes(bw, "JMP_");
            bw.Write(0x42L);
            WriteBytes(bw, "value");
            WriteBytes(bw, "value2");
            WriteBytes(bw, "value33");
            WriteBytes(bw, "key");
            bw.Write(0x72L);
            WriteBytes(bw, "key2");
            bw.Write(0x77L);
            WriteBytes(bw, "key33");
            bw.Write(0x7DL);
            WriteBytes(bw, "JMP_");
            bw.Write(0x0L);
            WriteBytes(bw, "value");
            WriteBytes(bw, "value2");
            WriteBytes(bw, "value33");
            bw.Flush();

            ipm.Stream.ToArray()
            .Should()
            .BeEquivalentTo(ms.ToArray());
        }
        public DatabaseIODeviceOptimalTokenTests()
        {
            _token = new OptimalTokenSource();
            _ms    = new MemoryStream();

            // setup a db
            using (var _db = new DatabaseBuilder()
                             .UseIODatabase(builder => builder.UseStringDB(StringDBVersion.v10_0_0, _ms, true))
                             .WithTransform(StringTransformer.Default, StringTransformer.Default))
            {
                _db.InsertRange(KeyValuePair.Create("one key", "one value"), KeyValuePair.Create("two key", "two value"));
                _db.Insert("key", "value");
                _db.Insert("another key", "another value");
            }

            _ms.Position = 0;

            _lldbiod = new StringDB10_0_0LowlevelDatabaseIODevice(_ms, false);
            _dbiod   = new DatabaseIODevice(_lldbiod, _token);
        }
Exemple #3
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);
            }
        }