public void AddOprationShouldAddDocToContext() { // 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.AddDocument(It.IsAny <object>(), It.IsAny <IExecutionContext>())) .Callback( (object itemToUpdate, 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.Add(indexable, context.Object, new ProviderIndexConfiguration()); //Assert context.Verify(t => t.AddDocument(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"]); } }
public void TemplateIdShoulNotBeAssignedByDefault() { // arrange using (var db = new Db { new ItemBuilder().AddSubItem().Build() }) { var item = db.GetItem("/sitecore/content/source"); var indexable = new SitecoreIndexableItem(item); IEnumerable <JObject> docs = null; var index = new IndexBuilder().Build(); var algoliaRepository = new Mock <IAlgoliaRepository>(); algoliaRepository.Setup( t => t.SaveObjectsAsync(It.IsAny <IEnumerable <JObject> >())) .Callback( (IEnumerable <JObject> objects) => docs = objects) .ReturnsAsync(new JObject()); var context = new AlgoliaUpdateContext(index, algoliaRepository.Object); var operations = new AlgoliaIndexOperations(index); //Act operations.Add(indexable, context, index.Configuration); context.Commit(); //Assert var itemDoc = docs.First(t => (string)t["_name"] == "source"); itemDoc["_template"].Should().BeNull(); } }
public void AddOperationShouldUseMaxFieldLength(int maxLenth, string expected) { // arrange using (var db = new Db { new ItemBuilder().AddSubItem().Build() }) { var item = db.GetItem("/sitecore/content/source"); var indexable = new SitecoreIndexableItem(item); IEnumerable <JObject> docs = null; var index = new IndexBuilder().WithMaxFieldLength(maxLenth).Build(); var algoliaRepository = new Mock <IAlgoliaRepository>(); algoliaRepository.Setup( t => t.SaveObjectsAsync(It.IsAny <IEnumerable <JObject> >())) .Callback( (IEnumerable <JObject> objects) => docs = objects) .ReturnsAsync(new JObject()); var context = new AlgoliaUpdateContext(index, algoliaRepository.Object); var operations = new AlgoliaIndexOperations(index); //Act operations.Add(indexable, context, index.Configuration); context.Commit(); //Assert var itemDoc = docs.First(t => (string)t["_name"] == "source"); ((string)itemDoc["_fullpath"]).Should().Be(expected); } }
public void AddOperationShouldLoadComputedFields() { // arrange using (var db = new Db { new ItemBuilder().AddSubItem().Build() }) { var item = db.GetItem("/sitecore/content/source/subitem"); var indexable = new SitecoreIndexableItem(item); IEnumerable <JObject> docs = null; var index = new IndexBuilder().WithParentsComputedField("parents").Build(); var algoliaRepository = new Mock <IAlgoliaRepository>(); algoliaRepository.Setup( t => t.SaveObjectsAsync(It.IsAny <IEnumerable <JObject> >())) .Callback( (IEnumerable <JObject> objects) => docs = objects) .ReturnsAsync(new JObject()); var context = new AlgoliaUpdateContext(index, algoliaRepository.Object); var operations = new AlgoliaIndexOperations(index); //Act operations.Add(indexable, context, new ProviderIndexConfiguration()); context.Commit(); //Assert var itemDoc = docs.First(t => (string)t["_name"] == "subitem"); var parents = (JArray)itemDoc["parents"]; parents.Count.Should().Be(1); ((string)parents.First).Should().Be(TestData.TestItemId.ToString()); } }
public void AddOperationShouldGenerateTags() { // arrange using (var db = new Db { new ItemBuilder().AddSubItem().Build() }) { var item = db.GetItem("/sitecore/content/source"); var indexable = new SitecoreIndexableItem(item); IEnumerable <JObject> docs = null; var index = new IndexBuilder().WithTagsBuilderForId().Build(); var algoliaRepository = new Mock <IAlgoliaRepository>(); algoliaRepository.Setup( t => t.SaveObjectsAsync(It.IsAny <IEnumerable <JObject> >())) .Callback( (IEnumerable <JObject> objects) => docs = objects) .ReturnsAsync(new JObject()); var context = new AlgoliaUpdateContext(index, algoliaRepository.Object); var operations = new AlgoliaIndexOperations(index); //Act operations.Add(indexable, context, new ProviderIndexConfiguration()); context.Commit(); //Assert var itemDoc = docs.First(t => (string)t["_name"] == "source"); var tags = (JArray)itemDoc["_tags"]; tags.Count.Should().Be(2); tags.ToObject <string[]>().Contains(TestData.TestItemId.ToString()).Should().BeTrue(); } }