Skip to content

Conversation

@AhmedLeithy
Copy link
Member

After reviewing the KeyVault and Cognitive Search SDKs, I found that both Search and Keyvault.Admin were set up such that the samples classes inherit from their TestBases that were [RecordedTestBases].

In Search, each test was set to be either [SyncOnly] or [AsyncOnly]. See here

As such this is the approach I used here.

@AhmedLeithy AhmedLeithy requested a review from maririos as a code owner August 3, 2021 15:30
Copy link
Member

@maririos maririos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach so much better. Thank you for taking the time to look at other services and adjusting.
Minor comments


public Uri CreateTargetContainer(List<TestDocument> documents = default)
{
Recording.DisableIdReuse();
Copy link
Member

@maririos maririos Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if a good way to avoid having the same logic in so many functions is to create 2 functions (one sync and one async) with logic:1. get a container name, create the container, upload the document, return the container,
and then source, target, and glossary functions can use call those functions.
What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Sounds great. Will implement this first thing tomorrow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I somehow got a notification from you asking about the permissions. That is a good point.
We can make them a parameter too

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yea, I initially had a comment about that but I replaced it thinking that I can just return the containerClient like you mentioned. Then the caller function can generate the Sas with whichever permissions it needs. Not sure which one is more elegant.

Copy link
Member

@maririos maririos Aug 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both have pros and cons. whichever should be ok

public partial class DocumentTranslationSamples : DocumentTranslationLiveTestBase
{
public DocumentTranslationSamples(bool async)
: base(async, RecordedTestMode.Live)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't need to set the RecordedTestMode.Live as the CI will set it for us.
You should be able to only do : base(async)

/// Samples that are used in the associated README.md file.
/// </summary>
public partial class SampleSnippets : SamplesBase<DocumentTranslationTestEnvironment>
public partial class SampleSnippets : DocumentTranslationLiveTestBase
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the sample code we have here, we don't actually need for this class to inherit from DocumentTranslationLiveTestBase. We can just leave it as it


[Test]
[Ignore("Samples not working yet")]
[SyncOnly]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be added. The sample is just showing inputs and there is no actual call to client.StartTranslation therefore, we don't need to actually call Uri sourceSasUri = CreateSourceContainer(oneTestDocuments);

Uri source1SasUri = new Uri("<source1 SAS URI>");
Uri source2SasUri = new Uri("<source2 SAS URI>");
#else
Uri source1SasUri = CreateSourceContainer(oneTestDocuments);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comment above about how this is not needed for this sample

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea it makes sense that we don't actually need to create containers, but it seems like there is some form of format checking that takes place. A System.UriFormatException : Invalid URI exception is thrown if the sample input is used. I thought that creating an actual container would suffice, but you're right that it is unnecessary.

I could however just use any other sample uri, like the url for the github repo for example. Or is there a standard one that I should use?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think once you remove the inheritance from DocumentTranslationLiveTestBase back to SamplesBase<DocumentTranslationTestEnvironment> you should be ok

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the format exception is still thrown. I believe it is thrown by the Uri constructor as it does its own checks on the input string format.

@AhmedLeithy
Copy link
Member Author

/azp run net - translation - tests

@azure-pipelines
Copy link

Commenter does not have sufficient privileges for PR 23072 in repo Azure/azure-sdk-for-net

@maririos
Copy link
Member

maririos commented Aug 4, 2021

/azp run net - translation - tests

@azure-pipelines
Copy link

Pull request contains merge conflicts.

…samples

Fixed minor bug that resulted from the merger.
@maririos
Copy link
Member

maririos commented Aug 4, 2021

/azp run net - translation - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@maririos
Copy link
Member

maririos commented Aug 4, 2021

/azp run net - translation - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@maririos maririos merged commit aec5c75 into Azure:main Aug 4, 2021
@maririos maririos mentioned this pull request Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants