示例#1
0
        public void TestAccountCopyIndexSameApp()
        {
            SearchIndex   index1  = BaseTest.SearchClient.InitIndex(TestHelper.GetTestIndexName("copy_index"));
            SearchIndex   index2  = BaseTest.SearchClient.InitIndex(TestHelper.GetTestIndexName("copy_index_2"));
            AccountClient account = new AccountClient();

            AlgoliaException ex =
                Assert.ThrowsAsync <AlgoliaException>(() => account.CopyIndexAsync <AccountCopyObject>(index1, index2));

            Assert.That(ex.Message.Contains("Source and Destination indices should not be on the same application."));
        }
示例#2
0
        public async Task TestAccountCopyIndex()
        {
            AccountClient accountClient = new AccountClient();

            string indexOneName = TestHelper.GetTestIndexName("copy_index");
            string indexTwoName = TestHelper.GetTestIndexName("copy_index_2");

            SearchIndex index1 = BaseTest.SearchClient.InitIndex(indexOneName);
            SearchIndex index2 = BaseTest.SearchClient2.InitIndex(indexTwoName);

            var objectToAdd = new AccountCopyObject {
                ObjectID = "one"
            };
            var addObject = index1.SaveObjectAsync(objectToAdd);

            Rule ruleToSave = new Rule
            {
                ObjectID = "one",
#pragma warning disable 612, 618
                Condition = new Condition {
                    Anchoring = "is", Pattern = "pattern"
                },
#pragma warning restore 612, 618
                Consequence = new Consequence
                {
                    Params = new ConsequenceParams
                    {
                        Query = new ConsequenceQuery
                        {
                            Edits = new List <Edit>
                            {
                                new Edit {
                                    Type = EditType.Remove, Delete = "patter"
                                }
                            }
                        }
                    }
                },
            };

            var saveRule = index1.SaveRuleAsync(ruleToSave);

            var synonym = new Synonym
            {
                ObjectID = "one",
                Type     = SynonymType.Synonym,
                Synonyms = new List <string> {
                    "one", "two"
                }
            };

            var saveSynonym = index1.SaveSynonymAsync(synonym);

            IndexSettings settings = new IndexSettings {
                AttributesForFaceting = new List <string> {
                    "company"
                }
            };

            var saveSettings = index1.SetSettingsAsync(settings);

            Task.WaitAll(saveSettings, saveSynonym, saveRule, addObject);

            // Algolia wait
            addObject.Result.Wait();
            saveRule.Result.Wait();
            saveSettings.Result.Wait();
            saveSynonym.Result.Wait();

            var copyIndex = await accountClient.CopyIndexAsync <AccountCopyObject>(index1, index2);

            copyIndex.Wait();

            var getObjectTask       = index2.GetObjectAsync <AccountCopyObject>("one");
            var getRule             = index2.GetRuleAsync(ruleToSave.ObjectID);
            var getSynonym          = index2.GetSynonymAsync(synonym.ObjectID);
            var getSettings         = index2.GetSettingsAsync();
            var getOriginalSettings = index1.GetSettingsAsync();

            Assert.True(TestHelper.AreObjectsEqual(objectToAdd, await getObjectTask));
            Assert.True(TestHelper.AreObjectsEqual(ruleToSave, await getRule));
            Assert.True(TestHelper.AreObjectsEqual(synonym, await getSynonym));
            Assert.True(TestHelper.AreObjectsEqual(await getOriginalSettings, await getSettings));

            await index2.DeleteAsync();
        }