示例#1
0
        internal async Task TestUpdateWithGarbagePath()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                var service          = new AgentService();
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                //seting up a temp notebook job
                var notebook = AgentTestUtils.SetupNotebookJob(connectionResult).Result;
                //verifying that the notebook is created
                Assert.Equal(true, AgentTestUtils.VerifyNotebook(connectionResult, notebook));

                var updateNotebookContext = new Mock <RequestContext <UpdateAgentNotebookResult> >();
                updateNotebookContext.Setup(x => x.SendResult(It.IsAny <UpdateAgentNotebookResult>())).Returns(Task.FromResult(new object()));
                //calling the endpoint with a garbage path
                await service.HandleUpdateAgentNotebookRequest(new UpdateAgentNotebookParams()
                {
                    OwnerUri         = connectionResult.ConnectionInfo.OwnerUri,
                    Notebook         = notebook,
                    TemplateFilePath = "garbargepath"
                }, updateNotebookContext.Object);

                //the enpoint should return false
                updateNotebookContext.Verify(x => x.SendResult(It.Is <UpdateAgentNotebookResult>(p => p.Success == false)));

                //cleaning up the job
                await AgentTestUtils.CleanupNotebookJob(connectionResult, notebook);

                Assert.Equal(false, AgentTestUtils.VerifyNotebook(connectionResult, notebook));
            }
        }
示例#2
0
        internal async Task TestDuplicateJobCreation()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                var service          = new AgentService();
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                AgentNotebookInfo notebook = AgentTestUtils.GetTestNotebookInfo("myTestNotebookJob" + Guid.NewGuid().ToString(), "master");
                var createNotebookContext  = new Mock <RequestContext <CreateAgentNotebookResult> >();
                createNotebookContext.Setup(x => x.SendResult(It.IsAny <CreateAgentNotebookResult>())).Returns(Task.FromResult(new object()));
                await service.HandleCreateAgentNotebookRequest(new CreateAgentNotebookParams()
                {
                    OwnerUri         = connectionResult.ConnectionInfo.OwnerUri,
                    Notebook         = notebook,
                    TemplateFilePath = AgentTestUtils.CreateTemplateNotebookFile()
                }, createNotebookContext.Object);

                createNotebookContext.Verify(x => x.SendResult(It.Is <CreateAgentNotebookResult>(p => p.Success == true)));
                await service.HandleCreateAgentNotebookRequest(new CreateAgentNotebookParams()
                {
                    OwnerUri         = connectionResult.ConnectionInfo.OwnerUri,
                    Notebook         = notebook,
                    TemplateFilePath = AgentTestUtils.CreateTemplateNotebookFile()
                }, createNotebookContext.Object);

                createNotebookContext.Verify(x => x.SendResult(It.Is <CreateAgentNotebookResult>(p => p.Success == false)));
                await AgentTestUtils.CleanupNotebookJob(connectionResult, notebook);
            }
        }
示例#3
0
        internal async Task TestDeletingUpdatedJob()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                var service          = new AgentService();
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                //seting up a temp notebook job
                var notebook = AgentTestUtils.SetupNotebookJob(connectionResult).Result;
                //verifying that the notebook is created
                Assert.Equal(true, AgentTestUtils.VerifyNotebook(connectionResult, notebook));

                var originalName = notebook.Name;
                //Changing the notebookName
                notebook.Name = "myTestNotebookJob" + Guid.NewGuid().ToString();

                Assert.Equal(false, AgentTestUtils.VerifyNotebook(connectionResult, notebook));

                await AgentNotebookHelper.UpdateNotebook(
                    service,
                    connectionResult.ConnectionInfo.OwnerUri,
                    originalName,
                    notebook,
                    null,
                    ManagementUtils.asRunType(0)
                    );

                Assert.Equal(true, AgentTestUtils.VerifyNotebook(connectionResult, notebook));

                //cleaning up the job
                await AgentTestUtils.CleanupNotebookJob(connectionResult, notebook);
            }
        }
示例#4
0
        internal async Task TestDeleteAgentNotebookHandler()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                var service          = new AgentService();
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                //creating a notebook job
                AgentNotebookInfo notebook = AgentTestUtils.SetupNotebookJob(connectionResult).Result;
                //verifying it's getting created
                Assert.Equal(true, AgentTestUtils.VerifyNotebook(connectionResult, notebook));
                //deleting the notebook job
                var deleteNotebookContext = new Mock <RequestContext <ResultStatus> >();
                deleteNotebookContext.Setup(x => x.SendResult(It.IsAny <ResultStatus>())).Returns(Task.FromResult(new object()));
                await service.HandleDeleteAgentNotebooksRequest(new DeleteAgentNotebookParams()
                {
                    OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
                    Notebook = notebook
                }, deleteNotebookContext.Object);

                deleteNotebookContext.Verify(x => x.SendResult(It.Is <ResultStatus>(p => p.Success == true)));
                //verifying if the job is deleted
                Assert.Equal(false, AgentTestUtils.VerifyNotebook(connectionResult, notebook));
            }
        }
