mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-19 17:23:55 -05:00
Kusto Auth Refactor Tests (#1148)
* Refactored Kusto.ServiceLayer to pass ConnectionDetails to DataSourceFactory instead of connection string. Created KustoConnectionDetails to map needed details to KustoClient. * Removed unused ScriptingScriptOperation from KustoServiceLayer. * Created DstsAuthenticationManager and moved logic for getting DstsToken. Updated error message for failing to create KustoConnection. * Removed DstsAuthenticationManager.cs. Refactored DataSourceFactory to retrieve UserToken from ConnectionDetails. * Renamed AzureAccountToken in ConnectionDetails to AccountToken. Changed mapping to KustoConnectionDetails based on the AccountToken. * Removed Kusto.Data reference from ConnectionService and ScriptingListObjectsOperation. Moved creation of KustoConnectionStringBuilder to DataSourceFactory * Added accountToken validation to DataSourceFactory Create. * Renamed KustoConnectionDetails to DataSourceConnectionDetails. Renamed AzureToken to AuthToken. * Refactored SchemaState and intellisense out of KustoClient to KustoIntellisenseClient. Added IIntellisenseClient. Added unit tests for KustoIntellisenseClient and KustoClient. * Removed unused property dataSourceFactory from LanguageService > InitializeService. Moved KustoIntellisense functions from KustoIntellisenseHelper to KustoIntellisenseClient and made SchemaState private. Added IIntellisenseClient to IDataSource. * Renamed directory from DataSourceIntellisense to Intellisense and updated namespace. Fixed namespace in ScriptDocumentInfo.
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Microsoft.Kusto.ServiceLayer.DataSource;
|
||||
using Microsoft.Kusto.ServiceLayer.DataSource.Contracts;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Microsoft.Kusto.ServiceLayer.UnitTests.DataSource
|
||||
{
|
||||
public class KustoClientTests
|
||||
{
|
||||
[Test]
|
||||
public void Constructor_Throws_ArgumentException_For_MissingToken()
|
||||
{
|
||||
var connectionDetails = new DataSourceConnectionDetails
|
||||
{
|
||||
UserToken = ""
|
||||
};
|
||||
|
||||
Assert.Throws<ArgumentException>(() => new KustoClient(connectionDetails, "ownerUri"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Constructor_Sets_ClusterName_With_DefaultDatabaseName()
|
||||
{
|
||||
string clusterName = "https://fake.url.com";
|
||||
var connectionDetails = new DataSourceConnectionDetails
|
||||
{
|
||||
UserToken = "UserToken",
|
||||
ServerName = clusterName,
|
||||
DatabaseName = "",
|
||||
AuthenticationType = "AzureMFA"
|
||||
};
|
||||
|
||||
var client = new KustoClient(connectionDetails, "ownerUri");
|
||||
|
||||
Assert.AreEqual(clusterName, client.ClusterName);
|
||||
Assert.AreEqual("NetDefaultDB", client.DatabaseName);
|
||||
}
|
||||
|
||||
[TestCase("dstsAuth")]
|
||||
[TestCase("AzureMFA")]
|
||||
public void Constructor_Creates_Client_With_Valid_AuthenticationType(string authenticationType)
|
||||
{
|
||||
string clusterName = "https://fake.url.com";
|
||||
var connectionDetails = new DataSourceConnectionDetails
|
||||
{
|
||||
UserToken = "UserToken",
|
||||
ServerName = clusterName,
|
||||
DatabaseName = "FakeDatabaseName",
|
||||
AuthenticationType = authenticationType
|
||||
};
|
||||
|
||||
var client = new KustoClient(connectionDetails, "ownerUri");
|
||||
|
||||
Assert.AreEqual(clusterName, client.ClusterName);
|
||||
Assert.AreEqual("FakeDatabaseName", client.DatabaseName);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user