(true,false, TimeSpan.Zero, []));
- });
- Assert.Equal(10000, request.Timeout);
- Assert.Equal("Teste", request.Alias);
- Assert.Equal("Test ", request.Html);
- Assert.Equal("header", request.Config!.Header);
- Assert.Equal("
Footer", request.Config!.Footer);
- Assert.True(request.Config.DisplayHeaderFooter);
- Assert.False(request.Config.PrintBackground);
- Assert.Equal(1.4f, request.Config.Scale);
- Assert.Null(request.InputParam);
- Assert.Equal(PageOrientation.Landscape, request.Config.Orientation);
- Assert.Equal("1.0;2.0", request.Config.Size.ToString());
- Assert.Equal("1.0;2.0;3.0;4.0", request.Config.Margins.ToString());
- Assert.Equal([], result.OutputData!);
- }
-
- [Fact]
- public async Task Ensure_Run_Compress_Decompress_Request_with_Param()
- {
- RequestHtmlPdf request = new("x","", new(), 100, null);
- var result = await HtmlPdfClient.Create("Teste")
- .PageConfig(cfg =>
- {
- cfg.Header("header
")
- .Footer("Footer
")
- .Orientation(PageOrientation.Landscape)
- .Format(1, 2)
- .Scale(1.4f)
- .DisplayHeaderFooter(true)
- .PrintBackground(false)
- .Margins(1, 2, 3, 4);
- })
- .FromHtml("Test ")
- .Timeout(10000)
- .Run((eventdata, token) =>
- {
- request = GZipHelper.DecompressRequest(eventdata);
- return Task.FromResult(new HtmlPdfResult(true,false, TimeSpan.Zero, "output"));
- },"input");
- Assert.Equal(10000, request.Timeout);
- Assert.Equal("Teste", request.Alias);
- Assert.Equal("Test ", request.Html);
- Assert.Equal("header", request.Config!.Header);
- Assert.Equal("
Footer", request.Config!.Footer);
- Assert.True(request.Config.DisplayHeaderFooter);
- Assert.False(request.Config.PrintBackground);
- Assert.Equal(1.4f, request.Config.Scale);
- Assert.Equal("input",request.InputParam);
- Assert.Equal(PageOrientation.Landscape, request.Config.Orientation);
- Assert.Equal("1.0;2.0", request.Config.Size.ToString());
- Assert.Equal("1.0;2.0;3.0;4.0", request.Config.Margins.ToString());
- Assert.Equal("output",result.OutputData);
- }
-
[Fact]
public void Scale_ThrowsArgumentException_WhenValueIsOutOfRange()
{
diff --git a/src/TestHtmlPdfCliPlus/HtmlPdfCliPlus/HtmlPdfConfigTest.cs b/src/TestHtmlPdfCliPlus/HtmlPdfCliPlus/HtmlPdfConfigTest.cs
index f052424..a02dc07 100644
--- a/src/TestHtmlPdfCliPlus/HtmlPdfCliPlus/HtmlPdfConfigTest.cs
+++ b/src/TestHtmlPdfCliPlus/HtmlPdfCliPlus/HtmlPdfConfigTest.cs
@@ -16,7 +16,7 @@ public class HtmlPdfConfigTest
public void Ensure_Create_HtmlPdfConfig_FormatByWH()
{
var result = new HtmlPdfConfig();
- result.Format();
+ result.Format();
Assert.Equal("210.0;297.0", result.PageConfig.Size.ToString());
}
@@ -66,7 +66,7 @@ public void Ensure_Create_HtmlPdfConfig_HeaderNull()
public void Ensure_Create_HtmlPdfConfig_Margins()
{
var result = new HtmlPdfConfig();
- result.Margins(1,2,3,4);
+ result.Margins(1, 2, 3, 4);
Assert.Equal("1.0;2.0;3.0;4.0", result.PageConfig.Margins.ToString());
}
@@ -74,7 +74,7 @@ public void Ensure_Create_HtmlPdfConfig_Margins()
public void Ensure_Create_HtmlPdfConfig_MarginsClass()
{
var result = new HtmlPdfConfig();
- result.Margins(PageMargins.Create(1,2,3,4));
+ result.Margins(PageMargins.Create(1, 2, 3, 4));
Assert.Equal("1.0;2.0;3.0;4.0", result.PageConfig.Margins.ToString());
}
diff --git a/src/TestHtmlPdfCliPlus/HtmlPdfCliPlus/HtmlPdfConfigTests.cs b/src/TestHtmlPdfCliPlus/HtmlPdfCliPlus/HtmlPdfConfigTests.cs
new file mode 100644
index 0000000..8670ef9
--- /dev/null
+++ b/src/TestHtmlPdfCliPlus/HtmlPdfCliPlus/HtmlPdfConfigTests.cs
@@ -0,0 +1,164 @@
+// ***************************************************************************************
+// MIT LICENCE
+// The maintenance and evolution is maintained by the HtmlPdfPlus team
+// https://github.com/FRACerqueira/HtmlPdfPlus
+// ***************************************************************************************
+
+using HtmlPdfPlus;
+using HtmlPdfPlus.Client.Core;
+
+namespace TestHtmlPdfPlus.HtmlPdfCliPlus
+{
+ public class HtmlPdfConfigTests
+ {
+ private readonly HtmlPdfConfig _config;
+
+ public HtmlPdfConfigTests()
+ {
+ _config = new HtmlPdfConfig();
+ }
+
+ [Fact]
+ public void DisplayHeaderFooter_ShouldSetDisplayHeaderFooter()
+ {
+ _config.DisplayHeaderFooter(true);
+ Assert.True(_config.PageConfig.DisplayHeaderFooter);
+ }
+
+ [Fact]
+ public void Footer_ShouldSetFooter()
+ {
+ _config.Footer("Footer content");
+ Assert.Equal("Footer content", _config.PageConfig.Footer);
+ }
+
+ [Fact]
+ public void Footer_ShouldSetFooterToNull_WhenValueIsNullOrEmpty()
+ {
+ _config.Footer(null);
+ Assert.Null(_config.PageConfig.Footer);
+
+ _config.Footer(string.Empty);
+ Assert.Null(_config.PageConfig.Footer);
+ }
+
+ [Fact]
+ public void Format_ShouldSetPageSize()
+ {
+ var pageSize = new PageSize(210, 297);
+ _config.Format(pageSize);
+ Assert.Equal(pageSize, _config.PageConfig.Size);
+ }
+
+ [Fact]
+ public void Format_ShouldSetPageSizeWithWidthAndHeight()
+ {
+ _config.Format(210, 297);
+ Assert.Equal(210, _config.PageConfig.Size.Width);
+ Assert.Equal(297, _config.PageConfig.Size.Height);
+ }
+
+ [Fact]
+ public void Format_ShouldThrowArgumentException_WhenWidthOrHeightIsInvalid()
+ {
+ Assert.Throws(() => _config.Format(-1, 297));
+ Assert.Throws(() => _config.Format(210, -1));
+ }
+
+ [Fact]
+ public void Header_ShouldSetHeader()
+ {
+ _config.Header("Header content");
+ Assert.Equal("Header content", _config.PageConfig.Header);
+ }
+
+ [Fact]
+ public void Header_ShouldSetHeaderToNull_WhenValueIsNullOrEmpty()
+ {
+ _config.Header(null);
+ Assert.Null(_config.PageConfig.Header);
+
+ _config.Header(string.Empty);
+ Assert.Null(_config.PageConfig.Header);
+ }
+
+ [Fact]
+ public void Margins_ShouldSetMargins()
+ {
+ var margins = new PageMargins(10, 10, 10, 10);
+ _config.Margins(margins);
+ Assert.Equal(margins, _config.PageConfig.Margins);
+ }
+
+ [Fact]
+ public void Margins_ShouldSetMarginsWithTopBottomLeftRight()
+ {
+ _config.Margins(10, 20, 30, 40);
+ Assert.Equal(10, _config.PageConfig.Margins.Top);
+ Assert.Equal(20, _config.PageConfig.Margins.Bottom);
+ Assert.Equal(30, _config.PageConfig.Margins.Left);
+ Assert.Equal(40, _config.PageConfig.Margins.Right);
+ }
+
+ [Fact]
+ public void Margins_ShouldThrowArgumentException_WhenAnyMarginValueIsInvalid()
+ {
+ Assert.Throws(() => _config.Margins(-1, 20, 30, 40));
+ Assert.Throws(() => _config.Margins(10, -1, 30, 40));
+ Assert.Throws(() => _config.Margins(10, 20, -1, 40));
+ Assert.Throws(() => _config.Margins(10, 20, 30, -1));
+ }
+
+ [Fact]
+ public void Margins_ShouldSetMarginsWithSingleValue()
+ {
+ _config.Margins(10);
+ Assert.Equal(10, _config.PageConfig.Margins.Top);
+ Assert.Equal(10, _config.PageConfig.Margins.Bottom);
+ Assert.Equal(10, _config.PageConfig.Margins.Left);
+ Assert.Equal(10, _config.PageConfig.Margins.Right);
+ }
+
+ [Fact]
+ public void Margins_ShouldThrowArgumentException_WhenSingleMarginValueIsInvalid()
+ {
+ Assert.Throws(() => _config.Margins(-1));
+ }
+
+ [Fact]
+ public void Orientation_ShouldSetOrientation()
+ {
+ _config.Orientation(PageOrientation.Landscape);
+ Assert.Equal(PageOrientation.Landscape, _config.PageConfig.Orientation);
+ }
+
+ [Fact]
+ public void PreferCSSPageSize_ShouldSetPreferCSSPageSize()
+ {
+ _config.PreferCSSPageSize(true);
+ Assert.True(_config.PageConfig.PreferCSSPageSize);
+ }
+
+ [Fact]
+ public void PrintBackground_ShouldSetPrintBackground()
+ {
+ _config.PrintBackground(false);
+ Assert.False(_config.PageConfig.PrintBackground);
+ }
+
+ [Fact]
+ public void Scale_ShouldSetScale()
+ {
+ _config.Scale(1.5f);
+ Assert.Equal(1.5f, _config.PageConfig.Scale);
+ }
+
+ [Fact]
+ public void Scale_ShouldThrowArgumentException_WhenScaleValueIsOutOfRange()
+ {
+ Assert.Throws(() => _config.Scale(0.05f));
+ Assert.Throws(() => _config.Scale(2.5f));
+ }
+ }
+
+}
diff --git a/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/GZipHelperTests.cs b/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/GZipHelperTests.cs
new file mode 100644
index 0000000..ac6cb12
--- /dev/null
+++ b/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/GZipHelperTests.cs
@@ -0,0 +1,57 @@
+// ***************************************************************************************
+// MIT LICENCE
+// The maintenance and evolution is maintained by the HtmlPdfPlus team
+// https://github.com/FRACerqueira/HtmlPdfPlus
+// ***************************************************************************************
+
+using HtmlPdfPlus.Shared.Core;
+using System.Text;
+
+namespace TestHtmlPdfPlus.HtmlPdfShrPlus
+{
+ public class GZipHelperTests
+ {
+ [Fact]
+ public async Task CompressAsync_ValidInput_CompressesData()
+ {
+ // Arrange
+ var input = Encoding.UTF8.GetBytes("Hello, World!");
+ var cancellationToken = CancellationToken.None;
+
+ // Act
+ var compressedData = await GZipHelper.CompressAsync(input, cancellationToken);
+
+ // Assert
+ Assert.NotNull(compressedData);
+ Assert.NotEqual(input, compressedData);
+ }
+
+ [Fact]
+ public async Task DecompressAsync_ValidInput_DecompressesData()
+ {
+ // Arrange
+ var input = Encoding.UTF8.GetBytes("Hello, World!");
+ var cancellationToken = CancellationToken.None;
+ var compressedData = await GZipHelper.CompressAsync(input, cancellationToken);
+
+ // Act
+ var decompressedData = await GZipHelper.DecompressAsync(compressedData, cancellationToken);
+
+ // Assert
+ Assert.NotNull(decompressedData);
+ Assert.Equal(input, decompressedData);
+ }
+
+ [Fact]
+ public async Task DecompressAsync_InvalidInput_ThrowsInvalidOperationException()
+ {
+ // Arrange
+ var invalidInput = new byte[] { 0xAF, 0x8B, 0x08 }; // Invalid GZip header
+ var cancellationToken = CancellationToken.None;
+
+ // Act & Assert
+ var exception = await Assert.ThrowsAsync(() => GZipHelper.DecompressAsync(invalidInput, cancellationToken));
+ Assert.Equal("The input byte array is not a valid GZip stream.", exception.Message);
+ }
+ }
+}
diff --git a/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/HtmlPdfConfigTests.cs b/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/HtmlPdfConfigTests.cs
new file mode 100644
index 0000000..ae9bfd2
--- /dev/null
+++ b/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/HtmlPdfConfigTests.cs
@@ -0,0 +1,216 @@
+using HtmlPdfPlus;
+using HtmlPdfPlus.Client.Core;
+namespace TestHtmlPdfPlus.HtmlPdfShrPlus
+{
+ public class HtmlPdfConfigTests
+ {
+ [Fact]
+ public void DisplayHeaderFooter_SetsValue_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+
+ // Act
+ var result = config.DisplayHeaderFooter(true);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.True(config.PageConfig.DisplayHeaderFooter);
+ }
+
+ [Fact]
+ public void Footer_SetsValue_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+ var footer = "Footer content";
+
+ // Act
+ var result = config.Footer(footer);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.Equal(footer, config.PageConfig.Footer);
+ }
+
+ [Fact]
+ public void Format_SetsPageSize_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+ var pageSize = PageSize.A4;
+
+ // Act
+ var result = config.Format(pageSize);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.Equal(pageSize, config.PageConfig.Size);
+ }
+
+ [Fact]
+ public void Format_SetsWidthAndHeight_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+ decimal width = 210;
+ decimal height = 297;
+
+ // Act
+ var result = config.Format(width, height);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.Equal(width, config.PageConfig.Size.Width);
+ Assert.Equal(height, config.PageConfig.Size.Height);
+ }
+
+ [Fact]
+ public void Header_SetsValue_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+ var header = "Header content";
+
+ // Act
+ var result = config.Header(header);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.Equal(header, config.PageConfig.Header);
+ }
+
+ [Fact]
+ public void Margins_SetsPageMargins_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+ var margins = new PageMargins(10, 10, 10, 10);
+
+ // Act
+ var result = config.Margins(margins);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.Equal(margins, config.PageConfig.Margins);
+ }
+
+ [Fact]
+ public void Margins_SetsAllMargins_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+ decimal margin = 10;
+
+ // Act
+ var result = config.Margins(margin);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.Equal(margin, config.PageConfig.Margins.Top);
+ Assert.Equal(margin, config.PageConfig.Margins.Bottom);
+ Assert.Equal(margin, config.PageConfig.Margins.Left);
+ Assert.Equal(margin, config.PageConfig.Margins.Right);
+ }
+
+ [Fact]
+ public void Margins_SetsIndividualMargins_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+ decimal top = 10;
+ decimal bottom = 20;
+ decimal left = 30;
+ decimal right = 40;
+
+ // Act
+ var result = config.Margins(top, bottom, left, right);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.Equal(top, config.PageConfig.Margins.Top);
+ Assert.Equal(bottom, config.PageConfig.Margins.Bottom);
+ Assert.Equal(left, config.PageConfig.Margins.Left);
+ Assert.Equal(right, config.PageConfig.Margins.Right);
+ }
+
+ [Fact]
+ public void Orientation_SetsValue_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+ var orientation = PageOrientation.Landscape;
+
+ // Act
+ var result = config.Orientation(orientation);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.Equal(orientation, config.PageConfig.Orientation);
+ }
+
+ [Fact]
+ public void PreferCSSPageSize_SetsValue_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+
+ // Act
+ var result = config.PreferCSSPageSize(true);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.True(config.PageConfig.PreferCSSPageSize);
+ }
+
+ [Fact]
+ public void PrintBackground_SetsValue_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+
+ // Act
+ var result = config.PrintBackground(false);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.False(config.PageConfig.PrintBackground);
+ }
+
+ [Fact]
+ public void Scale_SetsValue_ReturnsInstance()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+ float scale = 1.5f;
+
+ // Act
+ var result = config.Scale(scale);
+
+ // Assert
+ Assert.Equal(config, result);
+ Assert.Equal(scale, config.PageConfig.Scale);
+ }
+
+ [Fact]
+ public void Scale_InvalidValue_ThrowsArgumentException()
+ {
+ // Arrange
+ var config = new HtmlPdfConfig();
+ float invalidScale = 2.5f;
+
+ // Act & Assert
+ var exception = Assert.Throws(() => config.Scale(invalidScale));
+ Assert.Equal("Scale amount must be between 0.1 and 2.", exception.Message);
+ }
+ }// ***************************************************************************************
+ // MIT LICENCE
+ // The maintenance and evolution is maintained by the HtmlPdfPlus team
+ // https://github.com/FRACerqueira/HtmlPdfPlus
+ // ***************************************************************************************
+
+ namespace TestHtmlPdfPlus.HtmlPdfShrPlus
+ {
+
+ }
+}
\ No newline at end of file
diff --git a/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/HtmlPdfResultTests.cs b/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/HtmlPdfResultTests.cs
new file mode 100644
index 0000000..1d67c2e
--- /dev/null
+++ b/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/HtmlPdfResultTests.cs
@@ -0,0 +1,80 @@
+// ***************************************************************************************
+// MIT LICENCE
+// The maintenance and evolution is maintained by the HtmlPdfPlus team
+// https://github.com/FRACerqueira/HtmlPdfPlus
+// ***************************************************************************************
+
+using System.IO.Compression;
+using System.Text;
+using HtmlPdfPlus;
+
+namespace TestHtmlPdfPlus.HtmlPdfShrPlus
+{
+ public class HtmlPdfResultTests
+ {
+ [Fact]
+ public void Constructor_ShouldInitializeProperties()
+ {
+ // Arrange
+ var isSuccess = true;
+ var bufferDrained = false;
+ var elapsedTime = TimeSpan.FromSeconds(1);
+ var outputData = "Test Data";
+ var error = new Exception("Test Exception");
+
+ // Act
+ var result = new HtmlPdfResult(isSuccess, bufferDrained, elapsedTime, outputData, error);
+
+ // Assert
+ Assert.Equal(isSuccess, result.IsSuccess);
+ Assert.Equal(bufferDrained, result.BufferDrained);
+ Assert.Equal(elapsedTime, result.ElapsedTime);
+ Assert.Equal(outputData, result.OutputData);
+ Assert.Equal(error, result.Error);
+ }
+
+ [Fact]
+ public void DecompressOutputData_ShouldDecompressByteArray()
+ {
+ // Arrange
+ var isSuccess = true;
+ var bufferDrained = false;
+ var elapsedTime = TimeSpan.FromSeconds(1);
+ var originalData = Encoding.UTF8.GetBytes("Test Data");
+ var compressedData = Compress(originalData);
+ var result = new HtmlPdfResult(isSuccess, bufferDrained, elapsedTime, compressedData);
+
+ // Act
+ var decompressedResult = result.DecompressOutputData();
+
+ // Assert
+ Assert.Equal(originalData, decompressedResult.OutputData);
+ }
+
+ [Fact]
+ public void DecompressOutputData_ShouldThrowInvalidOperationException_WhenOutputDataIsNotByteArray()
+ {
+ // Arrange
+ var isSuccess = true;
+ var bufferDrained = false;
+ var elapsedTime = TimeSpan.FromSeconds(1);
+ var outputData = "Test Data";
+ var result = new HtmlPdfResult(isSuccess, bufferDrained, elapsedTime, outputData);
+
+ // Act & Assert
+ Assert.Throws(() => result.DecompressOutputData());
+ }
+
+ private byte[] Compress(byte[] data)
+ {
+ using (var memoryStream = new System.IO.MemoryStream())
+ {
+ using (var gzipStream = new GZipStream(memoryStream, CompressionMode.Compress))
+ {
+ gzipStream.Write(data, 0, data.Length);
+ }
+ return memoryStream.ToArray();
+ }
+ }
+ }
+}
diff --git a/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/RequestHtmlPdfTests.cs b/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/RequestHtmlPdfTests.cs
new file mode 100644
index 0000000..da03f92
--- /dev/null
+++ b/src/TestHtmlPdfCliPlus/HtmlPdfShrPlus/RequestHtmlPdfTests.cs
@@ -0,0 +1,152 @@
+// ***************************************************************************************
+// MIT LICENCE
+// The maintenance and evolution is maintained by the HtmlPdfPlus team
+// https://github.com/FRACerqueira/HtmlPdfPlus
+// ***************************************************************************************
+
+using HtmlPdfPlus;
+using HtmlPdfPlus.Shared.Core;
+using NUglify;
+using System.Text;
+using System.Text.Json;
+
+namespace TestHtmlPdfPlus.HtmlPdfShrPlus
+{
+ public class RequestHtmlPdfTests
+ {
+ [Fact]
+ public void Constructor_ValidParameters_ShouldInitializeProperties()
+ {
+ // Arrange
+ var html = "";
+ var alias = "testAlias";
+ var config = new PdfPageConfig();
+ var timeout = 30000;
+ var inputParam = "input";
+
+ // Act
+ var request = new RequestHtmlPdf(html, alias, config, timeout, inputParam);
+
+ // Assert
+ Assert.Equal(html, request.Html);
+ Assert.Equal(alias, request.Alias);
+ Assert.Equal(config, request.Config);
+ Assert.Equal(timeout, request.Timeout);
+ Assert.Equal(inputParam, request.InputParam);
+ }
+
+ [Fact]
+ public void Constructor_NullHtml_ShouldThrowArgumentException()
+ {
+ // Arrange
+ string html = null;
+
+ // Act & Assert
+ Assert.Throws(() => new RequestHtmlPdf(html));
+ }
+
+ [Fact]
+ public void Constructor_EmptyHtml_ShouldThrowArgumentException()
+ {
+ // Arrange
+ var html = "";
+
+ // Act & Assert
+ Assert.Throws(() => new RequestHtmlPdf(html));
+ }
+
+ [Fact]
+ public void Constructor_TimeoutLessThanOrEqualToZero_ShouldThrowArgumentException()
+ {
+ // Arrange
+ var html = "";
+ var timeout = 0;
+
+ // Act & Assert
+ Assert.Throws(() => new RequestHtmlPdf(html, timeout: timeout));
+ }
+
+ [Fact]
+ public void ChangeHtml_ValidHtml_ShouldUpdateHtml()
+ {
+ // Arrange
+ var html = "";
+ var request = new RequestHtmlPdf(html);
+ var newHtml = "Updated";
+
+ // Act
+ request.ChangeHtml(newHtml, false);
+
+ // Assert
+ Assert.Equal(newHtml, request.Html);
+ }
+
+ [Fact]
+ public void ChangeHtml_NullHtml_ShouldThrowArgumentException()
+ {
+ // Arrange
+ var html = "";
+ var request = new RequestHtmlPdf(html);
+
+ // Act & Assert
+ Assert.Throws(() => request.ChangeHtml(null, false));
+ }
+
+ [Fact]
+ public void ChangeHtml_EmptyHtml_ShouldThrowArgumentException()
+ {
+ // Arrange
+ var html = "";
+ var request = new RequestHtmlPdf(html);
+
+ // Act & Assert
+ Assert.Throws(() => request.ChangeHtml("", false));
+ }
+
+ [Fact]
+ public void ChangeHtml_Minify_ShouldMinifyHtml()
+ {
+ // Arrange
+ var html = " Test ";
+ var request = new RequestHtmlPdf(html);
+ var expectedHtml = Uglify.Html(html).Code;
+
+ // Act
+ request.ChangeHtml(html, true);
+
+ // Assert
+ Assert.Equal(expectedHtml, request.Html);
+ }
+
+ [Fact]
+ public void ToBytes_ShouldReturnByteArray()
+ {
+ // Arrange
+ var html = "";
+ var request = new RequestHtmlPdf(html);
+ var expectedBytes = Encoding.UTF8.GetBytes(JsonSerializer.Serialize(request));
+
+ // Act
+ var result = request.ToBytes();
+
+ // Assert
+ Assert.Equal(expectedBytes, result);
+ }
+
+ [Fact]
+ public async Task ToBytesCompress_ShouldReturnCompressedByteArray()
+ {
+ // Arrange
+ var html = "";
+ var request = new RequestHtmlPdf(html);
+ var bytes = request.ToBytes();
+ var expectedCompressedBytes = await GZipHelper.CompressAsync(bytes);
+
+ // Act
+ var result = await request.ToBytesCompress();
+
+ // Assert
+ Assert.Equal(expectedCompressedBytes, result);
+ }
+ }
+}
diff --git a/src/TestHtmlPdfCliPlus/HtmlPdfSrvPlus/HtmlPdfServerTest.cs b/src/TestHtmlPdfCliPlus/HtmlPdfSrvPlus/HtmlPdfServerTest.cs
index 04c901e..0cd148c 100644
--- a/src/TestHtmlPdfCliPlus/HtmlPdfSrvPlus/HtmlPdfServerTest.cs
+++ b/src/TestHtmlPdfCliPlus/HtmlPdfSrvPlus/HtmlPdfServerTest.cs
@@ -17,7 +17,7 @@ public class HtmlPdfServerTests
public void BeforePDF_ThrowsArgumentNullException_WhenInputParamIsNull()
{
// Act & Assert
- Assert.Throws(() => new HtmlPdfServer(null, "teste").Source(null).BeforePDF(null));
+ Assert.Throws(() => new HtmlPdfServer(null, "teste").ScopeData(null).BeforePDF(null));
}
@@ -25,7 +25,7 @@ public void BeforePDF_ThrowsArgumentNullException_WhenInputParamIsNull()
public void AfterPDF_ThrowsArgumentNullException_WhenInputParamIsNull()
{
// Act & Assert
- Assert.Throws(() => new HtmlPdfServer(null, "teste").Source(null).AfterPDF(null));
+ Assert.Throws(() => new HtmlPdfServer(null, "teste").ScopeData(null).AfterPDF(null));
}
[Fact]
@@ -62,7 +62,7 @@ public async Task Run_ThrowsArgumentNullException_WhenRequestclientIsEmpty()
// Arrange
using var objbuilder = new HtmlPdfBuilder(null);
// Act & Assert
- await Assert.ThrowsAsync(async () => await new HtmlPdfServer(objbuilder, "Test").Run("", CancellationToken.None));
+ await Assert.ThrowsAsync(async () => await new HtmlPdfServer(objbuilder, "Test").Run([], CancellationToken.None));
}
[Fact]
@@ -72,20 +72,7 @@ public async Task Run_ThrowsArgumentNullException_WhenNotExistfterPDFAndReturnCu
using var objbuilder = new HtmlPdfBuilder(null);
// Act & Assert
await Assert.ThrowsAsync(async () => await new HtmlPdfServer(objbuilder, "Teste").Run(
- new RequestHtmlPdf("","Teste", new PdfPageConfig(), 10000).ToStringCompress(), CancellationToken.None));
- }
-
- [Fact]
- public async Task Run_Resultfalse_WhenInvalidFormatRequestclient()
- {
- // Arrange
- using var objbuilder = new HtmlPdfBuilder(null);
- // Act & Assert
- var result = await new HtmlPdfServer(objbuilder, "Teste").Run("teste", CancellationToken.None);
- Assert.IsType(result.Error);
- Assert.False(result.IsSuccess);
- Assert.True(result.ElapsedTime.TotalMilliseconds > 0);
- Assert.Null(result.OutputData);
+ await new RequestHtmlPdf("","Teste", new PdfPageConfig(), 10000).ToBytesCompress(), CancellationToken.None));
}
@@ -94,11 +81,10 @@ public async Task Run_Resultfalse_WhenErrorOnBeforePDF()
{
// Arrange
using var objbuilder = new HtmlPdfBuilder(null);
- var requestHtmlPdf = GZipHelper.CompressRequest("Client", new PdfPageConfig(), "Test ", 10000, "teste");
-
+ var requestHtmlPdf = await new RequestHtmlPdf("Test ","teste", new PdfPageConfig(),10000).ToBytesCompress();
// Act & Assert
- var result = await new HtmlPdfServer(objbuilder, "Server")
- .Request(requestHtmlPdf)
+ var result = await new HtmlPdfServer(objbuilder, "Server")
+ .ScopeRequest(requestHtmlPdf)
.BeforePDF((_, _, _) => throw new InvalidTimeZoneException("Test"))
.Run(CancellationToken.None);
Assert.IsType(result.Error);
@@ -120,7 +106,7 @@ public async Task Run_ResultTrue_BasicPDF()
Orientation = PageOrientation.Landscape,
Size = PageSize.A3
};
- var requestHtmlPdf = GZipHelper.CompressRequest("Client", config, "Test ", 5000, null);
+ var requestHtmlPdf = await new RequestHtmlPdf("Test ", "teste", new PdfPageConfig(), 5000).ToBytesCompress();
// Act & Assert
var result = await new HtmlPdfServer(objbuilder, "Server")
@@ -146,11 +132,11 @@ public async Task Run_ResultTrue_WithBeforePDF_AND_AfterPDF()
Orientation = PageOrientation.Landscape,
Size = PageSize.A3,
};
- var requestHtmlPdf = GZipHelper.CompressRequest("Client", config, "Test ", 50000, null);
+ var requestHtmlPdf = await new RequestHtmlPdf("Test ", "teste", new PdfPageConfig(), 5000).ToBytesCompress();
// Act & Assert
var result = await new HtmlPdfServer(objbuilder, "Server")
- .Request(requestHtmlPdf)
+ .ScopeRequest(requestHtmlPdf)
.BeforePDF((_,_,_) => Task.FromResult("Test "))
.AfterPDF((_,_,_) => Task.FromResult("Test"))
.Run(CancellationToken.None);
diff --git a/src/docs/assemblies/HtmlPdfPlus.Shared.md b/src/docs/assemblies/HtmlPdfPlus.Shared.md
index 4312c20..bbea437 100644
--- a/src/docs/assemblies/HtmlPdfPlus.Shared.md
+++ b/src/docs/assemblies/HtmlPdfPlus.Shared.md
@@ -14,6 +14,7 @@
| enum [PageOrientation](./HtmlPdfPlus/PageOrientation.md) | Orientation Page PDF |
| class [PageSize](./HtmlPdfPlus/PageSize.md) | Page size for PDF. |
| class [PdfPageConfig](./HtmlPdfPlus/PdfPageConfig.md) | The Config PDF page. |
+| static class [StreamExtension](./HtmlPdfPlus/StreamExtension.md) | Extend function for Stream |
### See Also
* [Main Index](../docindex.md)
diff --git a/src/docs/assemblies/HtmlPdfPlus/HtmlPdfClient.md b/src/docs/assemblies/HtmlPdfPlus/HtmlPdfClient.md
index d398b24..792c0cb 100644
--- a/src/docs/assemblies/HtmlPdfPlus/HtmlPdfClient.md
+++ b/src/docs/assemblies/HtmlPdfPlus/HtmlPdfClient.md
@@ -16,8 +16,6 @@ public static class HtmlPdfClient
| --- | --- |
| static [DisableOptions](HtmlPdfClient/DisableOptions.md) { get; set; } | Options for disabling internal features. |
| static [Create](HtmlPdfClient/Create.md)(…) | Create an instance of Html to Pdf Client |
-| static [ToHtmlPdfResult](HtmlPdfClient/ToHtmlPdfResult.md)(…) | Convert Response Data from server HtmlPdfPlus |
-| static [ToHtmlPdfResult<T>](HtmlPdfClient/ToHtmlPdfResult.md)(…) | Convert Response Data from server HtmlPdfPlus |
### See Also
diff --git a/src/docs/assemblies/HtmlPdfPlus/HtmlPdfClient/ToHtmlPdfResult.md b/src/docs/assemblies/HtmlPdfPlus/HtmlPdfClient/ToHtmlPdfResult.md
deleted file mode 100644
index 933a705..0000000
--- a/src/docs/assemblies/HtmlPdfPlus/HtmlPdfClient/ToHtmlPdfResult.md
+++ /dev/null
@@ -1,50 +0,0 @@
-
-
-### HtmlPdfClient.ToHtmlPdfResult method (1 of 2)
-
-
-
-#### Convert Response Data from server HtmlPdfPlus
-
-```csharp
-public static HtmlPdfResult ToHtmlPdfResult(this string dataresponse)
-```
-
-| parameter | description |
-| --- | --- |
-| dataresponse | Response data |
-
-### Return Value
-
-HtmlPdfResult
-
-### See Also
-
-* class [HtmlPdfClient](../HtmlPdfClient.md)
-* namespace [HtmlPdfPlus](../../HtmlPdfPlus.Client.md)
-
----
-
-### HtmlPdfClient.ToHtmlPdfResult<T> method (2 of 2)
-
-#### Convert Response Data from server HtmlPdfPlus
-
-```csharp
-public static HtmlPdfResult ToHtmlPdfResult(this string dataresponse)
-```
-
-| parameter | description |
-| --- | --- |
-| T | Type of result |
-| dataresponse | Response data |
-
-### Return Value
-
-HtmlPdfResult
-
-### See Also
-
-* class [HtmlPdfClient](../HtmlPdfClient.md)
-* namespace [HtmlPdfPlus](../../HtmlPdfPlus.Client.md)
-
-
diff --git a/src/docs/assemblies/HtmlPdfPlus/HtmlPdfResult-1.md b/src/docs/assemblies/HtmlPdfPlus/HtmlPdfResult-1.md
index 7fe1564..79e9ed4 100644
--- a/src/docs/assemblies/HtmlPdfPlus/HtmlPdfResult-1.md
+++ b/src/docs/assemblies/HtmlPdfPlus/HtmlPdfResult-1.md
@@ -24,7 +24,7 @@ public sealed class HtmlPdfResult
| [Error](HtmlPdfResult-1/Error.md) { get; } | The exception during conversion. Exception |
| [IsSuccess](HtmlPdfResult-1/IsSuccess.md) { get; } | If the conversion was successful |
| [OutputData](HtmlPdfResult-1/OutputData.md) { get; } | Output custom data or PDF in byte[] |
-| [DecompressBytes](HtmlPdfResult-1/DecompressBytes.md)() | Decompress output data if it is byte[] |
+| [DecompressOutputData](HtmlPdfResult-1/DecompressOutputData.md)() | Decompress OutputData when type is byte[] |
### See Also
diff --git a/src/docs/assemblies/HtmlPdfPlus/HtmlPdfResult-1/DecompressOutputData.md b/src/docs/assemblies/HtmlPdfPlus/HtmlPdfResult-1/DecompressOutputData.md
new file mode 100644
index 0000000..d5b57cd
--- /dev/null
+++ b/src/docs/assemblies/HtmlPdfPlus/HtmlPdfResult-1/DecompressOutputData.md
@@ -0,0 +1,28 @@
+
+
+### HtmlPdfResult<T>.DecompressOutputData method
+
+
+
+#### Decompress OutputData when type is byte[]
+
+```csharp
+public HtmlPdfResult DecompressOutputData()
+```
+
+### Return Value
+
+The [`HtmlPdfResult`](../HtmlPdfResult-1.md) with OutputData Decompressed when type is byte[]
+
+### Exceptions
+
+| exception | condition |
+| --- | --- |
+| InvalidOperationException | OutputData is not byte[] |
+
+### See Also
+
+* class [HtmlPdfResult<T>](../HtmlPdfResult-1.md)
+* namespace [HtmlPdfPlus](../../HtmlPdfPlus.Shared.md)
+
+
diff --git a/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient.md b/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient.md
index b5ff8a9..336d14d 100644
--- a/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient.md
+++ b/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient.md
@@ -16,7 +16,7 @@ public interface IHtmlPdfClient
| --- | --- |
| [FromHtml](IHtmlPdfClient/FromHtml.md)(…) | Register HTML to be executed by the server. |
| [FromRazor<T>](IHtmlPdfClient/FromRazor.md)(…) | Execute the Razor HTML template with the data and register the HTML. |
-| [FromUrl](IHtmlPdfClient/FromUrl.md)(…) | ;Register Page Url to be executed by the server. |
+| [FromUrl](IHtmlPdfClient/FromUrl.md)(…) | Register Page Url to be executed by the server. |
| [HtmlParser](IHtmlPdfClient/HtmlParser.md)(…) | Execute parse validation of the HTML before sending it to the server. |
| [Logger](IHtmlPdfClient/Logger.md)(…) | Set Logger integration. |
| [PageConfig](IHtmlPdfClient/PageConfig.md)(…) | Set PDF page configuration. |
diff --git a/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient/FromUrl.md b/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient/FromUrl.md
index 0772357..84e4330 100644
--- a/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient/FromUrl.md
+++ b/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient/FromUrl.md
@@ -4,7 +4,7 @@
-#### ;Register Page Url to be executed by the server.
+#### Register Page Url to be executed by the server.
```csharp
public IHtmlPdfClient FromUrl(Uri value)
diff --git a/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient/Run.md b/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient/Run.md
index 98aa11a..1ee1df9 100644
--- a/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient/Run.md
+++ b/src/docs/assemblies/HtmlPdfPlus/IHtmlPdfClient/Run.md
@@ -8,7 +8,7 @@
```csharp
public Task> Run(
- Func>> submitHtmlToPdf,
+ Func>> submitHtmlToPdf,
CancellationToken token = default)
```
@@ -103,7 +103,7 @@ Returns bytes[] from HtmlPdfResult representing the asynchronous operation of co
```csharp
public Task> Run(
- Func