Files
sqltoolsservice/test/Microsoft.SqlTools.ServiceLayer.IntegrationTests/Agent/AgentProxyTests.cs
Karl Burtram 704b25f082 Add Get Alerts and Get Operators handlers (#648)
* Stage changes

* stage changes 2

* WIP 3

* Add Get Alerts and Get Operators handlers

* Add Get Proxy request handler
2018-06-28 21:12:10 -07:00

117 lines
5.0 KiB
C#

//
// 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.Security;
using Microsoft.SqlTools.ServiceLayer.IntegrationTests.Utility;
using Microsoft.SqlTools.ServiceLayer.Security;
using Microsoft.SqlTools.ServiceLayer.Security.Contracts;
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 AgentProxyTests
{
/// <summary>
/// Verify default agent/proxies handlers
/// </summary>
[Fact]
public async Task TestHandleAgentProxiesRequest()
{
using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
{
var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath);
var requestParams = new AgentProxiesParams()
{
OwnerUri = connectionResult.ConnectionInfo.OwnerUri
};
var requestContext = new Mock<RequestContext<AgentProxiesResult>>();
AgentService service = new AgentService();
await service.HandleAgentProxiesRequest(requestParams, requestContext.Object);
requestContext.VerifyAll();
}
}
/// <summary>
/// TestHandleCreateAgentProxyRequest
/// </summary>
[Fact]
public async Task TestHandleCreateAgentProxyRequest()
{
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);
// test
await AgentTestUtils.CreateAgentProxy(service, connectionResult, proxy);
// cleanup
await AgentTestUtils.DeleteAgentProxy(service, connectionResult, proxy);
await SecurityTestUtils.CleanupCredential(connectionResult, credential);
}
}
/// <summary>
/// Verify the default "update agent alert" request handler with valid parameters
/// </summary>
[Fact]
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);
}
}
/// <summary>
/// TestHandleDeleteAgentProxyRequest
/// </summary>
[Fact]
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);
}
}
}
}