示例#5
0
        public async Task TestHandleUpdateAgentScheduleRequest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                // setup
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                var service = new AgentService();
                var job     = await AgentTestUtils.SetupJob(connectionResult);

                var schedule = AgentTestUtils.GetTestScheduleInfo();
                await AgentTestUtils.DeleteAgentSchedule(service, connectionResult, schedule);

                await AgentTestUtils.CreateAgentSchedule(service, connectionResult, schedule);

                // test
                schedule.IsEnabled = !schedule.IsEnabled;
                await AgentTestUtils.UpdateAgentSchedule(service, connectionResult, schedule.Name, schedule);

                // cleanup
                await AgentTestUtils.DeleteAgentSchedule(service, connectionResult, schedule);

                await AgentTestUtils.CleanupJob(connectionResult, job);
            }
        }
        public async Task TestHandleUpdateAgentProxyRequest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                // setup
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                var credential = await SecurityTestUtils.SetupCredential(connectionResult);

                var service = new AgentService();
                var proxy   = AgentTestUtils.GetTestProxyInfo();
                await AgentTestUtils.DeleteAgentProxy(service, connectionResult, proxy);

                await AgentTestUtils.CreateAgentProxy(service, connectionResult, proxy);

                // test
                string originalProxyName = proxy.AccountName;
                proxy.AccountName = proxy.AccountName + " Updated";
                await AgentTestUtils.UpdateAgentProxy(service, connectionResult, originalProxyName, proxy);

                // cleanup
                await AgentTestUtils.DeleteAgentProxy(service, connectionResult, proxy);

                await SecurityTestUtils.CleanupCredential(connectionResult, credential);
            }
        }
示例#7
0
        internal async Task TestAgentNotebookCreateHelper()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                AgentNotebookInfo notebook = AgentTestUtils.GetTestNotebookInfo("myTestNotebookJob" + Guid.NewGuid().ToString(), "master");
                Assert.Equal(false, AgentTestUtils.VerifyNotebook(connectionResult, notebook));
                notebook = AgentTestUtils.SetupNotebookJob(connectionResult).Result;
                Assert.Equal(true, AgentTestUtils.VerifyNotebook(connectionResult, notebook));
                await AgentTestUtils.CleanupNotebookJob(connectionResult, notebook);
            }
        }
        public async Task TestHandleDeleteAgentOperatorRequest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                // setup
                var service          = new AgentService();
                var operatorInfo     = AgentTestUtils.GetTestOperatorInfo();
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                await AgentTestUtils.DeleteAgentOperator(service, connectionResult, operatorInfo);

                await AgentTestUtils.CreateAgentOperator(service, connectionResult, operatorInfo);

                // test
                await AgentTestUtils.DeleteAgentOperator(service, connectionResult, operatorInfo);
            }
        }
示例#9
0
        public async Task TestHandleDeleteAgentJobRequest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                // setup
                var service          = new AgentService();
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                var job = AgentTestUtils.GetTestJobInfo();
                await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify : false);

                await AgentTestUtils.CreateAgentJob(service, connectionResult, job);

                // test
                await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify : false);
            }
        }
        public async Task TestHandleDeleteAgentProxyRequest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                // setup
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                var credential = await SecurityTestUtils.SetupCredential(connectionResult);

                var service = new AgentService();
                var proxy   = AgentTestUtils.GetTestProxyInfo();

                // test
                await AgentTestUtils.DeleteAgentProxy(service, connectionResult, proxy);

                await SecurityTestUtils.CleanupCredential(connectionResult, credential);
            }
        }
示例#11
0
        internal async Task TestDeleteNonExistentJob()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                var service          = new AgentService();
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                //getting a test notebook object
                var notebook = AgentTestUtils.GetTestNotebookInfo("myTestNotebookJob" + Guid.NewGuid().ToString(), "master");

                var deleteNotebookContext = new Mock <RequestContext <ResultStatus> >();
                deleteNotebookContext.Setup(x => x.SendResult(It.IsAny <ResultStatus>())).Returns(Task.FromResult(new object()));
                await service.HandleDeleteAgentNotebooksRequest(new DeleteAgentNotebookParams()
                {
                    OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
                    Notebook = notebook
                }, deleteNotebookContext.Object);

                //endpoint should error out
                deleteNotebookContext.Verify(x => x.SendResult(It.Is <ResultStatus>(p => p.Success == false)));
            }
        }
        public async Task TestHandleUpdateAgentJobStepRequest()
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                // setup
                var service          = new AgentService();
                var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);

                var job = AgentTestUtils.GetTestJobInfo();
                await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify : false);

                await AgentTestUtils.CreateAgentJob(service, connectionResult, job);

                var stepInfo = AgentTestUtils.GetTestJobStepInfo(connectionResult, job);
                await AgentTestUtils.CreateAgentJobStep(service, connectionResult, stepInfo);

                // test
                stepInfo.Script = "SELECT * FROM sys.objects";
                await AgentTestUtils.UpdateAgentJobStep(service, connectionResult, stepInfo);

                // cleanup
                await AgentTestUtils.DeleteAgentJob(service, connectionResult, job, verify : false);
            }
        }