From 958126d0cd0f8c4db79cf79e6169aa8c7b6c54c3 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Wed, 24 Sep 2025 14:11:50 -0400 Subject: [PATCH] Fix GenerateImagesAsync_SingleImageGeneration integration test Both DataContent and UriContent are valid in responses, and from both OpenAI and Azure OpenAI, I get back a UriContent. --- .../ImageGeneratorIntegrationTests.cs | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs index 8e3078efbb5..76b08941bc5 100644 --- a/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs +++ b/test/Libraries/Microsoft.Extensions.AI.Integration.Tests/ImageGeneratorIntegrationTests.cs @@ -43,13 +43,23 @@ public virtual async Task GenerateImagesAsync_SingleImageGeneration() Assert.NotNull(response); Assert.NotEmpty(response.Contents); - Assert.Single(response.Contents); - var content = response.Contents[0]; - Assert.IsType(content); - var dataContent = (DataContent)content; - Assert.False(dataContent.Data.IsEmpty); - Assert.StartsWith("image/", dataContent.MediaType, StringComparison.Ordinal); + var content = Assert.Single(response.Contents); + switch (content) + { + case UriContent uc: + Assert.StartsWith("http", uc.Uri.Scheme, StringComparison.Ordinal); + break; + + case DataContent dc: + Assert.False(dc.Data.IsEmpty); + Assert.StartsWith("image/", dc.MediaType, StringComparison.Ordinal); + break; + + default: + Assert.Fail($"Unexpected content type: {content.GetType()}"); + break; + } } [ConditionalFact]