Beispiel #1
0
        public void Suggest_Basics()
        {
            SampleDatabase.EnsureBuilt();
            QuerySuggester suggester = new QuerySuggester(SampleDatabase.XDatabaseContext);

            // Verbs
            Assert.AreEqual(s_verbs, Values(suggester.Suggest("")));
            Assert.AreEqual(s_verbs, Values(suggester.Suggest("re")));

            // Tables
            Assert.AreEqual(s_sources, Values(suggester.Suggest("read")));

            // Valid
            Assert.AreEqual(null, Values(suggester.Suggest($"read WebRequest")));

            // Verbs (newline)
            Assert.AreEqual(s_verbs, Values(suggester.Suggest($"read WebRequest\r\n")));
            Assert.AreEqual(s_verbs, Values(suggester.Suggest($"read WebRequest\r\n ")));

            // CompareOperator
            Assert.AreEqual("!=|:|::||>|<|<=|<>|=|==|>|>=", Values(suggester.Suggest($@"
                read WebRequest
                where [HttpStatus] !")));

            // Value missing
            Assert.AreEqual(s_selectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                where [HttpStatus] != ")));

            // ColumnFunctionOrLiteral
            Assert.AreEqual(s_selectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                select")));

            // Function argument (type)
            Assert.AreEqual(s_types, Values(suggester.Suggest($@"
                read WebRequest
                select Trim(Cast(Cast(5, Int32), ")));

            // Function argument (ColumnFunctionOrLiteral)
            Assert.AreEqual(s_stringSelectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                select Trim(")));

            // Nested Function argument (ColumnFunctionOrLiteral)
            Assert.AreEqual(s_stringSelectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                select Cast(Trim(")));

            // Correct nested function use
            Assert.AreEqual(true, suggester.Suggest($@"
                read WebRequest
                select Trim(Cast(Cast(5, Int32), String8)) AS [Fiver]").IsValid);

            // Select next argument
            Assert.AreEqual(s_selectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                select [HttpStatus]")));
        }
Beispiel #2
0
        public void Suggest_NoErrorsForValidValues()
        {
            SampleDatabase.EnsureBuilt();
            QuerySuggester suggester = new QuerySuggester(SampleDatabase.XDatabaseContext);

            // No error on constant
            Assert.AreEqual("", suggester.Suggest($@"
                read WebRequest
                where Cast([HttpStatus], UInt16) < 10").Context.ErrorMessage);
        }
Beispiel #3
0
        public HttpService(XDatabaseContext xDatabaseContext)
        {
            _xDatabaseContext = xDatabaseContext;
            _suggester        = new QuerySuggester(_xDatabaseContext);

            _server = new BackgroundWebServer(5073, "index.html", "Web");
            _server.AddResponder("suggest", Suggest);
            _server.AddResponder("run", Run);
            _server.AddResponder("download", Download);
            _server.AddResponder("count", CountWithinTimeout);
            _server.AddResponder("save", Save);
            _server.AddResponder("test", Test);
        }
Beispiel #4
0
        public void Suggest_FullErrorFidelity()
        {
            SampleDatabase.EnsureBuilt();
            QuerySuggester suggester = new QuerySuggester(SampleDatabase.XDatabaseContext);

            SuggestResult result = suggester.Suggest(@"
                read UsageError.WebRequest.MissingColumn");

            Assert.AreEqual(false, result.IsValid);
            Assert.AreEqual("UsageError.WebRequest.MissingColumn", result.Context.TableName);
            Assert.AreEqual(2, result.Context.QueryLineNumber);
            Assert.AreEqual("where {Expression}", result.Context.Usage);
            Assert.AreEqual("BadColumnName", result.Context.InvalidValue);
            Assert.AreEqual("[Column]", result.Context.InvalidValueCategory);
            Assert.AreEqual(s_columnNames, string.Join("|", result.Context.ValidValues));
        }
Beispiel #5
0
        public void Suggest_FullErrorFidelity()
        {
            SampleDatabase.EnsureBuilt();
            QuerySuggester suggester = new QuerySuggester(SampleDatabase.XDatabaseContext);

            SuggestResult result = suggester.Suggest(@"
                read WebRequest
                where [BadColumnName] != ""X""");

            Assert.AreEqual(false, result.IsValid);
            Assert.AreEqual(null, result.Context.TableName);
            Assert.AreEqual(3, result.Context.QueryLineNumber);
            Assert.AreEqual("where {Expression}", result.Context.Usage);
            Assert.AreEqual("[BadColumnName]", result.Context.InvalidValue);
            Assert.AreEqual("[Column]", result.Context.InvalidValueCategory);
            Assert.AreEqual("[ClientBrowser]|[ClientIP]|[ClientOs]|[ClientRegion]|[DataCenter]|[DaysSinceJoined]|[EventTime]|[HttpMethod]|[HttpStatus]|[ID]|[IsPremiumUser]|[Protocol]|[RequestBytes]|[ResponseBytes]|[ServerName]|[ServerPort]|[TimeTakenMs]|[UriStem]|[UserGuid]|[UserName]|[WasCachedResponse]|[WasEncrypted]", string.Join("|", result.Context.ValidValues));
        }
Beispiel #6
0
        public void Suggest_NoErrorOnLastToken()
        {
            SampleDatabase.EnsureBuilt();
            QuerySuggester suggester = new QuerySuggester(SampleDatabase.XDatabaseContext);

            // Verify errors only when token is complete and you've moved on
            Assert.AreEqual("", suggester.Suggest("read BadTable").Context.ErrorMessage);
            Assert.AreNotEqual("", suggester.Suggest("read BadTable\r\n").Context.ErrorMessage);
            Assert.AreEqual("", suggester.Suggest("read WebRequest\r\ncase").Context.ErrorMessage);
            Assert.AreNotEqual("", suggester.Suggest("read WebRequest\r\ncase ").Context.ErrorMessage, "Bad verb 'case' is now complete");
            Assert.AreEqual("", suggester.Suggest("read WebRequest\r\ncast ").Context.ErrorMessage);
            Assert.AreEqual("", suggester.Suggest("read WebRequest\r\ncast [HttpStatur]").Context.ErrorMessage);
            Assert.AreNotEqual("", suggester.Suggest("read WebRequest\r\ncast [HttpStatur] ").Context.ErrorMessage, "Bad column name now complete");
            Assert.AreEqual("", suggester.Suggest("read WebRequest\r\ncast [HttpStatus] Int").Context.ErrorMessage);
            Assert.AreEqual("", suggester.Suggest("read WebRequest\r\ncast [HttpStatus] Int33").Context.ErrorMessage);
            Assert.AreNotEqual("", suggester.Suggest("read WebRequest\r\ncast [HttpStatus] Int33 ").Context.ErrorMessage, "Bad Type name now complete");
            Assert.AreEqual("", suggester.Suggest("read WebRequest\r\ncast [HttpStatus] Int32 ").Context.ErrorMessage, "All Valid, optional not provided");
            Assert.AreNotEqual("", suggester.Suggest("read WebRequest\r\ncast [HttpStatur] Int32").Context.ErrorMessage, "Bad column name isn't last argument");
            Assert.AreNotEqual("", suggester.Suggest("read WebRequest\r\ncase [HttpStatus] Int32").Context.ErrorMessage, "Bad verb isn't last argument");
            Assert.AreNotEqual("", suggester.Suggest("read BadTable\r\ncast [HttpStatus] Int32").Context.ErrorMessage, "Bad table isn't last argument");
        }
Beispiel #7
0
        public void Suggest_Basics()
        {
            SampleDatabase.EnsureBuilt();
            QuerySuggester suggester = new QuerySuggester(SampleDatabase.XDatabaseContext);

            // Verbs
            Assert.AreEqual(s_verbs, Values(suggester.Suggest("")));
            Assert.AreEqual(string.Join("|", XqlParser.SupportedVerbs.Where((s) => s.IndexOf("re", System.StringComparison.OrdinalIgnoreCase) != -1).OrderBy((s) => s)), Values(suggester.Suggest("re")));

            // Valid, other values available
            Assert.AreEqual("read|readrange", Values(suggester.Suggest("read")));

            // Tables
            Assert.AreEqual(s_sources, Values(suggester.Suggest("read ")));

            // Tables, filtered
            Assert.AreEqual("WebRequest.BigServers|WebRequest.BigServers.Direct", Values(suggester.Suggest($"read Request.Big")));

            // Valid, no alternatives
            Assert.AreEqual(null, Values(suggester.Suggest($"read WebRequest.NullableHandling")));

            // Verbs (newline)
            Assert.AreEqual(s_verbs, Values(suggester.Suggest($"read WebRequest\r\n")));
            Assert.AreEqual(s_verbs, Values(suggester.Suggest($"read WebRequest\r\n ")));

            // Valid
            Assert.AreEqual("!=|:|::||>|<|<=|<>|=|==|>|>||>=", Values(suggester.Suggest($@"
                read WebRequest
                where [HttpStatus]")));

            // CompareOperator
            Assert.AreEqual("!=|:|::||>|<|<=|<>|=|==|>|>||>=", Values(suggester.Suggest($@"
                read WebRequest
                where [HttpStatus] ")));

            // CompareOperator [partially typed]
            Assert.AreEqual("!=", Values(suggester.Suggest($@"
                read WebRequest
                where [HttpStatus] !")));

            // Valid
            Assert.AreEqual(null, Values(suggester.Suggest($@"
                read WebRequest
                where [HttpStatus] !=")));

            // Value missing
            Assert.AreEqual(s_selectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                where [HttpStatus] != ")));

            // Valid
            Assert.AreEqual(null, Values(suggester.Suggest($@"
                read WebRequest
                select")));

            // ColumnFunctionOrLiteral
            Assert.AreEqual(s_selectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                select ")));

            // Function argument (type)
            Assert.AreEqual(s_types, Values(suggester.Suggest($@"
                read WebRequest
                select Trim(Cast(Cast(5, Int32), ")));

            // Function argument (ColumnFunctionOrLiteral)
            Assert.AreEqual(s_stringSelectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                select Trim(")));

            Assert.AreEqual(s_stringSelectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                select Trim(")));

            // Nested Function argument (ColumnFunctionOrLiteral)
            Assert.AreEqual(s_stringSelectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                select Cast(Trim(")));

            // Correct nested function use
            Assert.AreEqual(true, suggester.Suggest($@"
                read WebRequest
                select Trim(Cast(Cast(5, Int32), String8)) AS [Fiver]").IsValid);

            // Valid
            Assert.AreEqual(s_selectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                select [HttpStatus]")));

            // Select next argument
            Assert.AreEqual(s_selectListOptions, Values(suggester.Suggest($@"
                read WebRequest
                select [HttpStatus], ")));
        }