Пример #1
0
        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();
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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());
            }
        }
Пример #4
0
        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));
        }
Пример #5
0
        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();
            }
        }