public void GetSqlTextFromInvalidType()
        {
            // Setup:
            // ... Mock up an implementation of ExecuteRequestParamsBase
            // ... Create a query execution service without a connection service or workspace
            //     service (we won't execute code that uses either
            var mockParams   = new Mock <ExecuteRequestParamsBase>().Object;
            var queryService = new QueryExecutionService(null, null);

            // If: I attempt to get query text from the mock params
            // Then: It should throw an exception
            Assert.Throws <InvalidCastException>(() => queryService.GetSqlText(mockParams));
        }
        public void ExecuteDocumentStatementTest()
        {
            string query            = string.Format("{0}{1}GO{1}{0}", Constants.StandardQuery, Environment.NewLine);
            var    workspaceService = GetDefaultWorkspaceService(query);
            var    queryService     = new QueryExecutionService(null, workspaceService);

            var queryParams = new ExecuteDocumentStatementParams {
                OwnerUri = Constants.OwnerUri, Line = 0, Column = 0
            };
            var queryText = queryService.GetSqlText(queryParams);

            // The text should match the standard query
            Assert.Equal(queryText, Constants.StandardQuery);
        }
        public void GetSqlTextFromStringRequest()
        {
            // Setup: 
            // ... Create a query execution service without a connection service or workspace
            //     service (we won't execute code that uses either
            var queryService = new QueryExecutionService(null, null);

            // If: I attempt to get query text from execute string params
            var queryParams = new ExecuteStringParams {OwnerUri = Common.OwnerUri, Query = Common.StandardQuery};
            var queryText = queryService.GetSqlText(queryParams);

            // Then: The text should match the standard query
            Assert.Equal(Common.StandardQuery, queryText);
        }
        private void ExecuteDocumentStatementSameLineHelper(string statement1, string statement2, int cursorColumn, string expectedQueryText)
        {
            string query            = string.Format("{0};{1}", statement1, statement2);
            var    workspaceService = GetDefaultWorkspaceService(query);
            var    queryService     = new QueryExecutionService(null, workspaceService);

            // If a line has multiple statements and the cursor is somewhere in the line
            var queryParams = new ExecuteDocumentStatementParams {
                OwnerUri = Constants.OwnerUri, Line = 0, Column = cursorColumn
            };
            var queryText = queryService.GetSqlText(queryParams);

            // The query text should match the expected statement at the cursor
            Assert.Equal(expectedQueryText, queryText);
        }
        public void GetSqlTextFromDocumentRequestPartial()
        {
            // Setup:
            // ... Create a workspace service with a multi-line constructed query
            string query = string.Format("{0}{1}GO{1}{0}", Common.StandardQuery, Environment.NewLine);
            var workspaceService = GetDefaultWorkspaceService(query);
            var queryService = new QueryExecutionService(null, workspaceService);

            // If: I attempt to get query text from execute document params (partial document)
            var queryParams = new ExecuteDocumentSelectionParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.SubsectionDocument};
            var queryText = queryService.GetSqlText(queryParams);

            // Then: The text should be a subset of the constructed query
            Assert.Contains(queryText, query);
        }
        public void GetSqlTextFromDocumentRequestFull()
        {
            // Setup:
            // ... Create a workspace service with a multi-line constructed query
            // ... Create a query execution service without a connection service (we won't be
            //     executing queries), and the previously created workspace service
            string query = string.Format("{0}{1}GO{1}{0}", Common.StandardQuery, Environment.NewLine);
            var workspaceService = GetDefaultWorkspaceService(query);
            var queryService = new QueryExecutionService(null, workspaceService);

            // If: I attempt to get query text from execute document params (entire document)
            var queryParams = new ExecuteDocumentSelectionParams {OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
            var queryText = queryService.GetSqlText(queryParams);

            // Then: The text should match the constructed query
            Assert.Equal(query, queryText);
        }