Skip to content
Closed
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -131,24 +131,25 @@ public async Task StartRecognizeContentPopulatesFormPage(bool useStream)
public async Task StartRecognizeReceiptsPopulatesExtractedReceipt(bool useStream)
{
var client = CreateInstrumentedClient();
Operation<IReadOnlyList<RecognizedReceipt>> operation;
IReadOnlyList<RecognizedReceipt> receipts;

if (useStream)
{
using var stream = new FileStream(TestEnvironment.ReceiptPath, FileMode.Open);
operation = await client.StartRecognizeReceiptsAsync(stream, ContentType.Jpeg);
var operation = await client.StartRecognizeReceiptsAsync(stream, ContentType.Jpeg);

await operation.WaitForCompletionAsync();

Assert.IsTrue(operation.HasValue);
receipts = operation.Value;
}
else
{
var uri = new Uri(TestEnvironment.ReceiptUri);
operation = await client.StartRecognizeReceiptsFromUriAsync(uri, default);
receipts = (await client.RecognizeReceiptsFromUriAsync(uri, default)).Value;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not wild about the need to put parentheses around the expression and have .Value at the end.

Is there another approach? Krzysztof was ok with this approach...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implicit conversion to interfaces isn't allowed. Since RecognizeReceiptsOperation uses interface as its value type:

RecognizeReceiptsOperation : Operation<IReadOnlyList<RecognizedReceipt>>

we have to either return IReadOnlyList<RecognizedReceipt> from extension method instead of Response<IReadOnlyList<RecognizedReceipt>> or change value type to ReadOnlyCollection or some other concrete type.

Copy link
Member

Choose a reason for hiding this comment

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

When writing TA samples, Krzysztof raised this concern too, and after looking at alternatives, we went with .Value

}

await operation.WaitForCompletionAsync();

Assert.IsTrue(operation.HasValue);

var receipt = operation.Value.Single().AsUSReceipt();
var receipt = receipts.Single().AsUSReceipt();


// The expected values are based on the values returned by the service, and not the actual
Expand Down