public async Task MoveIndexTest()
        {
            var objectOne = new AlgoliaStub {
                ObjectId = "one"
            };
            var addObject = await _indexMove.SaveObjectAsync(objectOne);

            addObject.Wait();

            string indexDestName = TestHelper.GetTestIndexName("move_test_dest");

            var move = await BaseTest.SearchClient.MoveIndexAsync(_indexMoveName, indexDestName);

            move.Wait();

            var listIndices = await BaseTest.SearchClient.ListIndicesAsync();

            Assert.True(listIndices.Items.Exists(x => x.Name.Equals(indexDestName)));
            Assert.True(!listIndices.Items.Exists(x => x.Name.Equals(_indexMoveName)));
        }
        public async Task IndexOperationsAsyncTest()
        {
            // AddObject with ID
            var objectOne = new AlgoliaStub {
                ObjectId = "one"
            };
            var addObject = _index.SaveObjectAsync(objectOne);

            // AddObject without ID
            var objectWoId    = new AlgoliaStub();
            var addObjectWoId = _index.SaveObjectAsync(objectWoId, autoGenerateObjectId: true);

            // Save two objects with objectID
            var objectsWithIds = new List <AlgoliaStub>
            {
                new AlgoliaStub {
                    ObjectId = "two"
                },
                new AlgoliaStub {
                    ObjectId = "three"
                }
            };

            var addObjects = _index.SaveObjectsAsync(objectsWithIds);

            // Save two objects w/o objectIDs
            var objectsWoId = new List <AlgoliaStub>
            {
                new AlgoliaStub {
                    Property = "addObjectsWoId"
                },
                new AlgoliaStub {
                    Property = "addObjectsWoId"
                }
            };

            var addObjectsWoId = _index.SaveObjectsAsync(objectsWoId, autoGenerateObjectId: true);

            // Batch 1000 objects
            var objectsToBatch = new List <AlgoliaStub>();
            var ids            = new List <string>();

            for (int i = 0; i < 1000; i++)
            {
                var id = (i + 1).ToString();
                objectsToBatch.Add(new AlgoliaStub {
                    ObjectId = id, Property = $"Property{id}"
                });
                ids.Add(id);
            }

            var batch = _index.SaveObjectsAsync(objectsToBatch);

            // Wait for all http call to finish
            var responses = await Task.WhenAll(new[] { addObject, addObjectWoId, addObjects, addObjectsWoId, batch }).ConfigureAwait(false);

            // Wait for Algolia's task to finish (indexing)
            responses.Wait();

            // Six first records
            var generatedId = addObjectWoId.Result.Responses[0].ObjectIDs.ToList();

            objectWoId.ObjectId = generatedId.ElementAt(0);

            var generatedIDs = addObjectsWoId.Result.Responses[0].ObjectIDs.ToList();

            objectsWoId[0].ObjectId = generatedIDs.ElementAt(0);
            objectsWoId[1].ObjectId = generatedIDs.ElementAt(1);

            var settedIds = new List <string> {
                "one", "two", "three"
            };

            var sixFirstRecordsIds = settedIds.Concat(generatedId).Concat(generatedIDs).ToList();
            var sixFirstRecords    = (await _index.GetObjectsAsync <AlgoliaStub>(sixFirstRecordsIds)).ToList();

            Assert.True(sixFirstRecords.Count() == 6);

            var objectsToCompare = new List <AlgoliaStub> {
                objectOne
            }.Concat(objectsWithIds)
            .Concat(new List <AlgoliaStub> {
                objectWoId
            })
            .Concat(objectsWoId)
            .ToList();

            // Check retrieved objects againt original content
            Parallel.For(0, sixFirstRecords.Count, i =>
            {
                Assert.True(TestHelper.AreObjectsEqual(sixFirstRecords[i], objectsToCompare[i]));
            });

            // 1000 records
            var batchResponse = (await _index.GetObjectsAsync <AlgoliaStub>(ids)).ToList();

            Assert.True(batchResponse.Count() == 1000);

            // Check retrieved objects againt original content
            Parallel.For(0, batchResponse.Count, i =>
            {
                Assert.True(TestHelper.AreObjectsEqual(objectsToBatch[i], batchResponse[i]));
            });

            // Browse all index to assert that we have 1006 objects
            var objectsBrowsed = new List <AlgoliaStub>();

            foreach (var item in _index.Browse <AlgoliaStub>(new BrowseIndexQuery()))
            {
                objectsBrowsed.Add(item);
            }

            Assert.True(objectsBrowsed.Count() == 1006);

            // Update one object
            var objectToPartialUpdate = objectsToBatch.ElementAt(0);

            objectToPartialUpdate.Property = "PartialUpdated";

            var partialUpdateObject = await _index.PartialUpdateObjectAsync(objectToPartialUpdate);

            partialUpdateObject.Wait();

            var getUpdatedObject = await _index.GetObjectAsync <AlgoliaStub>(objectToPartialUpdate.ObjectId);

            Assert.True(getUpdatedObject.Property.Equals(objectToPartialUpdate.Property));

            // Update two objects
            var objectToPartialUpdate1 = objectsToBatch.ElementAt(1);

            objectToPartialUpdate1.Property = "PartialUpdated1";
            var objectToPartialUpdate2 = objectsToBatch.ElementAt(2);

            objectToPartialUpdate2.Property = "PartialUpdated2";

            var partialUpdateObjects = await _index.PartialUpdateObjectsAsync(new List <AlgoliaStub>
            {
                objectToPartialUpdate1,
                objectToPartialUpdate2
            });

            partialUpdateObjects.Wait();

            var getUpdatedObjects = (await _index.GetObjectsAsync <AlgoliaStub>(new List <string>
            {
                objectToPartialUpdate1.ObjectId,
                objectToPartialUpdate2.ObjectId
            })).ToList();

            Assert.True(getUpdatedObjects.ElementAt(0).Property.Equals(objectToPartialUpdate1.Property));
            Assert.True(getUpdatedObjects.ElementAt(1).Property.Equals(objectToPartialUpdate2.Property));

            // Delete six first objects
            var deleteObjects = await _index.DeleteObjectsAsync(sixFirstRecordsIds);

            // Assert that the objects were deleted
            var objectsBrowsedAfterDelete = new List <AlgoliaStub>();

            deleteObjects.Wait();
            foreach (var item in _index.Browse <AlgoliaStub>(new BrowseIndexQuery()))
            {
                objectsBrowsedAfterDelete.Add(item);
            }

            Assert.True(objectsBrowsedAfterDelete.Count() == 1000);

            // Delete remaining objects
            var deleteRemainingObjects = await _index.DeleteObjectsAsync(ids);

            deleteRemainingObjects.Wait();

            // Assert that all objects were deleted
            var search = await _index.SearchAsync <AlgoliaStub>(new Query(""));

            Assert.True(search.Hits.Count == 0);
        }