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 ShouldChunkUpdate(int docCount, int chunksCount) { //Arrange var repository = new Mock <IAlgoliaRepository>(); var index = new Mock <ISearchIndex>(); var sut = new AlgoliaUpdateContext(index.Object, repository.Object); for (int i = 0; i < docCount; i++) { sut.AddDocument(JObject.Parse("{\"objectID\": \"" + i + "\"}"), (IExecutionContext)null); } //Act sut.Commit(); //Assert repository.Verify(t => t.SaveObjectsAsync(It.Is <IEnumerable <JObject> >(o => o.Any())), Times.Exactly(chunksCount)); }
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(); } }