Add initial schedule request handlers (#638)

This commit is contained in:
Karl Burtram
2018-06-18 10:18:23 -07:00
committed by GitHub
parent d2cc376b87
commit 29fb715ad5
10 changed files with 555 additions and 279 deletions

View File

@@ -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();

View File

@@ -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);
}
}
}
}

View File

@@ -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);
}
}
}