Skip to content

Commit dfbb63c

Browse files
authored
[Core] Removes TA dependency and adds fake client (Azure#22519)
1 parent 0ff2950 commit dfbb63c

File tree

7 files changed

+125
-78
lines changed

7 files changed

+125
-78
lines changed

sdk/core/Azure.Core/Azure.Core.sln

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Core.Perf", "perf\Azu
2929
EndProject
3030
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Test.Perf", "..\..\..\common\Perf\Azure.Test.Perf\Azure.Test.Perf.csproj", "{33A10110-D88A-459B-82C1-FECEF86A822A}"
3131
EndProject
32-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.AI.TextAnalytics", "..\..\textanalytics\Azure.AI.TextAnalytics\src\Azure.AI.TextAnalytics.csproj", "{1862E359-6434-41AC-8000-9B8EA4BD0E71}"
33-
EndProject
3432
Global
3533
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3634
Debug|Any CPU = Debug|Any CPU
@@ -89,10 +87,6 @@ Global
8987
{33A10110-D88A-459B-82C1-FECEF86A822A}.Debug|Any CPU.Build.0 = Debug|Any CPU
9088
{33A10110-D88A-459B-82C1-FECEF86A822A}.Release|Any CPU.ActiveCfg = Release|Any CPU
9189
{33A10110-D88A-459B-82C1-FECEF86A822A}.Release|Any CPU.Build.0 = Release|Any CPU
92-
{1862E359-6434-41AC-8000-9B8EA4BD0E71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
93-
{1862E359-6434-41AC-8000-9B8EA4BD0E71}.Debug|Any CPU.Build.0 = Debug|Any CPU
94-
{1862E359-6434-41AC-8000-9B8EA4BD0E71}.Release|Any CPU.ActiveCfg = Release|Any CPU
95-
{1862E359-6434-41AC-8000-9B8EA4BD0E71}.Release|Any CPU.Build.0 = Release|Any CPU
9690
EndGlobalSection
9791
GlobalSection(SolutionProperties) = preSolution
9892
HideSolutionNode = FALSE

sdk/core/Azure.Core/samples/LongRunningOperations.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,18 @@ The `GetValuesAsync` method will contain the `AsyncPageable<T>` results.
5050

5151
```C# Snippet:PageableOperationGetValuesAsync
5252
// create a client
53-
var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential());
54-
var document = new List<string>() { "document with information" };
53+
var client = new MyStoreClient();
5554

5655
// Start the operation
57-
AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(document);
56+
GetProductsOperation operation = client.StartGetProducts();
5857

59-
await healthOperation.WaitForCompletionAsync();
58+
await operation.WaitForCompletionAsync();
6059

61-
await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValuesAsync())
60+
await foreach (Product product in operation.GetValuesAsync())
6261
{
63-
foreach (HealthcareEntity entity in documentsInPage[0].Entities)
64-
{
65-
Console.WriteLine($" Entity: {entity.Text}");
66-
}
62+
Console.WriteLine($"Name: {product.Name}");
63+
Console.WriteLine($"Quantity: {product.Quantity}");
64+
Console.WriteLine($"Price: {product.Price}");
6765
}
6866
```
6967

@@ -72,19 +70,17 @@ The `GetValues` method will contain the `Pageable<T>` results.
7270

7371
```C# Snippet:PageableOperationGetValues
7472
// create a client
75-
var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential());
76-
var document = new List<string>() { "document with information" };
73+
var client = new MyStoreClient();
7774

7875
// Start the operation
79-
AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(document);
76+
GetProductsOperation operation = client.StartGetProducts();
8077

81-
await healthOperation.WaitForCompletionAsync();
78+
await operation.WaitForCompletionAsync();
8279

83-
foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValues())
80+
foreach (Product product in operation.GetValues())
8481
{
85-
foreach (HealthcareEntity entity in documentsInPage[0].Entities)
86-
{
87-
Console.WriteLine($" Entity: {entity.Text}");
88-
}
82+
Console.WriteLine($"Name: {product.Name}");
83+
Console.WriteLine($"Quantity: {product.Quantity}");
84+
Console.WriteLine($"Price: {product.Price}");
8985
}
9086
```

sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
<ProjectReference Include="..\src\Azure.Core.csproj" />
2121
<ProjectReference Include="..\..\Microsoft.Azure.Core.NewtonsoftJson\src\Microsoft.Azure.Core.NewtonsoftJson.csproj" />
2222
<PackageReference Include="Azure.Security.KeyVault.Secrets" />
23-
<ProjectReference Include="..\..\..\textanalytics\Azure.AI.TextAnalytics\src\Azure.AI.TextAnalytics.csproj" />
2423
</ItemGroup>
2524
<ItemGroup>
2625
<Compile Include="..\src\Shared\Multipart\*.cs" LinkBase="Shared\Multipart" />

sdk/core/Azure.Core/tests/samples/EventSamples.cs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,13 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Threading;
65
using System.Threading.Tasks;
7-
using Azure.Core.Pipeline;
86
using NUnit.Framework;
97

108
namespace Azure.Core.Samples
119
{
1210
public class EventSamples
1311
{
14-
public class AlarmClientOptions : ClientOptions { }
15-
16-
public class AlarmClient
17-
{
18-
private ClientDiagnostics _clientDiagnostics = new ClientDiagnostics(new AlarmClientOptions());
19-
20-
public event SyncAsyncEventHandler<SyncAsyncEventArgs> Ring;
21-
22-
public void Snooze(CancellationToken cancellationToken = default) =>
23-
SnoozeInternal(true, cancellationToken).GetAwaiter().GetResult();
24-
25-
public async Task SnoozeAsync(CancellationToken cancellationToken = default) =>
26-
await SnoozeInternal(false, cancellationToken).ConfigureAwait(false);
27-
28-
protected virtual async Task SnoozeInternal(bool isRunningSynchronously, CancellationToken cancellationToken)
29-
{
30-
// Why does snoozing an alarm always wait 9 minutes?
31-
TimeSpan delay = TimeSpan.FromMilliseconds(900);
32-
if (isRunningSynchronously)
33-
{
34-
cancellationToken.WaitHandle.WaitOne(delay);
35-
}
36-
else
37-
{
38-
await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
39-
}
40-
SyncAsyncEventArgs e = new SyncAsyncEventArgs(isRunningSynchronously, cancellationToken);
41-
await Ring.RaiseAsync(e, nameof(AlarmClient), nameof(Ring), _clientDiagnostics).ConfigureAwait(false);
42-
}
43-
}
44-
4512
[Test]
4613
public void SyncHandler()
4714
{
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
using Azure.Core.Pipeline;
8+
9+
namespace Azure.Core.Samples
10+
{
11+
public class AlarmClient
12+
{
13+
private ClientDiagnostics _clientDiagnostics = new ClientDiagnostics(new AlarmClientOptions());
14+
15+
public event SyncAsyncEventHandler<SyncAsyncEventArgs> Ring;
16+
17+
public void Snooze(CancellationToken cancellationToken = default) =>
18+
SnoozeInternal(true, cancellationToken).GetAwaiter().GetResult();
19+
20+
public async Task SnoozeAsync(CancellationToken cancellationToken = default) =>
21+
await SnoozeInternal(false, cancellationToken).ConfigureAwait(false);
22+
23+
protected virtual async Task SnoozeInternal(bool isRunningSynchronously, CancellationToken cancellationToken)
24+
{
25+
// Why does snoozing an alarm always wait 9 minutes?
26+
TimeSpan delay = TimeSpan.FromMilliseconds(900);
27+
if (isRunningSynchronously)
28+
{
29+
cancellationToken.WaitHandle.WaitOne(delay);
30+
}
31+
else
32+
{
33+
await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
34+
}
35+
SyncAsyncEventArgs e = new SyncAsyncEventArgs(isRunningSynchronously, cancellationToken);
36+
await Ring.RaiseAsync(e, nameof(AlarmClient), nameof(Ring), _clientDiagnostics).ConfigureAwait(false);
37+
}
38+
}
39+
40+
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "<Pending>")]
41+
public class AlarmClientOptions : ClientOptions { }
42+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
8+
namespace Azure.Core.Samples
9+
{
10+
public class MyStoreClient
11+
{
12+
public GetProductsOperation StartGetProducts(CancellationToken cancellationToken = default) => new();
13+
}
14+
15+
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "<Pending>")]
16+
public class GetProductsOperation : PageableOperation<Product>
17+
{
18+
private bool _completed;
19+
20+
public override bool HasValue => _completed;
21+
public override bool HasCompleted => _completed;
22+
23+
public override string Id { get; }
24+
25+
public override Response GetRawResponse() => throw new NotImplementedException();
26+
27+
internal GetProductsOperation()
28+
{
29+
Id = "MyOperationID";
30+
_completed = true;
31+
}
32+
33+
public override Pageable<Product> GetValues(CancellationToken cancellationToken = default) => throw new NotImplementedException();
34+
35+
public override AsyncPageable<Product> GetValuesAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException();
36+
37+
public override Response UpdateStatus(CancellationToken cancellationToken = default) => throw new NotImplementedException();
38+
39+
public override ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException();
40+
41+
public override ValueTask<Response<AsyncPageable<Product>>> WaitForCompletionAsync(CancellationToken cancellationToken = default) =>
42+
this.DefaultWaitForCompletionAsync(cancellationToken);
43+
44+
public override ValueTask<Response<AsyncPageable<Product>>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) =>
45+
this.DefaultWaitForCompletionAsync(pollingInterval, cancellationToken);
46+
}
47+
48+
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "<Pending>")]
49+
public class Product
50+
{
51+
public string Name { get; set; }
52+
public int Quantity { get; set; }
53+
public double Price { get; set; }
54+
}
55+
}

