예제 #1
0
        public void If_OneMatchConditionGroupWithOneMatchConditionAndDateCondition_ThenReturnCorrectQueryModel()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            tokenSeq.Add(new LqlToken(TokenType.Match));
            tokenSeq.Add(new LqlToken(TokenType.OpenParenthesis));
            tokenSeq.Add(new LqlToken(TokenType.Application));
            tokenSeq.Add(new LqlToken(TokenType.Equals));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'MyApp'"));
            tokenSeq.Add(new LqlToken(TokenType.CloseParenthesis));
            AppendDateCondition(tokenSeq);
            AppendLimitCondition(tokenSeq);

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            var matchCondition = result.Groups.First().MatchConditions.First();

            // ASSERT
            Assert.AreEqual(1, result.Groups.Count()); // only one group
            Assert.AreEqual(1, result.Groups.First().MatchConditions.Count); // only one match condition in group
            Assert.AreEqual(LqlObject.Application, matchCondition.Object);
            Assert.AreEqual(LqlOperator.Equals, matchCondition.Operator);
            Assert.AreEqual("'MyApp'", matchCondition.Value);
            Assert.AreEqual(new DateTime(2016, 1, 1, 10, 0, 0), result.DateRange.From);
            Assert.AreEqual(new DateTime(2016, 1, 2, 10, 0, 0), result.DateRange.To);
        }
예제 #2
0
        public void If_SingleMatchConditionAppNotEquals_ThenReturnAppNotEquals()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            tokenSeq.Add(new LqlToken(TokenType.Match));
            tokenSeq.Add(new LqlToken(TokenType.OpenParenthesis));
            tokenSeq.Add(new LqlToken(TokenType.Application));
            tokenSeq.Add(new LqlToken(TokenType.NotEquals));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'MyApp'"));
            tokenSeq.Add(new LqlToken(TokenType.CloseParenthesis));
            AppendDateCondition(tokenSeq);
            AppendLimitCondition(tokenSeq);

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            var matchCondition = result.Groups.First().MatchConditions.First();

            // ASSERT
            Assert.AreEqual(LqlObject.Application, matchCondition.Object);
            Assert.AreEqual(LqlOperator.NotEquals, matchCondition.Operator);
            Assert.AreEqual("'MyApp'", matchCondition.Value);
        }
예제 #3
0
        public void If_OneMatchConditionGroupWithTwoMatchConditionsWithMixOfAndOr_ThenReturnThrowParserException()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            tokenSeq.Add(new LqlToken(TokenType.Match));
            tokenSeq.Add(new LqlToken(TokenType.OpenParenthesis));
            tokenSeq.Add(new LqlToken(TokenType.Application));
            tokenSeq.Add(new LqlToken(TokenType.Equals));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'MyApp'"));
            tokenSeq.Add(new LqlToken(TokenType.And));
            tokenSeq.Add(new LqlToken(TokenType.ExceptionType));
            tokenSeq.Add(new LqlToken(TokenType.Equals));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'System.Exception'"));
            tokenSeq.Add(new LqlToken(TokenType.Or));
            tokenSeq.Add(new LqlToken(TokenType.ExceptionType));
            tokenSeq.Add(new LqlToken(TokenType.Equals));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'System.NullReferenceException'"));
            tokenSeq.Add(new LqlToken(TokenType.CloseParenthesis));
            AppendDateCondition(tokenSeq);

            // ACT
            var parser = new LqlParser();
            try
            {
                parser.Parse(tokenSeq);
            }
            catch (LqlParserException ex)
            {
                Assert.AreEqual(LqlParser.MixedLogicalOperatorMessage, ex.Message);
            }
        }
예제 #4
0
        public void If_HasMinFrequency_ThenReturnMinFrequency()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            AppendDefaultMatchCondition(tokenSeq);
            AppendDateCondition(tokenSeq);
            tokenSeq.Add(new LqlToken(TokenType.FrequencyGreaterThan));
            tokenSeq.Add(new LqlToken(TokenType.Number, "100"));
            AppendLimitCondition(tokenSeq);

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            // ASSERT
            Assert.AreEqual(100, result.MinFrequency.Value);
        }
