public void SetKeyIndexWorks()
{
using (IKeyValueDB db = new InMemoryKeyValueDB())
{
var key = new byte[2];
const int keysCreated = 10000;
using (var tr = db.StartTransaction())
{
for (int i = 0; i < keysCreated; i++)
{
key[0] = (byte)(i / 256);
key[1] = (byte)(i % 256);
tr.CreateKey(key);
}
tr.Commit();
}
using (var tr = db.StartTransaction())
{
Assert.False(tr.SetKeyIndex(keysCreated));
for (int i = 0; i < keysCreated; i += 5)
{
Assert.True(tr.SetKeyIndex(i));
key = tr.GetKeyAsByteArray();
Assert.Equal((byte)(i / 256), key[0]);
Assert.Equal((byte)(i % 256), key[1]);
Assert.Equal(i, tr.GetKeyIndex());
}
}
}
}