sdk/core/Azure.Core/tests/samples/OperationSamples.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Collections.Generic;
65
using System.Threading.Tasks;
7-
using Azure.AI.TextAnalytics;
86
using Azure.Identity;
97
using Azure.Security.KeyVault.Secrets;
108
using NUnit.Framework;
@@ -59,20 +57,18 @@ public async Task GetValuesAsyncSample()
5957
{
6058
#region Snippet:PageableOperationGetValuesAsync
6159
// create a client
62-
var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential());
63-
var document = new List<string>() { "document with information" };
60+
var client = new MyStoreClient();
6461

6562
// Start the operation
66-
AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(document);
63+
GetProductsOperation operation = client.StartGetProducts();
6764

68-
await healthOperation.WaitForCompletionAsync();
65+
await operation.WaitForCompletionAsync();
6966

70-
await foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValuesAsync())
67+
await foreach (Product product in operation.GetValuesAsync())
7168
{
72-
foreach (HealthcareEntity entity in documentsInPage[0].Entities)
73-
{
74-
Console.WriteLine($" Entity: {entity.Text}");
75-
}
69+
Console.WriteLine($"Name: {product.Name}");
70+
Console.WriteLine($"Quantity: {product.Quantity}");
71+
Console.WriteLine($"Price: {product.Price}");
7672
}
7773
#endregion
7874
}
@@ -83,20 +79,18 @@ public async Task GetValuesSample()
8379
{
8480
#region Snippet:PageableOperationGetValues
8581
// create a client
86-
var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential());
87-
var document = new List<string>() { "document with information" };
82+
var client = new MyStoreClient();
8883

8984
// Start the operation
90-
AnalyzeHealthcareEntitiesOperation healthOperation = client.StartAnalyzeHealthcareEntities(document);
85+
GetProductsOperation operation = client.StartGetProducts();
9186

92-
await healthOperation.WaitForCompletionAsync();
87+
await operation.WaitForCompletionAsync();
9388

94-
foreach (AnalyzeHealthcareEntitiesResultCollection documentsInPage in healthOperation.GetValues())
89+
foreach (Product product in operation.GetValues())
9590
{
96-
foreach (HealthcareEntity entity in documentsInPage[0].Entities)
97-
{
98-
Console.WriteLine($" Entity: {entity.Text}");
99-
}
91+
Console.WriteLine($"Name: {product.Name}");
92+
Console.WriteLine($"Quantity: {product.Quantity}");
93+
Console.WriteLine($"Price: {product.Price}");
10094
}
10195
#endregion
10296
}

0 commit comments

Comments
 (0)