diff --git a/sdk/core/Azure.Core/Azure.Core.sln b/sdk/core/Azure.Core/Azure.Core.sln index 08ab723875381..d078a4561de15 100644 --- a/sdk/core/Azure.Core/Azure.Core.sln +++ b/sdk/core/Azure.Core/Azure.Core.sln @@ -29,8 +29,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.Perf", "perf\Azu EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Test.Perf", "..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj", "{33A10110-D88A-459B-82C1-FECEF86A822A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.TextAnalytics", "..\..\textanalytics\Azure.AI.TextAnalytics\src\Azure.AI.TextAnalytics.csproj", "{1862E359-6434-41AC-8000-9B8EA4BD0E71}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -89,10 +87,6 @@ Global {33A10110-D88A-459B-82C1-FECEF86A822A}.Debug|Any CPU.Build.0 = Debug|Any CPU {33A10110-D88A-459B-82C1-FECEF86A822A}.Release|Any CPU.ActiveCfg = Release|Any CPU {33A10110-D88A-459B-82C1-FECEF86A822A}.Release|Any CPU.Build.0 = Release|Any CPU - {1862E359-6434-41AC-8000-9B8EA4BD0E71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {1862E359-6434-41AC-8000-9B8EA4BD0E71}.Debug|Any CPU.Build.0 = Debug|Any CPU - {1862E359-6434-41AC-8000-9B8EA4BD0E71}.Release|Any CPU.ActiveCfg = Release|Any CPU - {1862E359-6434-41AC-8000-9B8EA4BD0E71}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/sdk/core/Azure.Core/samples/LongRunningOperations.md b/sdk/core/Azure.Core/samples/LongRunningOperations.md index 68a7672a894b2..e305f5e8aeb3a 100644 --- a/sdk/core/Azure.Core/samples/LongRunningOperations.md +++ b/sdk/core/Azure.Core/samples/LongRunningOperations.md @@ -50,20 +50,18 @@ The `GetValuesAsync` method will contain the `AsyncPageable` results. ```C# Snippet:PageableOperationGetValuesAsync // create a client -var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential()); -var document = new List() { "document with information" }; +var client = new MyStoreClient(); // Start the operation -AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(document); +GetProductsOperation operation = client.StartGetProducts(); -await healthOperation.WaitForCompletionAsync(); +await operation.WaitForCompletionAsync(); -await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValuesAsync()) +await foreach (Product product in operation.GetValuesAsync()) { - foreach (HealthcareEntity entity in documentsInPage[0].Entities) - { - Console.WriteLine($" Entity: {entity.Text}"); - } + Console.WriteLine($"Name: {product.Name}"); + Console.WriteLine($"Quantity: {product.Quantity}"); + Console.WriteLine($"Price: {product.Price}"); } ``` @@ -72,19 +70,17 @@ The `GetValues` method will contain the `Pageable` results. ```C# Snippet:PageableOperationGetValues // create a client -var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential()); -var document = new List() { "document with information" }; +var client = new MyStoreClient(); // Start the operation -AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(document); +GetProductsOperation operation = client.StartGetProducts(); -await healthOperation.WaitForCompletionAsync(); +await operation.WaitForCompletionAsync(); -foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValues()) +foreach (Product product in operation.GetValues()) { - foreach (HealthcareEntity entity in documentsInPage[0].Entities) - { - Console.WriteLine($" Entity: {entity.Text}"); - } + Console.WriteLine($"Name: {product.Name}"); + Console.WriteLine($"Quantity: {product.Quantity}"); + Console.WriteLine($"Price: {product.Price}"); } ``` diff --git a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj index 6a48f2a132228..26914c406d8ab 100644 --- a/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj +++ b/sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj @@ -20,7 +20,6 @@ - diff --git a/sdk/core/Azure.Core/tests/samples/EventSamples.cs b/sdk/core/Azure.Core/tests/samples/EventSamples.cs index 4bed1e1802a4a..a312b049b9055 100644 --- a/sdk/core/Azure.Core/tests/samples/EventSamples.cs +++ b/sdk/core/Azure.Core/tests/samples/EventSamples.cs @@ -2,46 +2,13 @@ // Licensed under the MIT License. using System; -using System.Threading; using System.Threading.Tasks; -using Azure.Core.Pipeline; using NUnit.Framework; namespace Azure.Core.Samples { public class EventSamples { - public class AlarmClientOptions : ClientOptions { } - - public class AlarmClient - { - private ClientDiagnostics _clientDiagnostics = new ClientDiagnostics(new AlarmClientOptions()); - - public event SyncAsyncEventHandler Ring; - - public void Snooze(CancellationToken cancellationToken = default) => - SnoozeInternal(true, cancellationToken).GetAwaiter().GetResult(); - - public async Task SnoozeAsync(CancellationToken cancellationToken = default) => - await SnoozeInternal(false, cancellationToken).ConfigureAwait(false); - - protected virtual async Task SnoozeInternal(bool isRunningSynchronously, CancellationToken cancellationToken) - { - // Why does snoozing an alarm always wait 9 minutes? - TimeSpan delay = TimeSpan.FromMilliseconds(900); - if (isRunningSynchronously) - { - cancellationToken.WaitHandle.WaitOne(delay); - } - else - { - await Task.Delay(delay, cancellationToken).ConfigureAwait(false); - } - SyncAsyncEventArgs e = new SyncAsyncEventArgs(isRunningSynchronously, cancellationToken); - await Ring.RaiseAsync(e, nameof(AlarmClient), nameof(Ring), _clientDiagnostics).ConfigureAwait(false); - } - } - [Test] public void SyncHandler() { diff --git a/sdk/core/Azure.Core/tests/samples/FakeClients/AlarmClient.cs b/sdk/core/Azure.Core/tests/samples/FakeClients/AlarmClient.cs new file mode 100644 index 0000000000000..934fe48aaa9f0 --- /dev/null +++ b/sdk/core/Azure.Core/tests/samples/FakeClients/AlarmClient.cs @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core.Pipeline; + +namespace Azure.Core.Samples +{ + public class AlarmClient + { + private ClientDiagnostics _clientDiagnostics = new ClientDiagnostics(new AlarmClientOptions()); + + public event SyncAsyncEventHandler Ring; + + public void Snooze(CancellationToken cancellationToken = default) => + SnoozeInternal(true, cancellationToken).GetAwaiter().GetResult(); + + public async Task SnoozeAsync(CancellationToken cancellationToken = default) => + await SnoozeInternal(false, cancellationToken).ConfigureAwait(false); + + protected virtual async Task SnoozeInternal(bool isRunningSynchronously, CancellationToken cancellationToken) + { + // Why does snoozing an alarm always wait 9 minutes? + TimeSpan delay = TimeSpan.FromMilliseconds(900); + if (isRunningSynchronously) + { + cancellationToken.WaitHandle.WaitOne(delay); + } + else + { + await Task.Delay(delay, cancellationToken).ConfigureAwait(false); + } + SyncAsyncEventArgs e = new SyncAsyncEventArgs(isRunningSynchronously, cancellationToken); + await Ring.RaiseAsync(e, nameof(AlarmClient), nameof(Ring), _clientDiagnostics).ConfigureAwait(false); + } + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "")] + public class AlarmClientOptions : ClientOptions { } +} diff --git a/sdk/core/Azure.Core/tests/samples/FakeClients/MyStoreClient.cs b/sdk/core/Azure.Core/tests/samples/FakeClients/MyStoreClient.cs new file mode 100644 index 0000000000000..5b3940647e5e8 --- /dev/null +++ b/sdk/core/Azure.Core/tests/samples/FakeClients/MyStoreClient.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Azure.Core.Samples +{ + public class MyStoreClient + { + public GetProductsOperation StartGetProducts(CancellationToken cancellationToken = default) => new(); + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "")] + public class GetProductsOperation : PageableOperation + { + private bool _completed; + + public override bool HasValue => _completed; + public override bool HasCompleted => _completed; + + public override string Id { get; } + + public override Response GetRawResponse() => throw new NotImplementedException(); + + internal GetProductsOperation() + { + Id = "MyOperationID"; + _completed = true; + } + + public override Pageable GetValues(CancellationToken cancellationToken = default) => throw new NotImplementedException(); + + public override AsyncPageable GetValuesAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); + + public override Response UpdateStatus(CancellationToken cancellationToken = default) => throw new NotImplementedException(); + + public override ValueTask UpdateStatusAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException(); + + public override ValueTask>> WaitForCompletionAsync(CancellationToken cancellationToken = default) => + this.DefaultWaitForCompletionAsync(cancellationToken); + + public override ValueTask>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) => + this.DefaultWaitForCompletionAsync(pollingInterval, cancellationToken); + } + + [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "")] + public class Product + { + public string Name { get; set; } + public int Quantity { get; set; } + public double Price { get; set; } + } +} diff --git a/sdk/core/Azure.Core/tests/samples/OperationSamples.cs b/sdk/core/Azure.Core/tests/samples/OperationSamples.cs index bbb8778b0dee7..b9040614eaa71 100644 --- a/sdk/core/Azure.Core/tests/samples/OperationSamples.cs +++ b/sdk/core/Azure.Core/tests/samples/OperationSamples.cs @@ -2,9 +2,7 @@ // Licensed under the MIT License. using System; -using System.Collections.Generic; using System.Threading.Tasks; -using Azure.AI.TextAnalytics; using Azure.Identity; using Azure.Security.KeyVault.Secrets; using NUnit.Framework; @@ -59,20 +57,18 @@ public async Task GetValuesAsyncSample() { #region Snippet:PageableOperationGetValuesAsync // create a client - var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential()); - var document = new List() { "document with information" }; + var client = new MyStoreClient(); // Start the operation - AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(document); + GetProductsOperation operation = client.StartGetProducts(); - await healthOperation.WaitForCompletionAsync(); + await operation.WaitForCompletionAsync(); - await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValuesAsync()) + await foreach (Product product in operation.GetValuesAsync()) { - foreach (HealthcareEntity entity in documentsInPage[0].Entities) - { - Console.WriteLine($" Entity: {entity.Text}"); - } + Console.WriteLine($"Name: {product.Name}"); + Console.WriteLine($"Quantity: {product.Quantity}"); + Console.WriteLine($"Price: {product.Price}"); } #endregion } @@ -83,20 +79,18 @@ public async Task GetValuesSample() { #region Snippet:PageableOperationGetValues // create a client - var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential()); - var document = new List() { "document with information" }; + var client = new MyStoreClient(); // Start the operation - AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(document); + GetProductsOperation operation = client.StartGetProducts(); - await healthOperation.WaitForCompletionAsync(); + await operation.WaitForCompletionAsync(); - foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValues()) + foreach (Product product in operation.GetValues()) { - foreach (HealthcareEntity entity in documentsInPage[0].Entities) - { - Console.WriteLine($" Entity: {entity.Text}"); - } + Console.WriteLine($"Name: {product.Name}"); + Console.WriteLine($"Quantity: {product.Quantity}"); + Console.WriteLine($"Price: {product.Price}"); } #endregion }