[Test] public async Task TestDropElementsFromCollection() { Value dropped = await client.Query(Drop(2, Arr(1, 2, 3))); Assert.That(dropped.Collect(Field.To <long>()), Is.EquivalentTo(new List <long> { 3L })); }
[Test] public async Task TestTakeElementsFromCollection() { Value taken = await client.Query(Take(2, Arr(1, 2, 3))); Assert.That(taken.Collect(Field.To <long>()), Is.EquivalentTo(new List <long> { 1L, 2L })); }
[Test] public async Task TestEvalLetExpression() { Value res = await client.Query( Let("x", 1, "y", 2).In(Arr(Var("y"), Var("x"))) ); Assert.That(res.Collect(Field.To <long>()), Is.EquivalentTo(new List <long> { 2L, 1L })); }
[Test] public async Task TestAppendElementsInACollection() { Value appended = await client.Query( Append(Arr(3, 4), Arr(1, 2)) ); Assert.That(appended.Collect(Field.To <long>()), Is.EquivalentTo(new List <long> { 1L, 2L, 3L, 4L })); }
[Test] public async Task TestExecuteForeachExpression() { var clazz = await RandomClass(); Value res = await client.Query( Foreach(Arr("Fireball Level 1", "Fireball Level 2"), Lambda("spell", Create(clazz, Obj("data", Obj("name", Var("spell")))))) ); Assert.That(res.Collect(Field.To <string>()), Is.EquivalentTo(new List <string> { "Fireball Level 1", "Fireball Level 2" })); ////////////////// res = await client.Query( Foreach(Arr("Fireball Level 1", "Fireball Level 2"), Lambda(spell => Create(clazz, Obj("data", Obj("name", spell))))) ); Assert.That(res.Collect(Field.To <string>()), Is.EquivalentTo(new List <string> { "Fireball Level 1", "Fireball Level 2" })); ////////////////// res = await client.Query( Foreach(Arr("Fireball Level 1", "Fireball Level 2"), spell => Create(clazz, Obj("data", Obj("name", spell)))) ); Assert.That(res.Collect(Field.To <string>()), Is.EquivalentTo(new List <string> { "Fireball Level 1", "Fireball Level 2" })); }
[Test] public async Task TestFilterACollection() { Value filtered = await client.Query( Filter(Arr(1, 2, 3), Lambda("i", EqualsFn(0, Modulo(Var("i"), 2)))) ); Assert.That(filtered.Collect(Field.To <long>()), Is.EquivalentTo(new List <long> { 2L })); ////////////////// filtered = await client.Query( Filter(Arr(1, 2, 3), Lambda(i => EqualsFn(0, Modulo(i, 2)))) ); Assert.That(filtered.Collect(Field.To <long>()), Is.EquivalentTo(new List <long> { 2L })); ////////////////// filtered = await client.Query( Filter(Arr(1, 2, 3), i => EqualsFn(0, Modulo(i, 2))) ); Assert.That(filtered.Collect(Field.To <long>()), Is.EquivalentTo(new List <long> { 2L })); }
[Test] public async Task TestMapOverCollections() { Value res = await client.Query( Map(Arr(1, 2, 3), Lambda("i", Add(Var("i"), 1))) ); Assert.That(res.Collect(Field.To <long>()), Is.EquivalentTo(new List <long> { 2L, 3L, 4L })); ////////////////// res = await client.Query( Map(Arr(1, 2, 3), Lambda(i => Add(i, 1))) ); Assert.That(res.Collect(Field.To <long>()), Is.EquivalentTo(new List <long> { 2L, 3L, 4L })); ////////////////// res = await client.Query( Map(Arr(1, 2, 3), i => Add(i, 1)) ); Assert.That(res.Collect(Field.To <long>()), Is.EquivalentTo(new List <long> { 2L, 3L, 4L })); }