public void AddItemsIntegration() { // arrange using (var db = new Db { _source }) { var item = db.GetItem("/sitecore/content/source"); var indexable = new SitecoreIndexableItem(item); var index = new AlgoliaSearchIndex("algolia_master_index", "3Q92VD0BCR", "8ae3d3950e531a4be7d32a3e58bb2eea", "test"); var context = index.CreateUpdateContext(); var operations = new AlgoliaIndexOperations(index); //Act operations.Update(indexable, context, new ProviderIndexConfiguration()); context.Commit(); //Assert } }
public void UpdateTest() { // arrange using (var db = new Db { _source }) { var item = db.GetItem("/sitecore/content/source"); var indexable = new SitecoreIndexableItem(item); JObject doc = null; var context = new Mock <IProviderUpdateContext>(); context.Setup( t => t.UpdateDocument(It.IsAny <object>(), It.IsAny <object>(), It.IsAny <IExecutionContext>())) .Callback( (object itemToUpdate, object criteriaForUpdate, IExecutionContext executionContext) => doc = itemToUpdate as JObject); var index = new IndexBuilder().Build(); context.Setup(t => t.Index).Returns(index); var operations = new AlgoliaIndexOperations(index); //Act operations.Update(indexable, context.Object, new ProviderIndexConfiguration()); //Assert context.Verify( t => t.UpdateDocument(It.IsAny <object>(), It.IsAny <object>(), It.IsAny <IExecutionContext>()), Times.Once); Assert.AreEqual("en_" + TestData.TestItemKey.ToLower(), (string)doc["objectID"]); Assert.AreEqual("/sitecore/content/source", (string)doc["_fullpath"]); Assert.AreEqual("source", (string)doc["_name"]); Assert.AreEqual("en", (string)doc["_language"]); Assert.AreEqual(TestData.TestItemId.ToString(), (string)doc["_id"]); } }