コード例 #1
0
        public void FieldsParameter002()
        {
            // Arrange
            var    expected = JObject.Parse(@"
            {
              ""fields"": [
                ""_id_"",
                ""_score_""
              ]
            }");
            string actual;
            var    jObject           = new JObject();
            var    expressionCache   = new ExpressionCache <TestDocument>();
            var    expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache);
            var    parameter         = new FieldsParameter <TestDocument>(expressionBuilder);

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

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

            // Assert
            Assert.Equal(expected.ToString(), actual);
        }
コード例 #2
0
        public void FieldsParameter005()
        {
            // Arrange
            var expressionCache   = new ExpressionCache <TestDocument>();
            var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache);
            var parameter         = new FieldsParameter <TestDocument>(expressionBuilder);

            // Act / Assert
            Assert.Throws <ArgumentException>(() => parameter.Configure(new Expression <Func <TestDocument, object> >[] { }));
        }
コード例 #3
0
        public void FieldsParameter004()
        {
            // Arrange
            var expressionCache   = new ExpressionCache <TestDocument>();
            var expressionBuilder = (IExpressionBuilder <TestDocument>) new ExpressionBuilder <TestDocument>(expressionCache);
            var parameter         = new FieldsParameter <TestDocument>(expressionBuilder);

            // Act / Assert
            Assert.Throws <ArgumentNullException>(() => parameter.Configure(null));
        }
コード例 #4
0
        public void FieldsParameter003()
        {
            // Arrange
            bool   actual;
            string dummy;
            var    expressionCache   = new ExpressionCache <TestDocumentWithAttribute>();
            var    expressionBuilder = (IExpressionBuilder <TestDocumentWithAttribute>) new ExpressionBuilder <TestDocumentWithAttribute>(expressionCache);
            var    parameter         = new FieldsParameter <TestDocumentWithAttribute>(expressionBuilder);

            parameter.Configure(q => q.Stored, q => q.NotStored);

            // Act
            parameter.Validate(out actual, out dummy);

            // Assert
            Assert.False(actual);
        }
コード例 #5
0
        public void FieldsParameter006()
        {
            // Arrange
            bool   isValid;
            string errorMessage;
            var    expressionCache   = new ExpressionCache <TestDocumentWithAttribute>();
            var    expressionBuilder = (IExpressionBuilder <TestDocumentWithAttribute>) new ExpressionBuilder <TestDocumentWithAttribute>(expressionCache);
            var    parameter         = new FieldsParameter <TestDocumentWithAttribute>(expressionBuilder);

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

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

            // Assert
            Assert.True(isValid);
        }
コード例 #6
0
        public void FieldsParameter007()
        {
            // Arrange
            bool   isValid;
            string errorMessage;
            var    expressionCache   = new ExpressionCache <TestDocumentWithAttribute>();
            var    expressionBuilder = (IExpressionBuilder <TestDocumentWithAttribute>) new ExpressionBuilder <TestDocumentWithAttribute>(expressionCache);
            var    parameter         = new FieldsParameter <TestDocumentWithAttribute>(expressionBuilder);

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

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

            // Assert
            Assert.False(isValid);
            Assert.Equal(Resource.FieldMustBeStoredTrueToBeUsedInFieldsException, errorMessage);
        }