Пример #1
0
        private async Task VerifyScriptAs(string query, ScriptingObject scriptingObject, string scriptCreateDrop, string expectedScript)
        {
            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"
                    };

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

                    scriptingParams.ScriptingObjects = new List <ScriptingObject>
                    {
                        scriptingObject
                    };


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

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

                    requestContext.Verify(x => x.SendResult(It.Is <ScriptingResult>(r => VerifyScriptingResult(r, expectedScript))));
                    connectionService.Disconnect(new ServiceLayer.Connection.Contracts.DisconnectParams
                    {
                        OwnerUri = queryTempFile.FilePath
                    });
                }
            }
            catch
            {
                throw;
            }
            finally
            {
                await testDb.CleanupAsync();
            }
        }
        private async Task <Mock <RequestContext <ScriptingScriptAsResult> > > SendAndValidateScriptRequest(ScriptOperation operation, string objectType)
        {
            var result         = GetLiveAutoCompleteTestObjects();
            var requestContext = new Mock <RequestContext <ScriptingScriptAsResult> >();

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

            var scriptingParams = new ScriptingScriptAsParams
            {
                OwnerUri  = result.ConnectionInfo.OwnerUri,
                Operation = operation,
                Metadata  = GenerateMetadata(objectType)
            };

            await ScriptingService.HandleScriptingScriptAsRequest(scriptingParams, requestContext.Object);

            return(requestContext);
        }
Пример #3
0
        private async Task <Mock <RequestContext <ScriptingScriptAsResult> > > SendAndValidateScriptRequest(ScriptOperation operation)
        {
            var result         = GetLiveAutoCompleteTestObjects();
            var requestContext = new Mock <RequestContext <ScriptingScriptAsResult> >();

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

            var scriptingParams = new ScriptingScriptAsParams
            {
                OwnerUri  = result.ConnectionInfo.OwnerUri,
                Operation = operation,
                Metadata  = new ObjectMetadata()
                {
                    MetadataType     = MetadataType.Table,
                    MetadataTypeName = "Table",
                    Schema           = SchemaName,
                    Name             = TableName
                }
            };

            await ScriptingService.HandleScriptingScriptAsRequest(scriptingParams, requestContext.Object);

            return(requestContext);
        }