예제 #5
0
        public void If_HasCountByMinuteAndIsFraction_ThenReturnCountByMinuteRoundedDown()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            AppendDefaultMatchCondition(tokenSeq);
            AppendDateCondition(tokenSeq);
            tokenSeq.Add(new LqlToken(TokenType.CountBy));
            tokenSeq.Add(new LqlToken(TokenType.CountByValue, "1.5m"));

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            // ASSERT
            Assert.AreEqual(new TimeSpan(0, 0, 1, 0), result.CountByPeriod.Value);
        }
예제 #6
0
        public void If_HasLimit_ThenReturnLimit()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            AppendDefaultMatchCondition(tokenSeq);
            AppendDateCondition(tokenSeq);
            tokenSeq.Add(new LqlToken(TokenType.Limit));
            tokenSeq.Add(new LqlToken(TokenType.Number, "100"));

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            // ASSERT
            Assert.AreEqual(100, result.Limit.Value);
        }
예제 #7
0
        public void If_NotRankingAndNotCountBy_ThenReturnMessagesQueryType()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            AppendDefaultMatchCondition(tokenSeq);
            AppendDateCondition(tokenSeq);
            AppendLimitCondition(tokenSeq);

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            // ASSERT
            Assert.AreEqual(QueryType.Messages, result.QueryType);
        }
예제 #8
0
        public void If_HasCountBy_ThenReturnAggregationQueryType()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            AppendDefaultMatchCondition(tokenSeq);
            AppendDateCondition(tokenSeq);
            tokenSeq.Add(new LqlToken(TokenType.CountBy));
            tokenSeq.Add(new LqlToken(TokenType.CountByValue, "1.5d"));

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            // ASSERT
            Assert.AreEqual(QueryType.Aggregation, result.QueryType);
        }
예제 #9
0
        public void If_HasAsRanking_ThenReturnRankingQueryType()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            AppendDefaultMatchCondition(tokenSeq);
            AppendDateCondition(tokenSeq);
            tokenSeq.Add(new LqlToken(TokenType.AsRanking));
            AppendLimitCondition(tokenSeq);

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            // ASSERT
            Assert.AreEqual(QueryType.Ranking, result.QueryType);
        }
예제 #10
0
        public void If_SingleMatchConditionFingerprintEquals_ThenReturnFingerprintEquals()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            tokenSeq.Add(new LqlToken(TokenType.Match));
            tokenSeq.Add(new LqlToken(TokenType.OpenParenthesis));
            tokenSeq.Add(new LqlToken(TokenType.Fingerprint));
            tokenSeq.Add(new LqlToken(TokenType.Equals));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'C9630DAA7B50F0C3B0E993AC4295A7FD'"));
            tokenSeq.Add(new LqlToken(TokenType.CloseParenthesis));
            AppendDateCondition(tokenSeq);
            AppendLimitCondition(tokenSeq);

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            var matchCondition = result.Groups.First().MatchConditions.First();

            // ASSERT
            Assert.AreEqual(LqlObject.Fingerprint, matchCondition.Object);
            Assert.AreEqual(LqlOperator.Equals, matchCondition.Operator);
            Assert.AreEqual("'C9630DAA7B50F0C3B0E993AC4295A7FD'", matchCondition.Value);
        }
