Files
sqltoolsservice/test/Microsoft.Kusto.ServiceLayer.UnitTests/DataSource/DataSourceFactoryTests.cs
Justin M f2eb590d97 3490 Kusto Connection Refresh Fix (#1085)
* 3490 Injected OwnerUri into KustClient to store for token refreshing. Removed UpdateAzureToken from IDataSource, DataSourceBase, and KustoDataSource. Removed logic for retrying queries related to Unauthorized datasource in Batch and Query. Changed ScriptingService, ScriptingScriptOperation, and ScriptAsScriptingOperation to take DataSource in the constructor instead of datasourcefactory. Changed ScriptingService to inject ConnectionService through InitializeService function.

* 3490 Removed Catch block for DataSourceUnauthorizedException in ExecuteControlCommandAsync

* 3490 Removed OwnerUri from KustoClient and used azureAccountToken to refresh token in ConnectionService.

* 3490 Reverted unneeded changes.

* 3490 Split ExecuteQuery in KustoClient to execute first query then remaining queries after

* 3490 Passed OwnerUri down into KustoClient to refresh token.

* 3490 Removed DataSourceUnauthorizedException. Refactored ExecuteQuery to catch aggregate exception. Added RefreshAzureToken logic to ExecuteControlCommand

* 3490 Added logic to update ReliableDataSourceConnection azure token within ConnectionInfo.

* 3490 Add retry logic to ExecuteQuery and ExecuteControlCommand in KustoClient
2020-10-06 17:20:13 -07:00

91 lines
3.6 KiB
C#

using System;
using System.Collections.Generic;
using Microsoft.Kusto.ServiceLayer.DataSource;
using Microsoft.Kusto.ServiceLayer.DataSource.DataSourceIntellisense;
using Microsoft.Kusto.ServiceLayer.LanguageServices.Completion;
using Microsoft.Kusto.ServiceLayer.Workspace.Contracts;
using NUnit.Framework;
namespace Microsoft.Kusto.ServiceLayer.UnitTests.DataSource
{
public class DataSourceFactoryTests
{
[TestCase(typeof(ArgumentNullException), "", "AzureAccountToken")]
[TestCase(typeof(ArgumentNullException), "ConnectionString", "")]
[TestCase(typeof(ArgumentException), "ConnectionString", "AzureAccountToken")]
public void Create_Throws_Exceptions_For_InvalidParams(Type exceptionType,
string connectionString,
string azureAccountToken)
{
var dataSourceFactory = new DataSourceFactory();
Assert.Throws(exceptionType,
() => dataSourceFactory.Create(DataSourceType.None, connectionString, azureAccountToken, ""));
}
[Test]
public void GetDefaultAutoComplete_Throws_ArgumentException_For_InvalidDataSourceType()
{
Assert.Throws<ArgumentException>(() =>
DataSourceFactory.GetDefaultAutoComplete(DataSourceType.None, null, null));
}
[Test]
public void GetDefaultAutoComplete_Returns_CompletionItems()
{
var textDocumentPosition = new TextDocumentPosition
{
Position = new Position()
};
var scriptFile = new ScriptFile("", "", "");
var scriptParseInfo = new ScriptParseInfo();
var documentInfo = new ScriptDocumentInfo(textDocumentPosition, scriptFile, scriptParseInfo);
var position = new Position();
var completionItems = DataSourceFactory.GetDefaultAutoComplete(DataSourceType.Kusto, documentInfo, position);
Assert.AreNotEqual(0, completionItems.Length);
}
[Test]
public void GetDefaultSemanticMarkers_Throws_ArgumentException_For_InvalidDataSourceType()
{
Assert.Throws<ArgumentException>(() =>
DataSourceFactory.GetDefaultSemanticMarkers(DataSourceType.None, null, null, null));
}
[Test]
public void GetDefaultSemanticMarkers_Returns_ScriptFileMarker()
{
var parseInfo = new ScriptParseInfo();
var file = new ScriptFile("", "", "");
var queryText = ".show databases";
var semanticMarkers = DataSourceFactory.GetDefaultSemanticMarkers(DataSourceType.Kusto, parseInfo, file, queryText);
Assert.AreNotEqual(0, semanticMarkers.Length);
}
[Test]
public void ConvertToServerInfoFormat_Throws_ArgumentException_For_InvalidDataSourceType()
{
Assert.Throws<ArgumentException>(() =>
DataSourceFactory.ConvertToServerInfoFormat(DataSourceType.None, null));
}
[Test]
public void ConvertToServerInfoFormat_Returns_ServerInfo_With_Options()
{
var diagnosticsInfo = new DiagnosticsInfo
{
Options = new Dictionary<string, object>
{
{"Key", "Object"}
}
};
var serverInfo = DataSourceFactory.ConvertToServerInfoFormat(DataSourceType.Kusto, diagnosticsInfo);
Assert.IsNotNull(serverInfo.Options);
Assert.AreEqual(diagnosticsInfo.Options["Key"], serverInfo.Options["Key"]);
}
}
}