diff --git a/PdfAValidator/PdfAValidator.csproj b/PdfAValidator/PdfAValidator.csproj
index 913a540..3200ed5 100644
--- a/PdfAValidator/PdfAValidator.csproj
+++ b/PdfAValidator/PdfAValidator.csproj
@@ -50,7 +50,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
@@ -58,7 +58,7 @@
-
+
diff --git a/PdfAValidatorTest/PdfAValidatorTest.csproj b/PdfAValidatorTest/PdfAValidatorTest.csproj
index 4550dd1..ab0446c 100644
--- a/PdfAValidatorTest/PdfAValidatorTest.csproj
+++ b/PdfAValidatorTest/PdfAValidatorTest.csproj
@@ -48,12 +48,12 @@
all
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
diff --git a/PdfAValidatorWebApi/Controllers/PdfAValidatorController.cs b/PdfAValidatorWebApi/Controllers/PdfAValidatorController.cs
index 31abe41..f17004b 100644
--- a/PdfAValidatorWebApi/Controllers/PdfAValidatorController.cs
+++ b/PdfAValidatorWebApi/Controllers/PdfAValidatorController.cs
@@ -1,4 +1,5 @@
-using Microsoft.AspNetCore.Http;
+using Codeuctivity;
+using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.IO;
@@ -15,6 +16,15 @@ namespace CodeuctivityWebApi.Controllers
[ApiController]
public class PdfAValidatorController : ControllerBase
{
+ private IPdfAValidator pdfAValidator { get; }
+ ///
+ /// Inject the validator.
+ ///
+ public PdfAValidatorController(IPdfAValidator PdfAValidator)
+ {
+ pdfAValidator = PdfAValidator;
+ }
+
///
/// Validates the compliance of a PdfA.
///
@@ -42,7 +52,6 @@ private async Task InternalValidate()
try
{
using var fs = new FileStream(tempPdfFilePath, FileMode.CreateNew, FileAccess.Write);
- using var pdfAValidator = new Codeuctivity.PdfAValidator();
await uploadedFile.CopyToAsync(fs).ConfigureAwait(false);
var result = await pdfAValidator.ValidateAsync(tempPdfFilePath).ConfigureAwait(false);
@@ -75,7 +84,6 @@ public async Task ValidateWithDetailedReport(IFormFile pdfFile)
try
{
using var fs = new FileStream(tempPdfFilePath, FileMode.CreateNew, FileAccess.Write);
- using var pdfAValidator = new Codeuctivity.PdfAValidator();
await uploadedFile.CopyToAsync(fs).ConfigureAwait(false);
var result = pdfAValidator.ValidateWithDetailedReportAsync(tempPdfFilePath);
diff --git a/PdfAValidatorWebApi/PdfAValidatorWebApi.csproj b/PdfAValidatorWebApi/PdfAValidatorWebApi.csproj
index e6a58ba..93894ea 100644
--- a/PdfAValidatorWebApi/PdfAValidatorWebApi.csproj
+++ b/PdfAValidatorWebApi/PdfAValidatorWebApi.csproj
@@ -17,12 +17,12 @@
all
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
+
diff --git a/PdfAValidatorWebApi/Startup.cs b/PdfAValidatorWebApi/Startup.cs
index c9537bd..de11b4c 100644
--- a/PdfAValidatorWebApi/Startup.cs
+++ b/PdfAValidatorWebApi/Startup.cs
@@ -1,4 +1,5 @@
-using Microsoft.AspNetCore.Builder;
+using Codeuctivity;
+using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
@@ -24,13 +25,14 @@ public class Startup
///
public void ConfigureServices(IServiceCollection services)
{
+ services.AddSingleton();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Latest);
// Register the Swagger generator, defining 1 or more Swagger documents
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
- Version = "v1",
+ Version = "v2",
Title = "PdfAValidator",
Description = "A simple ASP.NET Core Web API wrapping access to VeraPdf",
TermsOfService = new Uri(GithubProjectAdress),
diff --git a/PdfAValidatorWebApiTest/FromLibreOffice.pdf b/PdfAValidatorWebApiTest/FromLibreOffice.pdf
new file mode 100644
index 0000000..4ad16e2
Binary files /dev/null and b/PdfAValidatorWebApiTest/FromLibreOffice.pdf differ
diff --git a/PdfAValidatorWebApiTest/IntegrativeTests.cs b/PdfAValidatorWebApiTest/IntegrativeTests.cs
new file mode 100644
index 0000000..92ed2b0
--- /dev/null
+++ b/PdfAValidatorWebApiTest/IntegrativeTests.cs
@@ -0,0 +1,77 @@
+using Microsoft.AspNetCore.Mvc.Testing;
+using System;
+using System.IO;
+using System.Net.Http;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace CodeuctivityWebApiTest
+{
+ public class IntegrativeTests : IClassFixture>
+ {
+ private readonly WebApplicationFactory _factory;
+
+ public IntegrativeTests(WebApplicationFactory factory)
+ {
+ _factory = factory;
+ }
+
+ [Theory]
+ [InlineData("/", "text/html; charset=utf-8")]
+ [InlineData("/swagger/v1/swagger.json", "application/json; charset=utf-8")]
+ public async Task ShouldAccessEndpointSuccessfull(string route, string contentType)
+ {
+ // Arrange
+ var client = _factory.CreateClient();
+ var expectedUrl = new Uri($"https://localhost{route}");
+
+ // Act
+ var response = await client.GetAsync(expectedUrl).ConfigureAwait(false);
+
+ // Assert
+ response.EnsureSuccessStatusCode();
+ Assert.Equal(contentType, response.Content.Headers.ContentType.ToString());
+ }
+
+ [Fact]
+ public async Task ShouldValidatePdf()
+ {
+ // Arrange
+ var client = _factory.CreateClient();
+ using var request = new HttpRequestMessage(new HttpMethod("POST"), "http://localhost/api/PdfAValidator");
+ using var file = new ByteArrayContent(File.ReadAllBytes("../../../FromLibreOffice.pdf"));
+ file.Headers.Add("Content-Type", "application/pdf");
+ var multipartContent = new MultipartFormDataContent();
+ multipartContent.Add(file, "pdfFile", Path.GetFileName("FromLibreOffice.pdf"));
+ request.Content = multipartContent;
+
+ // Act
+ var response = await client.SendAsync(request).ConfigureAwait(false);
+
+ // Assert
+ response.EnsureSuccessStatusCode();
+ Assert.Equal("true", await response.Content.ReadAsStringAsync().ConfigureAwait(false));
+ }
+
+ [Fact]
+ public async Task ShouldValidatePdfDetailedReport()
+ {
+ // Arrange
+ var client = _factory.CreateClient();
+ using var request = new HttpRequestMessage(new HttpMethod("POST"), "http://localhost/api/PdfAValidator/DetailedReport");
+ using var file = new ByteArrayContent(File.ReadAllBytes("../../../FromLibreOffice.pdf"));
+ file.Headers.Add("Content-Type", "application/pdf");
+ var multipartContent = new MultipartFormDataContent();
+ multipartContent.Add(file, "pdfFile", Path.GetFileName("FromLibreOffice.pdf"));
+ request.Content = multipartContent;
+
+ // Act
+ var response = await client.SendAsync(request).ConfigureAwait(false);
+ // Assert
+ response.EnsureSuccessStatusCode();
+
+ string actual = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
+ Assert.Contains("isCompliant\":true", actual);
+ }
+ }
+}
diff --git a/PdfAValidatorWebApiTest/PdfAValidatorWebApiTest.csproj b/PdfAValidatorWebApiTest/PdfAValidatorWebApiTest.csproj
index 35f43d8..b08f32f 100644
--- a/PdfAValidatorWebApiTest/PdfAValidatorWebApiTest.csproj
+++ b/PdfAValidatorWebApiTest/PdfAValidatorWebApiTest.csproj
@@ -14,14 +14,17 @@
-
-
-
+
+
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all
diff --git a/PdfAValidatorWebApiTest/ShouldStartSuccessfull.cs b/PdfAValidatorWebApiTest/ShouldStartSuccessfull.cs
deleted file mode 100644
index b77ce53..0000000
--- a/PdfAValidatorWebApiTest/ShouldStartSuccessfull.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using Microsoft.AspNetCore.Mvc.Testing;
-using System;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace CodeuctivityWebApiTest
-{
- public class ShouldStartSuccessfull : IClassFixture>
- {
- private readonly WebApplicationFactory _factory;
-
- public ShouldStartSuccessfull(WebApplicationFactory factory)
- {
- _factory = factory;
- }
-
- [Theory]
- [InlineData("/", "text/html; charset=utf-8")]
- [InlineData("/swagger/v1/swagger.json", "application/json; charset=utf-8")]
- public async Task ShouldAccessEndpointSuccessfull(string route, string contentType)
- {
- // Arrange
- var client = _factory.CreateClient();
- var expectedUrl = new Uri($"https://localhost{route}");
-
- // Act
- var response = await client.GetAsync(expectedUrl).ConfigureAwait(false);
-
- // Assert
- response.EnsureSuccessStatusCode();
- Assert.Equal(contentType,
- response.Content.Headers.ContentType.ToString());
- }
- }
-}
\ No newline at end of file
diff --git a/nugetUpgrade.sh b/nugetUpgrade.sh
new file mode 100755
index 0000000..59a9747
--- /dev/null
+++ b/nugetUpgrade.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+regex='PackageReference Include="([^"]*)" Version="([^"]*)"'
+find . -name "*.*proj" | while read proj
+do
+ while read line
+ do
+ if [[ $line =~ $regex ]]
+ then
+ name="${BASH_REMATCH[1]}"
+ version="${BASH_REMATCH[2]}"
+ if [[ $version != *-* ]]
+ then
+ dotnet add $proj package $name
+ fi
+ fi
+ done < $proj
+done
\ No newline at end of file