Files
sqltoolsservice/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Agent/AgentScheduleTests.cs
Karl Burtram f288bee294 Make nullable warnings a per file opt-in (#1842)
* Make nullable warnings a per file opt-in

* Remove unneeded compiler directives

* Remove compiler directive for User Data
2023-02-03 18:10:07 -08:00

120 lines
4.7 KiB
C#

//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
#nullable disable
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 Moq;
using NUnit.Framework;
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.Agent
{
public class AgentScheduleTests
{
/// <summary>
/// HandleAgentSchedulesRequest
/// </summary>
[Test]
public async Task HandleAgentSchedulesRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
// setup
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
var service = new AgentService();
// test
var context = new Mock<RequestContext<AgentSchedulesResult>>();
await service.HandleAgentSchedulesRequest(new AgentSchedulesParams
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri
}, context.Object);
context.VerifyAll();
}
}
/// <summary>
/// TestHandleCreateAgentScheduleRequest
/// </summary>
[Test]
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>
[Test]
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>
[Test]
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);
}
}
}
}