Example #1
0
        public void FacetFieldParameter002()
        {
            // Arrange
            var    expected = JObject.Parse(@"
            {
              ""facet"": {
                ""Id"": {
                  ""terms"": {
                    ""field"": ""_id_"",
                    ""mincount"": 1,
                    ""sort"": {
                      ""count"": ""desc""
                    }
                  }
                }
              }
            }");
            string actual;
            var    jObject           = new JObject();
            var    expressionCache   = new ExpressionCache <TestDocument>();
            var    expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache);
            var    parameter         = new FacetFieldParameter <TestDocument>(expressionBuilder);

            parameter.Configure(q => q.Id, FacetSortType.CountDesc);

            // Act
            parameter.Execute(jObject);
            actual = jObject.ToString();

            // Assert
            Assert.Equal(expected.ToString(), actual);
        }
Example #2
0
        public void FacetFieldParameter005()
        {
            // Arrange
            var    expected = JObject.Parse(@"
            {
              ""facet"": {
                ""Id"": {
                  ""terms"": {
                    ""field"": ""_id_"",
                    ""mincount"": 1,
                    ""domain"":{
                        ""excludeTags"": [
                            ""tag1"",
                            ""tag2""
                        ]
                    }
                  }
                }
              }
            }");
            string actual;
            var    jObject           = new JObject();
            var    expressionCache   = new ExpressionCache <TestDocument>();
            var    expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache);
            var    parameter         = new FacetFieldParameter <TestDocument>(expressionBuilder);

            parameter.Configure(q => q.Id, excludes: new[] { "tag1", "tag2" });

            // Act
            parameter.Execute(jObject);
            actual = jObject.ToString();

            // Assert
            Assert.Equal(expected.ToString(), actual);
        }
Example #3
0
        public void FacetFieldParameter005()
        {
            // Arrange
            var expressionCache   = new ExpressionCache <TestDocument>();
            var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache);
            var parameter         = new FacetFieldParameter <TestDocument>(expressionBuilder);

            // Act / Assert
            Assert.Throws <ArgumentNullException>(() => parameter.Configure(null));
        }
Example #4
0
        public void FacetFieldParameter004()
        {
            // Arrange
            var container         = new List <string>();
            var expressionCache   = new ExpressionCache <TestDocument>();
            var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache);
            var parameter         = new FacetFieldParameter <TestDocument>(expressionBuilder);

            parameter.Configure(q => q.Id, FacetSortType.IndexDesc);

            // Act / Assert
            Assert.Throws <UnsupportedSortTypeException>(() => parameter.Execute(container));
        }
Example #5
0
        public void FacetFieldParameter006()
        {
            // Arrange
            bool   isValid;
            string errorMessage;
            var    expressionCache   = new ExpressionCache <TestDocumentWithAttribute>();
            var    expressionBuilder = (IExpressionBuilder <TestDocumentWithAttribute>) new ExpressionBuilder <TestDocumentWithAttribute>(expressionCache);
            var    parameter         = new FacetFieldParameter <TestDocumentWithAttribute>(expressionBuilder);

            parameter.Configure(q => q.Indexed);

            // Act
            parameter.Validate(out isValid, out errorMessage);

            // Assert
            Assert.True(isValid);
        }
Example #6
0
        public void FacetFieldParameter007()
        {
            // Arrange
            bool   isValid;
            string errorMessage;
            var    expressionCache   = new ExpressionCache <TestDocumentWithAttribute>();
            var    expressionBuilder = (IExpressionBuilder <TestDocumentWithAttribute>) new ExpressionBuilder <TestDocumentWithAttribute>(expressionCache);
            var    parameter         = new FacetFieldParameter <TestDocumentWithAttribute>(expressionBuilder);

            parameter.Configure(q => q.NotIndexed);

            // Act
            parameter.Validate(out isValid, out errorMessage);

            // Assert
            Assert.False(isValid);
            Assert.Equal(Resource.FieldMustBeIndexedTrueToBeUsedInAFacetException, errorMessage);
        }
Example #7
0
        public void FacetFieldParameter001()
        {
            // Arrange
            var container         = new List <string>();
            var expressionCache   = new ExpressionCache <TestDocument>();
            var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache);
            var parameter         = new FacetFieldParameter <TestDocument>(expressionBuilder);

            parameter.Configure(q => q.Id);

            // Act
            parameter.Execute(container);

            // Assert
            Assert.Equal(3, container.Count);
            Assert.Equal("facet=true", container[0]);
            Assert.Equal("facet.field={!key=Id}_id_", container[1]);
            Assert.Equal("f._id_.facet.mincount=1", container[2]);
        }