Ejemplo n.º 1
0
        public void ParseTest_SingleValueSpecifiedField()
        {
            // Arrange
            const string query = "app:Echo";
            IQueryExpression expected = new ComparisonQueryExpression
                                        {
                Field = "app",
                Comparator = ExpressionComparator.Equals,
                Value = "Echo"
            };

            // Act
            var actual = QueryParser.Parse(query);

            // Assert
            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 2
0
        public void GetDistinctSQLCommandTest_SingleField()
        {
            // Arrange
            IQueryExpression expression = new ComparisonQueryExpression { Field = "app", Comparator = ExpressionComparator.Equals, Value = "Echo" };

            const string field = "user";
            var from = DateTime.Now;
            var to = DateTime.Now.AddDays(1);

            // Act
            var actual = SQLMonitorStoreHelper.GetDistinctSQLCommand(expression, from, to, field);

            // Assert
            Assert.AreEqual(5, actual.Parameters.Count);
            Assert.AreEqual(field, actual.Parameters["@fd0"].Value);
            Assert.AreEqual("app", actual.Parameters["@ff0"].Value);
            Assert.AreEqual("Echo", actual.Parameters["@vf0"].Value);
            Assert.AreEqual(from, actual.Parameters["@fromTimestamp"].Value);
            Assert.AreEqual(to, actual.Parameters["@toTimestamp"].Value);
        }
Ejemplo n.º 3
0
        private static IQueryExpression BuildComparisonExpression(string query)
        {
            string[] elements = query.Split(FIELD_VALUE_INDICATOR.ToCharArray(), 2);

            ComparisonQueryExpression expression = new ComparisonQueryExpression()
            {
                Comparator = ExpressionComparator.Equals,
            };

            if (elements.Length == 1)
            {
                expression.Field = null;
                expression.Value = elements[0];
            }
            else
            {
                expression.Field = elements[0];
                expression.Value = elements[1];
            }

            return expression;
        }
Ejemplo n.º 4
0
        public void GetMessagesSQLCommandTest_SingleExpression()
        {
            // Arrange
            IQueryExpression expression = new ComparisonQueryExpression
                                          {
                                              Field = "app",
                                              Comparator = ExpressionComparator.Equals,
                                              Value = "Echo"
                                          };

            // Act
            var actual = SQLMonitorStoreHelper.GetMessagesSQLCommand(expression);

            // Assert
            Assert.AreEqual(2, actual.Parameters.Count);
            Assert.AreEqual("@ff0", actual.Parameters[1].ParameterName);
            Assert.AreEqual("app", actual.Parameters[1].Value);
            Assert.AreEqual("@vf0", actual.Parameters[0].ParameterName);
            Assert.AreEqual("Echo", actual.Parameters[0].Value);
        }
Ejemplo n.º 5
0
        public void TranslateQueryExpressionToWhereClauseTest_SingleFieldSpecified()
        {
            // Arrange
            IQueryExpression expression = new ComparisonQueryExpression
                                          {
                                              Field = "app",
                                              Comparator = ExpressionComparator.Equals,
                                              Value = "Echo"
                                          };
            const string expected = "[f0].[Value] = @vf0 AND [f0].[Field] = @ff0";
            var parameters = new Dictionary<string, object>();
            var fieldTableAliases = new List<string>();

            // Act
            var actual = SQLMonitorStoreHelper.TranslateQueryExpressionToWhereClause(expression, parameters, fieldTableAliases);

            // Assert
            Assert.AreEqual(expected, actual);
            Assert.AreEqual("app", parameters["@ff0"]);
            Assert.AreEqual("Echo", parameters["@vf0"]);
        }
Ejemplo n.º 6
0
        public void GetMessagesSQLCommandTest_SingleExpression_Since()
        {
            // Arrange
            IQueryExpression expression = new ComparisonQueryExpression
                                          {
                                              Field = "app",
                                              Comparator = ExpressionComparator.Equals,
                                              Value = "Echo"
                                          };

            var since = DateTime.Now;

            // Act
            var actual = SQLMonitorStoreHelper.GetMessagesSQLCommand(expression, since);

            // Assert
            Assert.AreEqual(3, actual.Parameters.Count);
            Assert.AreEqual("app", actual.Parameters["@ff0"].Value);
            Assert.AreEqual("Echo", actual.Parameters["@vf0"].Value);
            Assert.AreEqual(since, actual.Parameters["@fromTimestamp"].Value);
        }
Ejemplo n.º 7
0
        public void GetMessagesSQLCommandTest_SingleExpression_FromTo()
        {
            // Arrange
            IQueryExpression expression = new ComparisonQueryExpression { Field = "app", Comparator = ExpressionComparator.Equals, Value = "Echo" };

            var from = DateTime.Now;
            var to = DateTime.Now.AddDays(1);

            // Act
            var actual = SQLMonitorStoreHelper.GetMessagesSQLCommand(expression, from, to);

            // Assert
            Assert.AreEqual(4, actual.Parameters.Count);
            Assert.AreEqual("app", actual.Parameters["@ff0"].Value);
            Assert.AreEqual("Echo", actual.Parameters["@vf0"].Value);
            Assert.AreEqual(from, actual.Parameters["@fromTimestamp"].Value);
            Assert.AreEqual(to, actual.Parameters["@toTimestamp"].Value);
        }