136 instantiations of DataContent
Microsoft.Extensions.AI.Abstractions (3)
Microsoft.Extensions.AI.Abstractions.Tests (80)
ChatCompletion\ChatMessageTests.cs (4)
146new DataContent("data:text/image;base64,aGVsbG8="),
147new DataContent("data:text/plain;base64,aGVsbG8="),
259new DataContent(new Uri("data:text/plain;base64,aGVsbG8="), "mime-type/2")
263new DataContent(new BinaryData(new[] { 1, 2, 3 }, options: TestJsonSerializerContext.Default.Options), "mime-type/3")
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (8)
662updates.Add(new() { Contents = [new DataContent("data:image/png;base64,aGVsbG8=")] });
923var image1 = new DataContent((byte[])[1, 2, 3, 4], "image/png") { Name = "image1.png" };
924var image2 = new DataContent((byte[])[5, 6, 7, 8], "image/jpeg") { Name = "image2.jpg" };
925var image3 = new DataContent((byte[])[9, 10, 11, 12], "image/png") { Name = "image3.png" };
926var image4 = new DataContent((byte[])[13, 14, 15, 16], "image/gif") { Name = "image4.gif" };
981var image1 = new DataContent((byte[])[1, 2, 3, 4], "image/png") { Name = "image1.png" };
982var image2 = new DataContent((byte[])[5, 6, 7, 8], "image/jpeg") { Name = "image2.jpg" };
983var image3 = new DataContent((byte[])[9, 10, 11, 12], "image/png") { Name = "image3.png" };
Contents\DataContentTests.cs (37)
49Assert.Throws(exception, () => new DataContent(path));
61Assert.Throws<ArgumentException>("mediaType", () => new DataContent("data:image/png;base64,aGVsbG8=", type));
71var content = new DataContent("data:image/png;base64,aGVsbG8=", mediaType);
75content = new DataContent("data:,", mediaType);
79content = new DataContent("data:text/plain,", mediaType);
83content = new DataContent(new Uri("data:text/plain,"), mediaType);
87content = new DataContent(new byte[] { 0, 1, 2 }, mediaType);
91content = new DataContent(content.Uri);
101content = new DataContent("data:image/png;base64,aGVsbG8=");
106content = new DataContent(new Uri("data:image/png;base64,aGVsbG8="));
127Validate(new DataContent(uri), expectedData);
128Validate(new DataContent(new Uri(uri)), expectedData);
137var content = new DataContent(uri, mediaType);
147new DataContent(uri: "data:application/octet-stream;base64,AQIDBA=="),
153new DataContent(new ReadOnlyMemory<byte>([0x01, 0x02, 0x03, 0x04]), "application/octet-stream"),
159new DataContent(new ReadOnlyMemory<byte>([0x01, 0x02, 0x03, 0x04]), "application/octet-stream") { Name = "test.bin" },
248DataContent c = new("data:,", mediaType);
261var content = new DataContent("data:application/octet-stream;base64,AQIDBA==", mediaType);
274var content = new DataContent("data:application/octet-stream;base64,AQIDBA==", mediaType);
287var content = new DataContent(data, "application/octet-stream");
297var content = new DataContent("data:text/plain,hello world");
306DataContent content = new(new byte[] { 1, 2, 3 }, "application/octet-stream");
457DataContent content = new(testData, "application/octet-stream");
484DataContent content = new(testData, "application/json");
511DataContent content = new(testData, "application/json")
543DataContent content = new(testData, "application/json");
572DataContent content = new(testData, "application/json");
598DataContent content = new(testData, "application/json");
626DataContent content = new(testData, "image/png") { Name = "myimage.png" };
655DataContent content = new(testData, "text/plain") { Name = $"testfile_{Guid.NewGuid()}.txt" };
698DataContent content = new(new byte[] { 1 }, "application/octet-stream");
735DataContent content = new(testData, "text/css");
792DataContent content = new(new byte[] { 1, 2, 3 }, "application/octet-stream");
832DataContent content = new(testData, "application/json")
863DataContent content = new(testData, "application/json");
921DataContent content = new(testData, "application/octet-stream");
954DataContent content = new(newContent, "application/octet-stream");
Contents\ImageGenerationToolResultContentTests.cs (5)
32IList<AIContent> outputs = [new DataContent(new byte[] { 1, 2, 3 }, "image/png")];
55new DataContent(new byte[] { 1, 2, 3 }, "image/png"),
57new DataContent(new byte[] { 4, 5, 6 }, "image/gif")
76new DataContent(new byte[] { 1, 2, 3 }, "image/png"),
102new DataContent(new byte[] { 7, 8, 9 }, "image/png"),
Image\ImageGenerationResponseTests.cs (3)
74new DataContent(imageData, "image/jpeg")
100new DataContent((byte[])[1, 2, 3, 4], "image/jpeg")
138new DataContent((byte[])[255, 216, 255, 224], "image/jpeg"),
Microsoft.Extensions.AI.Evaluation.Integration.Tests (2)
Microsoft.Extensions.AI.Integration.Tests (7)
Microsoft.Extensions.AI.OpenAI (12)
Microsoft.Extensions.AI.OpenAI.Tests (10)
OpenAIResponseClientTests.cs (5)
4311new FunctionResultContent("call_789", new DataContent(imageData, "image/png"))
4547new FunctionResultContent("call_pdf", new DataContent(pdfData, "application/pdf") { Name = "report.pdf" })
4940new DataContent(imageData, "image/png"),
4941new DataContent(imageData, "image/png") { AdditionalProperties = new AdditionalPropertiesDictionary { ["detail"] = ResponseImageDetailLevel.Low }},
4942new DataContent(pdfData, "application/pdf") { Name = "doc.pdf" },
Microsoft.Extensions.AI.Tests (20)
Functions\AIFunctionFactoryTest.cs (15)
942AIFunctionFactory.Create(() => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")),
943AIFunctionFactory.Create(async () => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")),
944AIFunctionFactory.Create(async ValueTask<DataContent> () => new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")),
949AIFunctionFactory.Create(() => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
950AIFunctionFactory.Create(async () => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
951AIFunctionFactory.Create(async ValueTask<IEnumerable<AIContent>> () => (IEnumerable<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
956AIFunctionFactory.Create(() => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
957AIFunctionFactory.Create(async () => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
958AIFunctionFactory.Create(async ValueTask<AIContent[]> () => (AIContent[])[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
963AIFunctionFactory.Create(() => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
964AIFunctionFactory.Create(async () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
965AIFunctionFactory.Create(async ValueTask<List<AIContent>> () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
970AIFunctionFactory.Create(() => (IList<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
971AIFunctionFactory.Create(async () => (IList<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
972AIFunctionFactory.Create(async ValueTask<IList<AIContent>> () => (List<AIContent>)[new TextContent("text"), new DataContent(new byte[] { 1, 2, 3 }, "application/octet-stream")]),
Microsoft.Extensions.DataIngestion (1)
Microsoft.Extensions.DataIngestion.Tests (1)
213 references to DataContent
Microsoft.Extensions.AI (13)
Microsoft.Extensions.AI.Abstractions (31)
Microsoft.Extensions.AI.Abstractions.Tests (92)
ChatCompletion\ChatResponseUpdateExtensionsTests.cs (7)
923var image1 = new DataContent((byte[])[1, 2, 3, 4], "image/png") { Name = "image1.png" };
924var image2 = new DataContent((byte[])[5, 6, 7, 8], "image/jpeg") { Name = "image2.jpg" };
925var image3 = new DataContent((byte[])[9, 10, 11, 12], "image/png") { Name = "image3.png" };
926var image4 = new DataContent((byte[])[13, 14, 15, 16], "image/gif") { Name = "image4.gif" };
981var image1 = new DataContent((byte[])[1, 2, 3, 4], "image/png") { Name = "image1.png" };
982var image2 = new DataContent((byte[])[5, 6, 7, 8], "image/jpeg") { Name = "image2.jpg" };
983var image3 = new DataContent((byte[])[9, 10, 11, 12], "image/png") { Name = "image3.png" };
Contents\DataContentTests.cs (53)
71var content = new DataContent("data:image/png;base64,aGVsbG8=", mediaType);
99DataContent content;
121static void Validate(DataContent content, string expectedData)
137var content = new DataContent(uri, mediaType);
168Assert.Throws<ArgumentNullException>("uri", () => JsonSerializer.Deserialize<DataContent>(json, TestJsonSerializerContext.Default.Options)!);
175var content = JsonSerializer.Deserialize<DataContent>("""{"uri":"data:application/octet-stream;base64,AQIDBA=="}""", TestJsonSerializerContext.Default.Options)!;
183content = JsonSerializer.Deserialize<DataContent>("""{"uri":"data:application/octet-stream;base64,AQIDBA=="}""", TestJsonSerializerContext.Default.Options)!;
189content = JsonSerializer.Deserialize<DataContent>("""
216var content = JsonSerializer.Deserialize<DataContent>(serialized, TestJsonSerializerContext.Default.Options)!;
248DataContent c = new("data:,", mediaType);
261var content = new DataContent("data:application/octet-stream;base64,AQIDBA==", mediaType);
274var content = new DataContent("data:application/octet-stream;base64,AQIDBA==", mediaType);
287var content = new DataContent(data, "application/octet-stream");
297var content = new DataContent("data:text/plain,hello world");
306DataContent content = new(new byte[] { 1, 2, 3 }, "application/octet-stream");
323DataContent content = await DataContent.LoadFromAsync(tempPath);
350DataContent content = await DataContent.LoadFromAsync(tempPath, "custom/type");
377DataContent content = await DataContent.LoadFromAsync(tempPath);
404DataContent content = await DataContent.LoadFromAsync(fs);
428DataContent content = await DataContent.LoadFromAsync(ms, "video/mp4");
444DataContent content = await DataContent.LoadFromAsync(ms);
457DataContent content = new(testData, "application/octet-stream");
484DataContent content = new(testData, "application/json");
511DataContent content = new(testData, "application/json")
543DataContent content = new(testData, "application/json");
572DataContent content = new(testData, "application/json");
598DataContent content = new(testData, "application/json");
626DataContent content = new(testData, "image/png") { Name = "myimage.png" };
655DataContent content = new(testData, "text/plain") { Name = $"testfile_{Guid.NewGuid()}.txt" };
680await Assert.ThrowsAsync<ArgumentNullException>("path", async () => await DataContent.LoadFromAsync((string)null!));
686await Assert.ThrowsAsync<ArgumentException>("path", async () => await DataContent.LoadFromAsync(string.Empty));
692await Assert.ThrowsAsync<ArgumentNullException>("stream", async () => await DataContent.LoadFromAsync((Stream)null!));
698DataContent content = new(new byte[] { 1 }, "application/octet-stream");
716DataContent content = await DataContent.LoadFromAsync(filePath);
735DataContent content = new(testData, "text/css");
776await DataContent.LoadFromAsync(tempPath, cancellationToken: cts.Token));
792DataContent content = new(new byte[] { 1, 2, 3 }, "application/octet-stream");
825await DataContent.LoadFromAsync(ms, cancellationToken: cts.Token));
832DataContent content = new(testData, "application/json")
863DataContent content = new(testData, "application/json");
900DataContent content = await DataContent.LoadFromAsync(tempPath);
921DataContent content = new(testData, "application/octet-stream");
954DataContent content = new(newContent, "application/octet-stream");
Microsoft.Extensions.AI.Evaluation (1)
Microsoft.Extensions.AI.Evaluation.Safety (4)
Microsoft.Extensions.AI.Integration.Tests (29)
Microsoft.Extensions.AI.OpenAI (9)
Microsoft.Extensions.AI.OpenAI.Tests (16)
Microsoft.Extensions.AI.Tests (2)
Microsoft.Extensions.DataIngestion.MarkItDown (5)
Microsoft.Extensions.DataIngestion.Tests (11)