Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Removes TA dependency and adds fake client #22519

Merged
merged 2 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions sdk/core/Azure.Core/Azure.Core.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 14 additions & 18 deletions sdk/core/Azure.Core/samples/LongRunningOperations.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,18 @@ The `GetValuesAsync` method will contain the `AsyncPageable<T>` results.

```C# Snippet:PageableOperationGetValuesAsync
// create a client
var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential());
var document = new List<string>() { "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}");
}
```

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

```C# Snippet:PageableOperationGetValues
// create a client
var client = new TextAnalyticsClient(new Uri("http://example.com"), new DefaultAzureCredential());
var document = new List<string>() { "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}");
}
```
1 change: 0 additions & 1 deletion sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<ProjectReference Include="..\src\Azure.Core.csproj" />
<ProjectReference Include="..\..\Microsoft.Azure.Core.NewtonsoftJson\src\Microsoft.Azure.Core.NewtonsoftJson.csproj" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" />
<ProjectReference Include="..\..\..\textanalytics\Azure.AI.TextAnalytics\src\Azure.AI.TextAnalytics.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\src\Shared\Multipart\*.cs" LinkBase="Shared\Multipart" />
Expand Down
33 changes: 0 additions & 33 deletions sdk/core/Azure.Core/tests/samples/EventSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SyncAsyncEventArgs> 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()
{
Expand Down
42 changes: 42 additions & 0 deletions sdk/core/Azure.Core/tests/samples/FakeClients/AlarmClient.cs
Original file line number Diff line number Diff line change
@@ -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<SyncAsyncEventArgs> 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 = "<Pending>")]
public class AlarmClientOptions : ClientOptions { }
}
55 changes: 55 additions & 0 deletions sdk/core/Azure.Core/tests/samples/FakeClients/MyStoreClient.cs
Original file line number Diff line number Diff line change
@@ -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 = "<Pending>")]
public class GetProductsOperation : PageableOperation<Product>
{
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<Product> GetValues(CancellationToken cancellationToken = default) => throw new NotImplementedException();

public override AsyncPageable<Product> GetValuesAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException();

public override Response UpdateStatus(CancellationToken cancellationToken = default) => throw new NotImplementedException();

public override ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException();

public override ValueTask<Response<AsyncPageable<Product>>> WaitForCompletionAsync(CancellationToken cancellationToken = default) =>
this.DefaultWaitForCompletionAsync(cancellationToken);

public override ValueTask<Response<AsyncPageable<Product>>> 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 = "<Pending>")]
public class Product
{
public string Name { get; set; }
public int Quantity { get; set; }
public double Price { get; set; }
}
}
34 changes: 14 additions & 20 deletions sdk/core/Azure.Core/tests/samples/OperationSamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string>() { "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
}
Expand All @@ -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<string>() { "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
}
Expand Down