diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs index 5400628ba3..da30db6f98 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/MediaInputTest.cs @@ -2,7 +2,6 @@ using System; using System.IO; -using System.Net.Http; using System.Threading.Tasks; using Azure.AI.Projects; using Azure.Identity; @@ -21,12 +20,13 @@ public sealed class MediaInputTest(ITestOutputHelper output) : IntegrationTest(o { private const string WorkflowWithConversationFileName = "MediaInputConversation.yaml"; private const string WorkflowWithAutoSendFileName = "MediaInputAutoSend.yaml"; - private const string ImageReference = "https://sample-files.com/downloads/images/jpg/web_optimized_1200x800_97kb.jpg"; - private const string PdfReference = "https://sample-files.com/downloads/documents/pdf/basic-text.pdf"; + private const string ImageReferenceUrl = "https://sample-files.com/downloads/images/jpg/web_optimized_1200x800_97kb.jpg"; + private const string PdfLocalFile = "TestFiles/basic-text.pdf"; + private const string ImageLocalFile = "TestFiles/test-image.jpg"; [Theory] - [InlineData(ImageReference, "image/jpeg", true)] - [InlineData(ImageReference, "image/jpeg", false)] + [InlineData(ImageReferenceUrl, "image/jpeg", true)] + [InlineData(ImageReferenceUrl, "image/jpeg", false)] public async Task ValidateFileUrlAsync(string fileSource, string mediaType, bool useConversation) { // Arrange @@ -39,12 +39,12 @@ public async Task ValidateFileUrlAsync(string fileSource, string mediaType, bool // Temporarily disabled [Theory] [Trait("Category", "IntegrationDisabled")] - [InlineData(ImageReference, "image/jpeg", true)] - [InlineData(ImageReference, "image/jpeg", false)] + [InlineData(ImageLocalFile, "image/jpeg", true)] + [InlineData(ImageLocalFile, "image/jpeg", false)] public async Task ValidateImageFileDataAsync(string fileSource, string mediaType, bool useConversation) { // Arrange - byte[] fileData = await DownloadFileAsync(fileSource); + byte[] fileData = ReadLocalFile(fileSource); string encodedData = Convert.ToBase64String(fileData); string fileUrl = $"data:{mediaType};base64,{encodedData}"; this.Output.WriteLine($"Content: {fileUrl.Substring(0, Math.Min(112, fileUrl.Length))}..."); @@ -54,12 +54,12 @@ public async Task ValidateImageFileDataAsync(string fileSource, string mediaType } [Theory] - [InlineData(PdfReference, "application/pdf", true)] - [InlineData(PdfReference, "application/pdf", false)] + [InlineData(PdfLocalFile, "application/pdf", true)] + [InlineData(PdfLocalFile, "application/pdf", false)] public async Task ValidateFileDataAsync(string fileSource, string mediaType, bool useConversation) { // Arrange - byte[] fileData = await DownloadFileAsync(fileSource); + byte[] fileData = ReadLocalFile(fileSource); string encodedData = Convert.ToBase64String(fileData); string fileUrl = $"data:{mediaType};base64,{encodedData}"; this.Output.WriteLine($"Content: {fileUrl.Substring(0, Math.Min(112, fileUrl.Length))}..."); @@ -71,12 +71,12 @@ public async Task ValidateFileDataAsync(string fileSource, string mediaType, boo // Temporarily disabled [Theory] [Trait("Category", "IntegrationDisabled")] - [InlineData(PdfReference, "doc.pdf", true)] - [InlineData(PdfReference, "doc.pdf", false)] + [InlineData(PdfLocalFile, "doc.pdf", true)] + [InlineData(PdfLocalFile, "doc.pdf", false)] public async Task ValidateFileUploadAsync(string fileSource, string documentName, bool useConversation) { // Arrange - byte[] fileData = await DownloadFileAsync(fileSource); + byte[] fileData = ReadLocalFile(fileSource); AIProjectClient client = new(this.TestEndpoint, new AzureCliCredential()); using MemoryStream contentStream = new(fileData); OpenAIFileClient fileClient = client.GetProjectOpenAIClient().GetOpenAIFileClient(); @@ -94,11 +94,10 @@ public async Task ValidateFileUploadAsync(string fileSource, string documentName } } - private static async Task DownloadFileAsync(string uri) + private static byte[] ReadLocalFile(string relativePath) { - using HttpClient client = new(); - client.DefaultRequestHeaders.UserAgent.ParseAdd("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0"); - return await client.GetByteArrayAsync(new Uri(uri)); + string fullPath = Path.Combine(AppContext.BaseDirectory, relativePath); + return File.ReadAllBytes(fullPath); } private async Task ValidateFileAsync(AIContent fileContent, bool useConversation) diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj index 985086a56e..309a590b83 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj @@ -36,6 +36,9 @@ Always + + Always + diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/basic-text.pdf b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/basic-text.pdf new file mode 100644 index 0000000000..a4fb8a4509 Binary files /dev/null and b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/basic-text.pdf differ diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/test-image.jpg b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/test-image.jpg new file mode 100644 index 0000000000..8bb5fc31c4 Binary files /dev/null and b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/TestFiles/test-image.jpg differ