using Transversal.Services; using Transversal.Models; namespace phronCare.Test { [TestFixture] public class PdfGeneratorServiceTests { private PuppeteerPdfGeneratorService _pdfService; [OneTimeSetUp] public void Setup() { // Instancia real del servicio (recomendado para test manual/local) _pdfService = new PuppeteerPdfGeneratorService(); } [OneTimeTearDown] public async Task TearDown() { // Liberar Chromium al finalizar los tests if (_pdfService != null) await _pdfService.DisposeAsync(); } [Test] public async Task GeneratePdfFromHtml_ShouldCreatePdfFile() { // Arrange string html = @"

PhronCare Ortopedia

Presupuesto Médico

Cliente: Juan Pérez Presupuesto N°: 000123
Fecha: 13/05/2025 Profesional: Dr. Carlos López
Cantidad Producto Precio Unitario Subtotal
2 Rodillera ortopédica $5.000 $10.000
1 Férula de inmovilización $8.000 $8.000
Subtotal $18.000
IVA (21%) $3.780
Total $21.780
"; string outputFolder = @"C:\temp"; if (!Directory.Exists(outputFolder)) Directory.CreateDirectory(outputFolder); string outputPath = Path.Combine(outputFolder, "DemoTest_Puppeteer.pdf"); // Opcional: podés probar pasando o no opciones var options = new PdfGenerationOptions { Format = PuppeteerSharp.Media.PaperFormat.A4, Landscape = false, PrintBackground = true, Scale = 1.0m, HeaderTemplate = "
Presupuesto
", FooterTemplate = "
Página de
" }; // Act byte[] pdfBytes = await _pdfService.GeneratePdfFromHtmlAsync(html, options); await File.WriteAllBytesAsync(outputPath, pdfBytes); // Assert Assert.IsTrue(File.Exists(outputPath)); Assert.IsTrue(new FileInfo(outputPath).Length > 0); TestContext.WriteLine($"PDF generado correctamente en: {outputPath}"); } } }