Esempio n. 1
0
        public void GetSearchQueryElementRoot_ConfiguredEntityTypeForSearchQueryRootItemIsNotSet_ThrowsException() /* More specific which exception */
        {
            using (var db = new Db
            {
                // Arrange
                new DbItem("SearchQueryRootItem")
                {
                    TemplateID = Constants.Templates.SearchQueryRoot.TemplateId,
                    Fields =
                    {
                        { Constants.Fields._SearchQueryGrouping.SearchQueryGroupingLogicalOperator, ValidLogicalOperatorAnd }
                    }
                }
            })
            {
                var searchQueryRootItem = db.GetItem("/sitecore/content/searchqueryrootitem");
                var sut = new SitecoreSearchQueryElementProvider(() => searchQueryRootItem);

                // Act
                Action act = () => sut.GetSearchQueryElementRoot <TestIndexableEntity>();

                // Assert
                act.ShouldThrow <ArgumentException>();
            }
        }
Esempio n. 2
0
        public void GetSearchQueryElementRoot_NoChildSearchQueryElementItems_ReturnsEmptySearchQueryRoot(string rawlogicalOperator, LogicalOperator logicalOperator)
        {
            var typeName = GetValidIndexableEntityTypeName();

            using (var db = new Db
            {
                // Arrange
                new DbItem("SearchQueryRootItem")
                {
                    TemplateID = Constants.Templates.SearchQueryRoot.TemplateId,
                    Fields =
                    {
                        { Constants.Fields._IndexableEntityConfigurator.ConfiguredIndexableEntityType, typeName           },
                        { Constants.Fields._SearchQueryGrouping.SearchQueryGroupingLogicalOperator,    rawlogicalOperator }
                    }
                }
            })
            {
                var searchQueryRootItem = db.GetItem("/sitecore/content/searchqueryrootitem");
                var sut = new SitecoreSearchQueryElementProvider(() => searchQueryRootItem);

                // Act
                var actual = sut.GetSearchQueryElementRoot <TestIndexableEntity>();

                // Assert
                actual.Should().BeOfType(typeof(SearchQueryGrouping <TestIndexableEntity>));
                actual.As <SearchQueryGrouping <TestIndexableEntity> >().LogicalOperator.ShouldBeEquivalentTo(logicalOperator);
                actual.As <SearchQueryGrouping <TestIndexableEntity> >().SearchQueryElements.Count.ShouldBeEquivalentTo(0);
            }
        }
Esempio n. 3
0
        private ISearchResultRepository <T> CreateSearchResultRepository <T>()
            where T : IndexableEntity, new()
        {
            var elementProvider = new SitecoreSearchQueryElementProvider(() => RenderingContext.Current.Rendering.Item);
            var valueProvider   = new NameValuePairSearchQueryValueProvider(() => Request.QueryString);

            var builder = new SearchResultRepositoryBuilder <T>()
                          .WithIndexNameProvider <SitecoreMasterOrWebIndexNameProvider>();

            return(builder.Create(elementProvider, valueProvider));
        }
Esempio n. 4
0
        public void GetSearchQueryElementRoot_SingleSearchQueryRuleItem_ReturnsSearchQueryRootWithSearchQueryRule(
            string rawComparisonOperator, ComparisonOperator comparisonOperator, string propertyName, string defaultValue, string dynamicValueProvidingParameter)
        {
            var typeName         = GetValidIndexableEntityTypeName();
            var propertySelector = GetValidPropertySelectorForTestIndexableEntity(ValidPropertyNameForTestIndexableEntityType);

            using (var db = new Db
            {
                // Arrange
                new DbItem("SearchQueryRootItem")
                {
                    TemplateID = Constants.Templates.SearchQueryRoot.TemplateId,
                    Fields =
                    {
                        { Constants.Fields._IndexableEntityConfigurator.ConfiguredIndexableEntityType, typeName                },
                        { Constants.Fields._SearchQueryGrouping.SearchQueryGroupingLogicalOperator,    ValidLogicalOperatorAnd }
                    },

                    Children =
                    {
                        new DbItem("SearchQueryRuleItem")
                        {
                            TemplateID = Constants.Templates._SearchQueryRule.TemplateId,
                            Fields =
                            {
                                { Constants.Fields._SearchQueryRule.ComparisonOperator,             rawComparisonOperator                                         },
                                { Constants.Fields._SearchQueryRule.AssociatedPropertyName,         ValidPropertyNameForTestIndexableEntityType                   },
                                { Constants.Fields._SearchQueryRule.DefaultValue,                   defaultValue                                                  },
                                { Constants.Fields._SearchQueryRule.DynamicValueProvidingParameter, dynamicValueProvidingParameter                                }
                            },
                        }
                    }
                }
            })
            {
                var searchQueryRootItem = db.GetItem("/sitecore/content/searchqueryrootitem");
                var sut = new SitecoreSearchQueryElementProvider(() => searchQueryRootItem);

                // Act
                var actual = sut.GetSearchQueryElementRoot <TestIndexableEntity>();

                // Assert
                actual.As <SearchQueryGrouping <TestIndexableEntity> >().SearchQueryElements.Count.ShouldBeEquivalentTo(1);

                var actualSearchQueryRule = actual.As <SearchQueryGrouping <TestIndexableEntity> >().SearchQueryElements.First().As <SearchQueryRule <TestIndexableEntity> >();
                actualSearchQueryRule.ComparisonOperator.ShouldBeEquivalentTo(comparisonOperator);
                actualSearchQueryRule.PropertySelector.ShouldBeEquivalentTo(propertySelector);
                actualSearchQueryRule.DefaultValue.ShouldBeEquivalentTo(defaultValue);
                actualSearchQueryRule.DynamicValueProvidingParameter.ShouldBeEquivalentTo(dynamicValueProvidingParameter);
            }
        }
