/// <summary>
        /// Handle a table pr view metadata query request
        /// </summary>
        private static async Task HandleGetTableOrViewRequest(
            TableMetadataParams metadataParams,
            string objectType,
            RequestContext <TableMetadataResult> requestContext)
        {
            try
            {
                ConnectionInfo connInfo;
                MetadataService.ConnectionServiceInstance.TryFindConnection(
                    metadataParams.OwnerUri,
                    out connInfo);

                ColumnMetadata[] metadata = null;
                if (connInfo != null)
                {
                    using (SqlConnection sqlConn = ConnectionService.OpenSqlConnection(connInfo, "Metadata"))
                    {
                        TableMetadata table = new SmoMetadataFactory().GetObjectMetadata(
                            sqlConn, metadataParams.Schema,
                            metadataParams.ObjectName, objectType);
                        metadata = table.Columns;
                    }
                }

                await requestContext.SendResult(new TableMetadataResult
                {
                    Columns = metadata
                });
            }
            catch (Exception ex)
            {
                await requestContext.SendError(ex.ToString());
            }
        }
        public async void GetTableInfoReturnsValidResults()
        {
            this.testTableName += new Random().Next(1000000, 9999999).ToString();

            var result  = GetLiveAutoCompleteTestObjects();
            var sqlConn = MetadataService.OpenMetadataConnection(result.ConnectionInfo);

            CreateTestTable(sqlConn);

            var requestContext = new Mock <RequestContext <TableMetadataResult> >();

            requestContext.Setup(x => x.SendResult(It.IsAny <TableMetadataResult>())).Returns(Task.FromResult(new object()));

            var metadataParmas = new TableMetadataParams
            {
                OwnerUri   = result.ConnectionInfo.OwnerUri,
                Schema     = this.testTableSchema,
                ObjectName = this.testTableName
            };

            await MetadataService.HandleGetTableRequest(metadataParmas, requestContext.Object);

            DeleteTestTable(sqlConn);

            requestContext.VerifyAll();
        }
        public async void GetViewInfoReturnsValidResults()
        {
            var result         = GetLiveAutoCompleteTestObjects();
            var requestContext = new Mock <RequestContext <TableMetadataResult> >();

            requestContext.Setup(x => x.SendResult(It.IsAny <TableMetadataResult>())).Returns(Task.FromResult(new object()));

            var metadataParmas = new TableMetadataParams
            {
                OwnerUri   = result.ConnectionInfo.OwnerUri,
                Schema     = "sys",
                ObjectName = "all_objects"
            };

            await MetadataService.HandleGetViewRequest(metadataParmas, requestContext.Object);

            requestContext.VerifyAll();
        }
 /// <summary>
 /// Handle a view metadata query request
 /// </summary>
 internal static async Task HandleGetViewRequest(
     TableMetadataParams metadataParams,
     RequestContext <TableMetadataResult> requestContext)
 {
     await HandleGetTableOrViewRequest(metadataParams, "view", requestContext);
 }