mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-04 01:25:43 -05:00
Add initial schedule request handlers (#638)
This commit is contained in:
@@ -53,7 +53,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
// cleanup
|
||||
// setup
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
var credential = await SecurityTestUtils.SetupCredential(connectionResult);
|
||||
var service = new AgentService();
|
||||
@@ -80,7 +80,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
{
|
||||
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
|
||||
{
|
||||
// cleanup
|
||||
// setup
|
||||
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
|
||||
var credential = await SecurityTestUtils.SetupCredential(connectionResult);
|
||||
var service = new AgentService();
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.SqlTools.Hosting.Protocol;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent;
|
||||
using Microsoft.SqlTools.ServiceLayer.Agent.Contracts;
|
||||
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
|
||||
using Microsoft.SqlTools.ServiceLayer.Test.Common;
|
||||
using Microsoft.SqlTools.ServiceLayer.Utility;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using static Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility.LiveConnectionHelper;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
{
|
||||
public class AgentScheduleTests
|
||||
{
|
||||
/// <summary>
|
||||
/// TestHandleCreateAgentScheduleRequest
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestHandleCreateAgentScheduleRequest()
|
||||
{
|
||||
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);
|
||||
|
||||
// test
|
||||
await AgentTestUtils.CreateAgentSchedule(service, connectionResult, schedule);
|
||||
|
||||
// cleanup
|
||||
await AgentTestUtils.DeleteAgentSchedule(service, connectionResult, schedule);
|
||||
await AgentTestUtils.CleanupJob(connectionResult, job);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TestHandleUpdateAgentScheduleRequest
|
||||
/// </summary>
|
||||
[Fact]
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// TestHandleDeleteAgentScheduleRequest
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async Task TestHandleDeleteAgentScheduleRequest()
|
||||
{
|
||||
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
|
||||
await AgentTestUtils.DeleteAgentSchedule(service, connectionResult, schedule);
|
||||
|
||||
// cleanup
|
||||
await AgentTestUtils.CleanupJob(connectionResult, job);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
{
|
||||
public static class AgentTestUtils
|
||||
{
|
||||
public const string TestJobName = "Test Job";
|
||||
|
||||
internal static AgentJobStepInfo GetTestJobStepInfo(
|
||||
TestConnectionResult connectionResult,
|
||||
AgentJobInfo job,
|
||||
@@ -40,7 +42,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
{
|
||||
return new AgentJobInfo()
|
||||
{
|
||||
Name = "Test Job",
|
||||
Name = TestJobName,
|
||||
Owner = "sa",
|
||||
Description = "Test job description",
|
||||
CurrentExecutionStatus = 1,
|
||||
@@ -79,7 +81,17 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
Description = "Test proxy description",
|
||||
IsEnabled = true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
internal static AgentScheduleInfo GetTestScheduleInfo()
|
||||
{
|
||||
return new AgentScheduleInfo()
|
||||
{
|
||||
Name = "Test Schedule",
|
||||
JobName = TestJobName,
|
||||
IsEnabled = true
|
||||
};
|
||||
}
|
||||
|
||||
internal static async Task CreateAgentJob(
|
||||
AgentService service,
|
||||
@@ -211,7 +223,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
Operator = operatorInfo
|
||||
}, context.Object);
|
||||
context.VerifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
internal static async Task CreateAgentProxy(
|
||||
AgentService service,
|
||||
@@ -241,7 +253,7 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
Proxy = proxy
|
||||
}, context.Object);
|
||||
context.VerifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
internal static async Task DeleteAgentProxy(
|
||||
AgentService service,
|
||||
@@ -255,7 +267,51 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
Proxy = proxy
|
||||
}, context.Object);
|
||||
context.VerifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
internal static async Task CreateAgentSchedule(
|
||||
AgentService service,
|
||||
TestConnectionResult connectionResult,
|
||||
AgentScheduleInfo schedule)
|
||||
{
|
||||
var context = new Mock<RequestContext<AgentScheduleResult>>();
|
||||
await service.HandleCreateAgentScheduleRequest(new CreateAgentScheduleParams
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Schedule = schedule
|
||||
}, context.Object);
|
||||
context.VerifyAll();
|
||||
}
|
||||
|
||||
internal static async Task UpdateAgentSchedule(
|
||||
AgentService service,
|
||||
TestConnectionResult connectionResult,
|
||||
string originalScheduleName,
|
||||
AgentScheduleInfo schedule)
|
||||
{
|
||||
var context = new Mock<RequestContext<AgentScheduleResult>>();
|
||||
await service.HandleUpdateAgentScheduleRequest(new UpdateAgentScheduleParams()
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
OriginalScheduleName = originalScheduleName,
|
||||
Schedule = schedule
|
||||
}, context.Object);
|
||||
context.VerifyAll();
|
||||
}
|
||||
|
||||
internal static async Task DeleteAgentSchedule(
|
||||
AgentService service,
|
||||
TestConnectionResult connectionResult,
|
||||
AgentScheduleInfo schedule)
|
||||
{
|
||||
var context = new Mock<RequestContext<ResultStatus>>();
|
||||
await service.HandleDeleteAgentScheduleRequest(new DeleteAgentScheduleParams()
|
||||
{
|
||||
OwnerUri = connectionResult.ConnectionInfo.OwnerUri,
|
||||
Schedule = schedule
|
||||
}, context.Object);
|
||||
context.VerifyAll();
|
||||
}
|
||||
|
||||
internal static async Task<AgentAlertInfo[]> GetAgentAlerts(string connectionUri)
|
||||
{
|
||||
@@ -274,5 +330,22 @@ namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
|
||||
await service.HandleAgentAlertsRequest(requestParams, requestContext.Object);
|
||||
return agentAlerts;
|
||||
}
|
||||
|
||||
public static async Task<AgentJobInfo> SetupJob(TestConnectionResult connectionResult)
|
||||
{
|
||||
var service = new AgentService();
|
||||
var job = GetTestJobInfo();
|
||||
await DeleteAgentJob(service, connectionResult, job);
|
||||
await CreateAgentJob(service, connectionResult, job);
|
||||
return job;
|
||||
}
|
||||
|
||||
public static async Task CleanupJob(
|
||||
TestConnectionResult connectionResult,
|
||||
AgentJobInfo job)
|
||||
{
|
||||
var service = new AgentService();
|
||||
await DeleteAgentJob(service, connectionResult, job);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user