Esempio n. 5
0
        public void GetSearchQueryElementRoot_ItemIsNotSearchQueryRootItem_ThrowsException()
        {
            using (var db = new Db
            {
                // Arrange
                new DbItem("InvalidSearchQueryRootItem")
            })
            {
                var searchQueryRootItem = db.GetItem("/sitecore/content/invalidsearchqueryrootitem");
                var sut = new SitecoreSearchQueryElementProvider(() => searchQueryRootItem);

                // Act
                Action act = () => sut.GetSearchQueryElementRoot <TestIndexableEntity>();

                // Assert
                act.ShouldThrow <ArgumentException>();
            }
        }
Esempio n. 6
0
        public void GetSearchQueryElementRoot_ComparisonOperatorForSearchQueryRuleItemIsInvalid_ThrowsException() /* More specific which exception */
        {
            var typeName = GetValidIndexableEntityTypeName();

            using (var db = new Db
            {
                // Arrange
                new DbItem("SearchQueryRootItem")
                {
                    TemplateID = Constants.Templates.SearchQueryRoot.TemplateId,
                    Fields =
                    {
                        { Constants.Fields._IndexableEntityConfigurator.ConfiguredIndexableEntityType, typeName                },
                        { Constants.Fields._SearchQueryGrouping.SearchQueryGroupingLogicalOperator,    ValidLogicalOperatorAnd }
                    },

                    Children =
                    {
                        new DbItem("SearchQueryRuleItem")
                        {
                            TemplateID = Constants.Templates._SearchQueryRule.TemplateId,
                            Fields =
                            {
                                { Constants.Fields._SearchQueryRule.ComparisonOperator,     InvalidComparisonOperator                       },
                                { Constants.Fields._SearchQueryRule.AssociatedPropertyName, ValidPropertyNameForTestIndexableEntityType     }
                            },
                        }
                    }
                }
            })
            {
                var searchQueryRootItem = db.GetItem("/sitecore/content/searchqueryrootitem");
                var sut = new SitecoreSearchQueryElementProvider(() => searchQueryRootItem);

                // Act
                Action act = () => sut.GetSearchQueryElementRoot <TestIndexableEntity>();

                // Assert
                act.ShouldThrow <InvalidEnumArgumentException>();
            }
        }
Esempio n. 7
0
        public void GetSearchQueryElementRoot_SingleSearchQueryGroupingItem_ReturnsSearchQueryRootWithSearchQueryGrouping(string rawLogicalOperator, LogicalOperator logicalOperator)
        {
            var typeName = GetValidIndexableEntityTypeName();

            using (var db = new Db
            {
                // NOTE: Can't create two items with of different templates but with the same field
                //
                // For more details, see the explaination on issue over at GitHub:
                // https://github.com/sergeyshushlyapin/Sitecore.FakeDb/issues/132

                // TODO: Look into how one can leverage AutoFixture and customizations to build the
                // item template hierarchy once and for all, such that this can be used across the different
                // unit tests.

                // Arrange
                new DbTemplate("_SearchQueryGrouping", Constants.Templates._SearchQueryGrouping.TemplateId)
                {
                    Constants.Fields._SearchQueryGrouping.SearchQueryGroupingLogicalOperator
                },
                new DbTemplate("_IndexableEntityConfigurator", Constants.Templates._IndexableEntityConfigurator.TemplateId)
                {
                    Constants.Fields._IndexableEntityConfigurator.ConfiguredIndexableEntityType
                },
                new DbTemplate("SearchQueryRoot", Constants.Templates.SearchQueryRoot.TemplateId)
                {
                    BaseIDs = new[] {
                        Constants.Templates._SearchQueryGrouping.TemplateId,
                        Constants.Templates._IndexableEntityConfigurator.TemplateId
                    }
                },

                new DbItem("SearchQueryRootItem")
                {
                    TemplateID = Constants.Templates.SearchQueryRoot.TemplateId,
                    Fields =
                    {
                        { Constants.Fields._IndexableEntityConfigurator.ConfiguredIndexableEntityType, typeName           },
                        { Constants.Fields._SearchQueryGrouping.SearchQueryGroupingLogicalOperator,    rawLogicalOperator }
                    },

                    Children =
                    {
                        new DbItem("SearchQueryGroupingItem")
                        {
                            TemplateID = Constants.Templates._SearchQueryGrouping.TemplateId,
                            Fields =
                            {
                                { Constants.Fields._SearchQueryGrouping.SearchQueryGroupingLogicalOperator, rawLogicalOperator }
                            },
                        }
                    }
                }
            })
            {
                var searchQueryRootItem = db.GetItem("/sitecore/content/searchqueryrootitem");
                var sut = new SitecoreSearchQueryElementProvider(() => searchQueryRootItem);

                // Act
                var actual = sut.GetSearchQueryElementRoot <TestIndexableEntity>();

                // Assert
                actual.As <SearchQueryGrouping <TestIndexableEntity> >().SearchQueryElements.Count.ShouldBeEquivalentTo(1);

                var actualSearchQueryGrouping = actual.As <SearchQueryGrouping <TestIndexableEntity> >().SearchQueryElements.First().As <SearchQueryGrouping <TestIndexableEntity> >();
                actualSearchQueryGrouping.LogicalOperator.ShouldBeEquivalentTo(logicalOperator);
                actualSearchQueryGrouping.SearchQueryElements.Count.ShouldBeEquivalentTo(0);
            }
        }