forked from Azure/azure-sdk-for-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creating SDT client with endpoint only and making source input option…
…s public (Azure#44862) * SouceInput options are made public. Tests are updated to access stoarge accounts using managed identity and no loger through SAS urls. Single document translation client can be created using endpoint alone, mainly for SDK to work against containers. * Updating commit ID of specs repo to the latest * Fixing build and analyze failures * Fixing build errors * Fixing tests failing in MacOS by updating Default credentials with Token credentials while creating BlobServiceClient * Test recordings validated and updated
- Loading branch information
1 parent
458e91d
commit 155ac61
Showing
15 changed files
with
304 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
sdk/translation/Azure.AI.Translation.Document/src/SingleDocumentTranslationClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
// <auto-generated/> | ||
|
||
#nullable disable | ||
|
||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Azure.Core; | ||
using Azure.Core.Pipeline; | ||
|
||
namespace Azure.AI.Translation.Document | ||
{ | ||
// Data plane generated client. | ||
/// <summary> The SingleDocumentTranslation service client. </summary> | ||
public partial class SingleDocumentTranslationClient | ||
{ | ||
/// <summary> Initializes a new instance of SingleDocumentTranslationClient. </summary> | ||
/// <param name="endpoint"> | ||
/// Supported document Translation endpoint, protocol and hostname, for example: | ||
/// https://{TranslatorResourceName}-doctranslation.cognitiveservices.azure.com | ||
/// </param> | ||
/// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> is null. </exception> | ||
public SingleDocumentTranslationClient(Uri endpoint) : this(endpoint, new DocumentTranslationClientOptions()) | ||
{ | ||
} | ||
|
||
/// <summary> Initializes a new instance of SingleDocumentTranslationClient. </summary> | ||
/// <param name="endpoint"> | ||
/// Supported document Translation endpoint, protocol and hostname, for example: | ||
/// https://{TranslatorResourceName}-doctranslation.cognitiveservices.azure.com | ||
/// </param> | ||
/// <param name="options"> The options for configuring the client. </param> | ||
/// <exception cref="ArgumentNullException"> <paramref name="endpoint"/> is null. </exception> | ||
public SingleDocumentTranslationClient(Uri endpoint, DocumentTranslationClientOptions options) | ||
{ | ||
Argument.AssertNotNull(endpoint, nameof(endpoint)); | ||
options ??= new DocumentTranslationClientOptions(); | ||
|
||
ClientDiagnostics = new ClientDiagnostics(options, true); | ||
_pipeline = HttpPipelineBuilder.Build(options, Array.Empty<HttpPipelinePolicy>(), Array.Empty<HttpPipelinePolicy>(), new ResponseClassifier()); | ||
_endpoint = endpoint; | ||
_apiVersion = options.Version; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ranslation/Azure.AI.Translation.Document/tests/ContainerDocumentTranslationClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Core.TestFramework; | ||
using NUnit.Framework; | ||
|
||
namespace Azure.AI.Translation.Document.Tests | ||
{ | ||
public partial class ContainerDocumentTranslationClientTests : DocumentTranslationLiveTestBase | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ContainerDocumentTranslationClientTests"/> class. | ||
/// </summary> | ||
/// <param name="isAsync">A flag used by the Azure Core Test Framework to differentiate between tests for asynchronous and synchronous methods.</param> | ||
public ContainerDocumentTranslationClientTests(bool isAsync) | ||
: base(isAsync) | ||
{ | ||
} | ||
|
||
// Before running this test make sure you have docker application running and then run the Translator container | ||
[Test] | ||
[Ignore("Container Test only")] | ||
public async Task StartSynchronousDocumentTranslation() | ||
{ | ||
//Once the container is running, note the endpoint it is listening on and update accordingly | ||
var endpoint = new Uri("http://localhost:5000"); | ||
|
||
SingleDocumentTranslationClient client = new SingleDocumentTranslationClient(endpoint); | ||
|
||
string filePath = Path.Combine("TestData", "test-input.txt"); | ||
using Stream fileStream = File.OpenRead(filePath); | ||
|
||
var sourceDocument = new MultipartFormFileData(Path.GetFileName(filePath), fileStream, "text/html"); | ||
DocumentTranslateContent content = new DocumentTranslateContent(sourceDocument); | ||
|
||
//make sure this language model "hi" is downloaded | ||
var response = await client.DocumentTranslateAsync("hi", content, "en").ConfigureAwait(false); | ||
var requestString = File.ReadAllText(filePath); | ||
var responseString = Encoding.UTF8.GetString(response.Value.ToArray()); | ||
Assert.IsNotEmpty(responseString); | ||
Assert.IsNotNull(responseString); | ||
Assert.AreNotEqual(requestString, responseString); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.