Improved reading and writing large Office files without copying them into memory (#1243)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-28 23:03:30 +01:00
1 parent 918572c158
commit dbe609a9a7
37 files changed
+1161 -471

No files matched your search

@@ -1,5 +1,8 @@
using AIStudio.Tests.Tools.OpenXml;
using AIStudio.Tools.PowerPoint;
using Microsoft.Extensions.Logging.Abstractions;
using P = DocumentFormat.OpenXml.Presentation;
namespace AIStudio.Tests.Tools.PowerPoint;
@@ -37,6 +40,40 @@ public sealed class PresentationTemplateTests
}
}
[Test]
public void ATemplateFileIsReadThroughItsSkeleton()
{
var folder = Directory.CreateDirectory(Path.Join(Path.GetTempPath(), "mindwork-ai-studio-tests", Guid.NewGuid().ToString("N"))).FullName;
try
{
var path = Path.Join(folder, "template.pptx");
using (var file = TestTemplate.Create(
new TestTemplateOptions(Slides: [new TestSlide(1, (TestPlaceholder.Title(), "News"), (TestPlaceholder.Text(1, FULL_TEXT), "A point"))]),
new TestLayout("Title", TestPlaceholder.Title(), TestPlaceholder.Subtitle(SUBTITLE)),
new TestLayout("Content", TestPlaceholder.Title(), TestPlaceholder.Text(1, FULL_TEXT))))
File.WriteAllBytes(path, file.ToArray());
TestTemplate.AddVideo(path, 1, TestTemplate.VideoOf(1024 * 1024));
var stagedBefore = StagingFolder.Files();
var fromFile = PresentationTemplate.ReadFile(path, NullLogger.Instance);
PresentationTemplate fromStream;
using (var stream = File.OpenRead(path))
fromStream = PresentationTemplate.Read(stream);
using (Assert.EnterMultipleScope())
{
Assert.That(fromFile.ToCatalogPrompt(), Is.EqualTo(fromStream.ToCatalogPrompt()), "The skeleton holds every layout.");
Assert.That(fromFile.Slides.Select(slide => slide.Title), Is.EqualTo(new[] { "News" }), "The skeleton holds every slide.");
Assert.That(StagingFolder.Files().Except(stagedBefore), Is.Empty, "The skeleton is gone once the template is read.");
}
}
finally
{
Directory.Delete(folder, true);
}
}
[Test]
public void LayoutsWhichOnlyLookAlikeAreNoVariants()
{