public async Task ShouldAcceptAccessToken() { var httpClient = new HttpClient(); var response = await httpClient.PostAsync($"https://login.microsoftonline.com/{Config.AccessTokenCredentials.Tenant}/oauth2/v2.0/token", new FormUrlEncodedContent(new Dictionary <string, string>() { { "grant_type", "client_credentials" }, { "scope", "2ff814a6-3304-4ab8-85cb-cd0e6f879c1d/.default" }, { "client_id", Config.AccessTokenCredentials.ClientId }, { "client_secret", Config.AccessTokenCredentials.ClientSecret }, })); response.EnsureSuccessStatusCode(); var accessToken = JsonConvert.DeserializeObject <JObject>(await response.Content.ReadAsStringAsync())["access_token"].ToString(); // Arrange var connectionStringBuilder = new SparkConnectionStringBuilder(Config.ConnectionString); await using var conn = new SparkConnection($"Data Source={connectionStringBuilder.DataSource}"); conn.AccessToken = accessToken; // Assert and Act conn.Open(); Assert.Equal(ConnectionState.Open, conn.State); }
public void WhenParsingConnectionStringShouldParseImportantValues(string connectionString, string expectedDataSource, string expectedUserId, string expectedPassword) { // Act var sparkConnectionString = new SparkConnectionStringBuilder(connectionString); // Assert Assert.Equal(expectedDataSource, sparkConnectionString.DataSource); Assert.Equal(expectedUserId, sparkConnectionString.UserId); Assert.Equal(expectedPassword, sparkConnectionString.Password); }
public void WhenSettingConnectionStringValuesShouldGetSameValues() { // Act var sparkConnectionString = new SparkConnectionStringBuilder(); sparkConnectionString.DataSource = "https://adb-0000000000000000.00.azuredatabricks.net/sql/protocolv1/o/0000000000000000/0000-000000-xxxxx000"; sparkConnectionString.UserId = "token"; sparkConnectionString.Password = "******"; // Assert Assert.Equal("https://adb-0000000000000000.00.azuredatabricks.net/sql/protocolv1/o/0000000000000000/0000-000000-xxxxx000", sparkConnectionString.DataSource); Assert.Equal("token", sparkConnectionString.UserId); Assert.Equal("dapi00000000", sparkConnectionString.Password); }