public void KeyValueTest()
        {
            using (var bdb = CreateDb())
            {
                var keys = new List <int>();
                for (int i = 0; i < 6; i++)
                {
                    keys.Add(i);
                    var           key   = Encoding.UTF8.GetBytes("key" + i.ToString());
                    var           value = Encoding.UTF8.GetBytes("value" + i.ToString());
                    BerkeleyError error = bdb.WriteAsync(key, value, 0).Result;
                    error.ThrowIfError();
                }

                using (var cursor = new BerkeleyKeyValueCursor(bdb))
                {
                    KeyValueCheck(cursor, keys);

                    BerkeleyError error = cursor.DeleteCurrentAsync().Result;
                    error.ThrowIfError();

                    keys.Remove(keys.Last());
                    KeyValueCheck(cursor, keys);

                    var key = Encoding.UTF8.GetBytes("key3");
                    error = cursor.DeleteAsync(key, 0).Result;
                    error.ThrowIfError();

                    keys.Remove(3);
                    KeyValueCheck(cursor, keys);
                }
            }
        }
        private static HashSet <KeyValuePair <int, DateTime> > BulkDuplicateDelete(BerkeleyBulkDuplicateCursor cursor, HashSet <KeyValuePair <int, DateTime> > data, ref bool blobExists)
        {
            var checkData = new HashSet <KeyValuePair <int, DateTime> >();

            Byte[] key, value;
            foreach (KeyValuePair <int, DateTime> keyValue in data)
            {
                if ((keyValue.Value.Day % 3) == 0)
                {
                    key   = Encoding.UTF8.GetBytes(keyValue.Key.ToString());
                    value = Encoding.UTF8.GetBytes(keyValue.Value.ToString("dddd dd MMMM yyyy"));
                    cursor.AddDelete(key, value);
                }
                else
                {
                    checkData.Add(keyValue);
                }
            }

            key   = Encoding.UTF8.GetBytes((500 / 100 + 1).ToString());
            value = GenerateByteArray(34123);
            cursor.AddDelete(key, value);

            BerkeleyError error = cursor.DeleteAsync().Result;

            error.ThrowIfError();
            blobExists = false;
            return(checkData);
        }
        private static BerkeleyDb CreateDb(BerkeleyDbFlags flags)
        {
            var client = new HttpClient();

            client.BaseAddress = serviceRootUri;
            var methods = new BerkeleyDbWebApiMethods(client, new Newtonsoft.Json.JsonSerializer(), new System.Net.Http.Formatting.JsonMediaTypeFormatter());
            var bdb     = new BerkeleyDb(methods, BerkeleyDbType.DB_BTREE, flags);

            String fileName = Path.Combine(Path.GetTempPath(), "test.bdb");

            File.Delete(fileName);
            BerkeleyError error = bdb.OpenAsync(fileName, BerkeleyDbOpenFlags.DB_CREATE).Result;

            error.ThrowIfError();

            return(bdb);
        }
        private static HashSet <int> BulkDelete(BerkeleyBulkCursor cursor, HashSet <int> keys, ref bool blobExists)
        {
            foreach (int i in keys.Where(i => (i % 3) == 0))
            {
                cursor.AddDelete(Encoding.UTF8.GetBytes(i.ToString()));
            }
            if (blobExists)
            {
                cursor.AddDelete(Encoding.UTF8.GetBytes("blob value"));
            }

            BerkeleyError error = cursor.DeleteAsync().Result;

            error.ThrowIfError();

            blobExists = false;
            return(new HashSet <int>(keys.Where(i => (i % 3) != 0)));
        }