Esempio n. 1
0
        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"]);
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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());
            }
        }
        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
            }
        }
Esempio n. 6
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();
            }
        }