public async Task Task_Can_Add_Update_Remove_From_Index() { using (var db = await OpenTestPartitionAsync()) { var location = db.Root["Indexing"]; // clear previous values await CleanLocation(db, location); var subspace = location.ByKey("FoosByColor"); var index = new FdbIndex <int, string>(subspace); // add items to the index await db.WriteAsync(async (tr) => { await index.AddAsync(tr, 1, "red"); await index.AddAsync(tr, 2, "green"); await index.AddAsync(tr, 3, "blue"); await index.AddAsync(tr, 4, "green"); await index.AddAsync(tr, 5, "yellow"); }, this.Cancellation); #if DEBUG await DumpSubspace(db, subspace); #endif // lookup values using (var tr = await db.BeginReadOnlyTransactionAsync(this.Cancellation)) { var reds = await index.Lookup(tr, "red").ToListAsync(); Assert.That(reds, Is.EqualTo(new int[] { 1 })); var greens = await index.Lookup(tr, "green").ToListAsync(); Assert.That(greens, Is.EqualTo(new int[] { 2, 4 })); var blues = await index.Lookup(tr, "blue").ToListAsync(); Assert.That(blues, Is.EqualTo(new int[] { 3 })); var yellows = await index.Lookup(tr, "yellow").ToListAsync(); Assert.That(yellows, Is.EqualTo(new int[] { 5 })); } // update await db.WriteAsync(async (tr) => { await index.UpdateAsync(tr, 3, "indigo", "blue"); await index.RemoveAsync(tr, 5, "yellow"); }, this.Cancellation); #if DEBUG await DumpSubspace(db, subspace); #endif // check values using (var tr = await db.BeginTransactionAsync(this.Cancellation)) { var reds = await index.Lookup(tr, "red").ToListAsync(); Assert.That(reds, Is.EqualTo(new int[] { 1 })); var greens = await index.Lookup(tr, "green").ToListAsync(); Assert.That(greens, Is.EqualTo(new int[] { 2, 4 })); var blues = await index.Lookup(tr, "blue").ToListAsync(); Assert.That(blues.Count, Is.Zero); var yellows = await index.Lookup(tr, "yellow").ToListAsync(); Assert.That(yellows.Count, Is.Zero); var indigos = await index.Lookup(tr, "indigo").ToListAsync(); Assert.That(indigos, Is.EqualTo(new int[] { 3 })); } } }