Example #1
0
        private async Task <Mock <RequestContext <ScriptingResult> > > SendAndValidateScriptRequest(bool isSelectScript)
        {
            var result         = GetLiveAutoCompleteTestObjects();
            var requestContext = new Mock <RequestContext <ScriptingResult> >();

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

            var scriptingParams = new ScriptingParams
            {
                OwnerUri = ConnectionService.BuildConnectionString(result.ConnectionInfo.ConnectionDetails)
            };

            if (isSelectScript)
            {
                scriptingParams.ScriptOptions = new ScriptOptions {
                    ScriptCreateDrop = "ScriptSelect"
                };
                List <ScriptingObject> scriptingObjects = new List <ScriptingObject>();
                scriptingObjects.Add(new ScriptingObject {
                    Type = "View", Name = "sysobjects", Schema = "sys"
                });
                scriptingParams.ScriptingObjects = scriptingObjects;
            }
            ScriptingService service = new ScriptingService();
            await service.HandleScriptExecuteRequest(scriptingParams, requestContext.Object);

            return(requestContext);
        }
Example #2
0
        private async Task VerifyScriptAsForMultipleObjects(string query, List <ScriptingObject> scriptingObjects, ScriptingOperationType operation, List <string> expectedScripts)
        {
            var testDb = await SqlTestDb.CreateNewAsync(TestServerType.OnPrem, false, null, query, "ScriptingTests");

            try
            {
                var requestContext = new Mock <RequestContext <ScriptingResult> >();
                requestContext.Setup(x => x.SendResult(It.IsAny <ScriptingResult>())).Returns(Task.FromResult(new object()));
                ConnectionService connectionService = LiveConnectionHelper.GetLiveTestConnectionService();
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    //Opening a connection to db to lock the db
                    TestConnectionResult connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync(testDb.DatabaseName, queryTempFile.FilePath, ConnectionType.Default);

                    var scriptingParams = new ScriptingParams
                    {
                        OwnerUri          = queryTempFile.FilePath,
                        ScriptDestination = "ToEditor",
                        Operation         = operation
                    };

                    string scriptCreateOperation = "ScriptCreate";
                    if (operation == ScriptingOperationType.Delete)
                    {
                        scriptCreateOperation = "ScriptDrop";
                    }
                    else
                    {
                        scriptCreateOperation = $"Script{operation}";
                    }

                    scriptingParams.ScriptOptions = new ScriptOptions
                    {
                        ScriptCreateDrop = scriptCreateOperation,
                    };

                    scriptingParams.ScriptingObjects = scriptingObjects;


                    ScriptingService service = new ScriptingService();
                    await service.HandleScriptExecuteRequest(scriptingParams, requestContext.Object);

                    Thread.Sleep(2000);
                    await service.ScriptingTask;

                    requestContext.Verify(x => x.SendResult(It.Is <ScriptingResult>(r => VerifyScriptingResult(r, expectedScripts))));
                    connectionService.Disconnect(new ServiceLayer.Connection.Contracts.DisconnectParams
                    {
                        OwnerUri = queryTempFile.FilePath
                    });
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                await testDb.CleanupAsync();
            }
        }