/// <summary> /// Creates a <see cref="ShortCodesClient" /> with the azure key credential /// and instruments it to make use of the Azure Core Test Framework functionalities. /// </summary> /// <returns>The instrumented <see cref="ShortCodesClient" />.</returns> protected ShortCodesClient CreateClientWithAzureKeyCredential(bool isInstrumented = true) { var client = new ShortCodesClient( TestEnvironment.LiveTestStaticEndpoint, new AzureKeyCredential(TestEnvironment.LiveTestStaticAccessKey), CreateShortCodesClientOptionsWithCorrelationVectorLogs()); return(isInstrumented ? InstrumentClient(client) : client); }
/// <summary> /// Creates a <see cref="ShortCodesClient" /> with the token credential /// and instruments it to make use of the Azure Core Test Framework functionalities. /// </summary> /// <returns>The instrumented <see cref="ShortCodesClient" />.</returns> protected ShortCodesClient CreateClientWithTokenCredential(bool isInstrumented = true) { var client = new ShortCodesClient( TestEnvironment.LiveTestStaticEndpoint, (Mode == RecordedTestMode.Playback) ? new MockCredential() : new DefaultAzureCredential(), CreateShortCodesClientOptionsWithCorrelationVectorLogs()); return(isInstrumented ? InstrumentClient(client) : client); }
/// <summary> /// Creates a <see cref="ShortCodesClient" /> with the connectionstring via environment /// variables and instruments it to make use of the Azure Core Test Framework functionalities. /// </summary> /// <returns>The instrumented <see cref="ShortCodesClient" />.</returns> protected ShortCodesClient CreateClientWithConnectionString(bool isInstrumented = true) { var client = new ShortCodesClient( TestEnvironment.LiveTestStaticConnectionString, CreateShortCodesClientOptionsWithCorrelationVectorLogs()); // We always create the instrumented client to suppress the instrumentation check var instrumentedClient = InstrumentClient(client); return(isInstrumented ? instrumentedClient : client); }
public async Task GetShortCodes() { var connectionString = TestEnvironment.LiveTestStaticConnectionString; #region Snippet:CreateShortCodesClient // Get a connection string to our Azure Communication resource. //@@var connectionString = "<connection_string>"; var client = new ShortCodesClient(connectionString); #endregion Snippet:CreateShortCodesClient client = CreateClient(); var shortCodesPageable = client.GetShortCodesAsync(); var shortCodes = await shortCodesPageable.ToEnumerableAsync(); #region Snippet:GetShortCodes var pageable = client.GetShortCodesAsync(); await foreach (var shortCode in pageable) { Console.WriteLine($"Short Code Number: {shortCode.Number}"); } #endregion Snippet:GetShortCodes Assert.NotNull(shortCodes); }