Skip to content

Commit

Permalink
Linux support in ci (#16)
Browse files Browse the repository at this point in the history
* extended output on failed verapdf execution

* fixed error message creation code

* fixed linux testsetup

* nonfunctional changes

* dropped things that didnt do anything

* dropped unused variable

* Added notes about dependencies

* Moved forward to async implementation,
Fixed some compile warnings

* Updated ubuntu 20.04 cook book

* Major version increased

* Added integrative test

* Enabled dependency injection in webapp

* upgraded nuget references
  • Loading branch information
stesee authored Jul 1, 2020
1 parent ef5d1c5 commit 25eda99
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 51 deletions.
4 changes: 2 additions & 2 deletions PdfAValidator/PdfAValidator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.7.0.17535">
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.9.0.19135">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions PdfAValidatorTest/PdfAValidatorTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.7.0.17535">
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.9.0.19135">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
14 changes: 11 additions & 3 deletions PdfAValidatorWebApi/Controllers/PdfAValidatorController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http;
using Codeuctivity;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.IO;
Expand All @@ -15,6 +16,15 @@ namespace CodeuctivityWebApi.Controllers
[ApiController]
public class PdfAValidatorController : ControllerBase
{
private IPdfAValidator pdfAValidator { get; }
/// <summary>
/// Inject the validator.
/// </summary>
public PdfAValidatorController(IPdfAValidator PdfAValidator)
{
pdfAValidator = PdfAValidator;
}

/// <summary>
/// Validates the compliance of a PdfA.
/// </summary>
Expand Down Expand Up @@ -42,7 +52,6 @@ private async Task<ActionResult> 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);
Expand Down Expand Up @@ -75,7 +84,6 @@ public async Task<ActionResult> 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);
Expand Down
6 changes: 3 additions & 3 deletions PdfAValidatorWebApi/PdfAValidatorWebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.7.0.17535">
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.9.0.19135">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.4.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.1.2" />
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 4 additions & 2 deletions PdfAValidatorWebApi/Startup.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -24,13 +25,14 @@ public class Startup
/// <param name="services"></param>
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IPdfAValidator, PdfAValidator>();
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),
Expand Down
Binary file added PdfAValidatorWebApiTest/FromLibreOffice.pdf
Binary file not shown.
77 changes: 77 additions & 0 deletions PdfAValidatorWebApiTest/IntegrativeTests.cs
Original file line number Diff line number Diff line change
@@ -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<WebApplicationFactory<CodeuctivityWebApi.Startup>>
{
private readonly WebApplicationFactory<CodeuctivityWebApi.Startup> _factory;

public IntegrativeTests(WebApplicationFactory<CodeuctivityWebApi.Startup> 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);
}
}
}
11 changes: 7 additions & 4 deletions PdfAValidatorWebApiTest/PdfAValidatorWebApiTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
<PackageReference Include="AngleSharp" Version="0.14.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.4" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.7.0.17535">
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.5" />
<PackageReference Include="SonarAnalyzer.CSharp" Version="8.9.0.19135">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="1.3.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
35 changes: 0 additions & 35 deletions PdfAValidatorWebApiTest/ShouldStartSuccessfull.cs

This file was deleted.

17 changes: 17 additions & 0 deletions nugetUpgrade.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 25eda99

Please sign in to comment.