Skip to content

Commit

Permalink
[FormRecognizer] Removed IgnoreServiceError attributes and overrode I…
Browse files Browse the repository at this point in the history
…sEnvironmentReady method (#37858)
  • Loading branch information
kinelski authored Jul 27, 2023
1 parent 67a9768 commit f6fc3de
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests
/// These tests have a dependency on live Azure services and may incur costs for the associated
/// Azure subscription.
/// </remarks>
[IgnoreServiceError(400, "InvalidRequest", Message = "Content is not accessible: Invalid data URL", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28923")]
public class DocumentAnalysisClientLiveTests : DocumentAnalysisLiveTestBase
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests
/// These tests have a dependency on live Azure services and may incur costs for the associated
/// Azure subscription.
/// </remarks>
[IgnoreServiceError(400, "InvalidRequest", Message = "Content is not accessible: Invalid data URL", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28923")]
public class OperationsLiveTests : DocumentAnalysisLiveTestBase
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests
/// These tests have a dependency on live Azure services and may incur costs for the associated
/// Azure subscription.
/// </remarks>
[IgnoreServiceError(400, "InvalidRequest", Message = "Content is not accessible: Invalid data URL", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28923")]
public class DocumentModelAdministrationLiveTests : DocumentAnalysisLiveTestBase
{
private static readonly DocumentBuildMode[] s_buildDocumentModelTestCases = new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests
/// These tests have a dependency on live Azure services and may incur costs for the associated
/// Azure subscription.
/// </remarks>
[IgnoreServiceError(400, "InvalidRequest", Message = "Content is not accessible: Invalid data URL", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28923")]
public class MiscellaneousOperationsLiveTests : DocumentAnalysisLiveTestBase
{
private readonly IReadOnlyDictionary<string, string> _testingTags = new Dictionary<string, string>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace Azure.AI.FormRecognizer.Tests
[ClientTestFixture(
FormRecognizerClientOptions.ServiceVersion.V2_0,
FormRecognizerClientOptions.ServiceVersion.V2_1)]
[IgnoreServiceError(200, "3014", Message = "Generic error during training.", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28913")]
public class RecognizeCustomFormsLiveTests : FormRecognizerLiveTestBase
{
public RecognizeCustomFormsLiveTests(bool isAsync, FormRecognizerClientOptions.ServiceVersion serviceVersion)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ namespace Azure.AI.FormRecognizer.Tests
/// These tests have a dependency on live Azure services and may incur costs for the associated
/// Azure subscription.
/// </remarks>
[IgnoreServiceError(200, "3014", Message = "Generic error during training.", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28913")]
public class FormTrainingClientLiveTests : FormRecognizerLiveTestBase
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using Azure.Core.TestFramework;

namespace Azure.AI.FormRecognizer.DocumentAnalysis.Tests
Expand Down Expand Up @@ -73,6 +74,26 @@ public class DocumentAnalysisTestEnvironment : TestEnvironment
/// </summary>
public string ClassifierTrainingSasUrl => GetRecordedVariable("CLASSIFIER_BLOB_CONTAINER_SAS_URL", options => options.IsSecret(SanitizedSasUrl));

protected override async ValueTask<bool> IsEnvironmentReadyAsync()
{
var endpoint = new Uri(Endpoint);
var keyCredential = new AzureKeyCredential(ApiKey);
var keyCredentialClient = new DocumentModelAdministrationClient(endpoint, keyCredential);
var tokenCredentialClient = new DocumentModelAdministrationClient(endpoint, Credential);

try
{
await keyCredentialClient.GetResourceDetailsAsync();
await tokenCredentialClient.GetResourceDetailsAsync();
}
catch (RequestFailedException e) when (e.Status == 401)
{
return false;
}

return true;
}

/// <summary>
/// Creates an absolute path to a file contained in the local test assets folder.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Azure.AI.FormRecognizer.DocumentAnalysis.Samples
{
[LiveOnly]
[AsyncOnly] // Ensure that each sample will only run once.
[IgnoreServiceError(400, "InvalidRequest", Message = "Content is not accessible: Invalid data URL", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28923")]
public partial class DocumentAnalysisSamples : RecordedTestBase<DocumentAnalysisTestEnvironment>
{
public DocumentAnalysisSamples(bool isAsync) : base(isAsync, RecordedTestMode.Live)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ namespace Azure.AI.FormRecognizer.Samples
{
[LiveOnly]
[AsyncOnly] // Ensure that each sample will only run once.
[IgnoreServiceError(200, "3014", Message = "Generic error during training.", Reason = "https://github.com/Azure/azure-sdk-for-net/issues/28913")]
public partial class FormRecognizerSamples : RecordedTestBase<FormRecognizerTestEnvironment>
{
public FormRecognizerSamples(bool isAsync) : base(isAsync, RecordedTestMode.Live)
Expand Down

0 comments on commit f6fc3de

Please sign in to comment.