예제 #11
0
        public void If_TwoMatchConditionGroupsWithTwoMatchConditionsAndDateCondition_ThenReturnCorrectQueryModel()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            tokenSeq.Add(new LqlToken(TokenType.Match));
            tokenSeq.Add(new LqlToken(TokenType.OpenParenthesis));
            tokenSeq.Add(new LqlToken(TokenType.Application));
            tokenSeq.Add(new LqlToken(TokenType.Equals));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'MyApp'"));
            tokenSeq.Add(new LqlToken(TokenType.And));
            tokenSeq.Add(new LqlToken(TokenType.ExceptionType));
            tokenSeq.Add(new LqlToken(TokenType.Equals));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'System.Exception'"));
            tokenSeq.Add(new LqlToken(TokenType.CloseParenthesis));
            tokenSeq.Add(new LqlToken(TokenType.Or));
            tokenSeq.Add(new LqlToken(TokenType.OpenParenthesis));
            tokenSeq.Add(new LqlToken(TokenType.Application));
            tokenSeq.Add(new LqlToken(TokenType.Equals));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'MyOtherApp'"));
            tokenSeq.Add(new LqlToken(TokenType.Or));
            tokenSeq.Add(new LqlToken(TokenType.ExceptionType));
            tokenSeq.Add(new LqlToken(TokenType.Equals));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'System.NullReferenceException'"));
            tokenSeq.Add(new LqlToken(TokenType.CloseParenthesis));
            AppendDateCondition(tokenSeq);
            AppendLimitCondition(tokenSeq);

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            // ASSERT
            // two groups
            Assert.AreEqual(2, result.Groups.Count);

            var group1 = result.Groups[0];
            var group2 = result.Groups[1];

            Assert.AreEqual(2, group1.MatchConditions.Count); // two match conditions in group
            Assert.AreEqual(LqlLogicalOperator.And, group1.LogicalOperator);
            Assert.AreEqual(LqlLogicalOperator.Or, group2.LogicalOperator);
            Assert.AreEqual(LqlLogicalOperator.Or, group1.LogicalOperatorToNextGroup);

            var group1MatchCondition1 = group1.MatchConditions[0];
            var group1MatchCondition2 = group1.MatchConditions[1];

            Assert.AreEqual(LqlObject.Application, group1MatchCondition1.Object);
            Assert.AreEqual(LqlOperator.Equals, group1MatchCondition1.Operator);
            Assert.AreEqual("'MyApp'", group1MatchCondition1.Value);

            Assert.AreEqual(LqlObject.ExceptionType, group1MatchCondition2.Object);
            Assert.AreEqual(LqlOperator.Equals, group1MatchCondition2.Operator);
            Assert.AreEqual("'System.Exception'", group1MatchCondition2.Value);

            var group2MatchCondition1 = group2.MatchConditions[0];
            var group2MatchCondition2 = group2.MatchConditions[1];

            Assert.AreEqual(LqlObject.Application, group2MatchCondition1.Object);
            Assert.AreEqual(LqlOperator.Equals, group2MatchCondition1.Operator);
            Assert.AreEqual("'MyOtherApp'", group2MatchCondition1.Value);

            Assert.AreEqual(LqlObject.ExceptionType, group2MatchCondition2.Object);
            Assert.AreEqual(LqlOperator.Equals, group2MatchCondition2.Operator);
            Assert.AreEqual("'System.NullReferenceException'", group2MatchCondition2.Value);

            Assert.AreEqual(new DateTime(2016, 1, 1, 10, 0, 0), result.DateRange.From);
            Assert.AreEqual(new DateTime(2016, 1, 2, 10, 0, 0), result.DateRange.To);
        }
예제 #12
0
        public void If_SingleMatchConditionAppInMultipleItems_ThenReturnAppInMultipleItems()
        {
            // ARRANGE
            var tokenSeq = new List<LqlToken>();
            tokenSeq.Add(new LqlToken(TokenType.Match));
            tokenSeq.Add(new LqlToken(TokenType.OpenParenthesis));
            tokenSeq.Add(new LqlToken(TokenType.Application));
            tokenSeq.Add(new LqlToken(TokenType.In));
            tokenSeq.Add(new LqlToken(TokenType.OpenParenthesis));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'MyApp'"));
            tokenSeq.Add(new LqlToken(TokenType.Comma));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'MyOtherApp'"));
            tokenSeq.Add(new LqlToken(TokenType.Comma));
            tokenSeq.Add(new LqlToken(TokenType.StringValue, "'ThatOtherApp'"));
            tokenSeq.Add(new LqlToken(TokenType.CloseParenthesis));
            tokenSeq.Add(new LqlToken(TokenType.CloseParenthesis));
            AppendDateCondition(tokenSeq);
            AppendLimitCondition(tokenSeq);

            // ACT
            var parser = new LqlParser();
            var result = parser.Parse(tokenSeq);

            var matchCondition = result.Groups.First().MatchConditions.First();

            // ASSERT
            Assert.AreEqual(LqlObject.Application, matchCondition.Object);
            Assert.AreEqual(LqlOperator.In, matchCondition.Operator);
            Assert.AreEqual(3, matchCondition.Values.Count);
            Assert.AreEqual("'MyApp'", matchCondition.Values[0]);
            Assert.AreEqual("'MyOtherApp'", matchCondition.Values[1]);
            Assert.AreEqual("'ThatOtherApp'", matchCondition.Values[2]);
        }