mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:59:48 -05:00
* getting table name from a script * add InsertSqlInputBindingOperation * cleanup * move azure functions stuff out of dacfx service * cleanup * add tests * add another test * cleanup * add comments and connection string setting * addressing comments * change name to use add instead of insert
136 lines
5.9 KiB
C#
136 lines
5.9 KiB
C#
using Microsoft.SqlTools.Hosting.Protocol;
|
|
using Microsoft.SqlTools.ServiceLayer.AzureFunctions;
|
|
using Microsoft.SqlTools.ServiceLayer.AzureFunctions.Contracts;
|
|
using Microsoft.SqlTools.ServiceLayer.Utility;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.IntegrationTests.AzureFunctions
|
|
{
|
|
class AzureFunctionsServiceTests
|
|
{
|
|
private string testAzureFunctionsFolder = Path.Combine("..", "..", "..", "AzureFunctions", "AzureFunctionTestFiles");
|
|
|
|
/// <summary>
|
|
/// Verify input binding gets added
|
|
/// </summary>
|
|
[Test]
|
|
public void AddSqlInputBinding()
|
|
{
|
|
// copy the original file because the input binding will be inserted into the file
|
|
string originalFile = Path.Join(testAzureFunctionsFolder, "AzureFunctionsNoBindings.ts");
|
|
string testFile = Path.Join(Path.GetTempPath(), string.Format("InsertSqlInputBinding-{0}.ts", DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")));
|
|
File.Copy(originalFile, testFile, true);
|
|
|
|
AddSqlBindingParams parameters = new AddSqlBindingParams
|
|
{
|
|
bindingType = BindingType.input,
|
|
filePath = testFile,
|
|
functionName = "GetArtists_get",
|
|
objectName = "[dbo].[table1]",
|
|
connectionStringSetting = "SqlConnectionString"
|
|
};
|
|
|
|
AddSqlBindingOperation operation = new AddSqlBindingOperation(parameters);
|
|
ResultStatus result = operation.AddBinding();
|
|
|
|
Assert.True(result.Success);
|
|
Assert.IsNull(result.ErrorMessage);
|
|
|
|
string expectedFileText = File.ReadAllText(Path.Join(testAzureFunctionsFolder, "AzureFunctionsInputBinding.ts"));
|
|
string actualFileText = File.ReadAllText(testFile);
|
|
Assert.AreEqual(expectedFileText, actualFileText);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify output binding gets added
|
|
/// </summary>
|
|
[Test]
|
|
public void AddSqlOutputBinding()
|
|
{
|
|
// copy the original file because the output binding will be inserted into the file
|
|
string originalFile = Path.Join(testAzureFunctionsFolder, "AzureFunctionsNoBindings.ts");
|
|
string testFile = Path.Join(Path.GetTempPath(), string.Format("InsertSqlOutputBinding-{0}.ts", DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")));
|
|
File.Copy(originalFile, testFile, true);
|
|
|
|
AddSqlBindingParams parameters = new AddSqlBindingParams
|
|
{
|
|
bindingType = BindingType.output,
|
|
filePath = testFile,
|
|
functionName = "NewArtist_post",
|
|
objectName = "[dbo].[table1]",
|
|
connectionStringSetting = "SqlConnectionString"
|
|
};
|
|
|
|
AddSqlBindingOperation operation = new AddSqlBindingOperation(parameters);
|
|
ResultStatus result = operation.AddBinding();
|
|
|
|
Assert.True(result.Success);
|
|
Assert.IsNull(result.ErrorMessage);
|
|
|
|
string expectedFileText = File.ReadAllText(Path.Join(testAzureFunctionsFolder, "AzureFunctionsOutputBinding.ts"));
|
|
string actualFileText = File.ReadAllText(testFile);
|
|
Assert.AreEqual(expectedFileText, actualFileText);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify what happens when specified azure function isn't found
|
|
/// </summary>
|
|
[Test]
|
|
public void NoAzureFunctionForSqlBinding()
|
|
{
|
|
// copy the original file because the input binding will be inserted into the file
|
|
string originalFile = Path.Join(testAzureFunctionsFolder, "AzureFunctionsNoBindings.ts");
|
|
string testFile = Path.Join(Path.GetTempPath(), string.Format("NoAzureFunctionForSqlBinding-{0}.ts", DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")));
|
|
File.Copy(originalFile, testFile, true);
|
|
|
|
AddSqlBindingParams parameters = new AddSqlBindingParams
|
|
{
|
|
bindingType = BindingType.input,
|
|
filePath = testFile,
|
|
functionName = "noExistingFunction",
|
|
objectName = "[dbo].[table1]",
|
|
connectionStringSetting = "SqlConnectionString"
|
|
};
|
|
|
|
AddSqlBindingOperation operation = new AddSqlBindingOperation(parameters);
|
|
ResultStatus result = operation.AddBinding();
|
|
|
|
Assert.False(result.Success);
|
|
Assert.NotNull(result.ErrorMessage);
|
|
Assert.True(result.ErrorMessage.Equals(SR.CouldntFindAzureFunction("noExistingFunction", testFile)));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Verify what happens when there's more than one Azure function with the specified name in the file
|
|
/// </summary>
|
|
[Test]
|
|
public void MoreThanOneAzureFunctionWithSpecifiedName()
|
|
{
|
|
// copy the original file because the input binding will be inserted into the file
|
|
string originalFile = Path.Join(testAzureFunctionsFolder, "AzureFunctionsMultipleSameFunction.ts");
|
|
string testFile = Path.Join(Path.GetTempPath(), string.Format("MoreThanOneAzureFunctionWithSpecifiedName-{0}.ts", DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss")));
|
|
File.Copy(originalFile, testFile, true);
|
|
|
|
AddSqlBindingParams parameters = new AddSqlBindingParams
|
|
{
|
|
bindingType = BindingType.input,
|
|
filePath = testFile,
|
|
functionName = "GetArtists_get",
|
|
objectName = "[dbo].[table1]",
|
|
connectionStringSetting = "SqlConnectionString"
|
|
};
|
|
|
|
AddSqlBindingOperation operation = new AddSqlBindingOperation(parameters);
|
|
ResultStatus result = operation.AddBinding();
|
|
|
|
Assert.False(result.Success);
|
|
Assert.NotNull(result.ErrorMessage);
|
|
Assert.True(result.ErrorMessage.Equals(SR.MoreThanOneAzureFunctionWithName("GetArtists_get", testFile)));
|
|
}
|
|
}
|
|
}
|