Skip to content

Commit 1f86e74

Browse files
Add e2e test project
1 parent d2705cd commit 1f86e74

14 files changed

Lines changed: 127 additions & 5 deletions

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.pdf filter=lfs diff=lfs merge=lfs -text
2+
*.html filter=lfs diff=lfs merge=lfs -text

pdf2html.sln

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{ABE1E425-AA84-46A5-98EA-9B6D622EF8A5}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pdf2Html", "src\Pdf2Html\Pdf2Html.csproj", "{D3B9B4F8-F097-4F12-AB86-72CAE0B4577C}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{C361585C-8D3B-4CA0-A0BF-DB74DDB00EBE}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "E2E.Tests", "tests\E2E.Tests\E2E.Tests.csproj", "{9CAB9112-6B91-4615-A34A-B3C66FD3FAE1}"
13+
EndProject
14+
Global
15+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
16+
Debug|Any CPU = Debug|Any CPU
17+
Release|Any CPU = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
23+
{D3B9B4F8-F097-4F12-AB86-72CAE0B4577C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{D3B9B4F8-F097-4F12-AB86-72CAE0B4577C}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{D3B9B4F8-F097-4F12-AB86-72CAE0B4577C}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{D3B9B4F8-F097-4F12-AB86-72CAE0B4577C}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{9CAB9112-6B91-4615-A34A-B3C66FD3FAE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{9CAB9112-6B91-4615-A34A-B3C66FD3FAE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{9CAB9112-6B91-4615-A34A-B3C66FD3FAE1}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{9CAB9112-6B91-4615-A34A-B3C66FD3FAE1}.Release|Any CPU.Build.0 = Release|Any CPU
31+
EndGlobalSection
32+
GlobalSection(NestedProjects) = preSolution
33+
{D3B9B4F8-F097-4F12-AB86-72CAE0B4577C} = {ABE1E425-AA84-46A5-98EA-9B6D622EF8A5}
34+
{9CAB9112-6B91-4615-A34A-B3C66FD3FAE1} = {C361585C-8D3B-4CA0-A0BF-DB74DDB00EBE}
35+
EndGlobalSection
36+
EndGlobal

pdf2html.sln.DotSettings.user

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=604dc4c7_002D2a73_002D4e8b_002Daa5f_002D1f59b8b03adf/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="Test1" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
3+
&lt;TestAncestor&gt;&#xD;
4+
&lt;TestId&gt;NUnit3x::9CAB9112-6B91-4615-A34A-B3C66FD3FAE1::net7.0::E2E.Tests.ConvertPdfTest&lt;/TestId&gt;&#xD;
5+
&lt;/TestAncestor&gt;&#xD;
6+
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>

Controllers/RootController.cs renamed to src/Pdf2Html/Controllers/RootController.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using System.Reflection;
44
using Microsoft.AspNetCore.Mvc;
55

6-
namespace pdf2html.Controllers;
6+
namespace Pdf2Html.Controllers;
77

88
[ApiController]
99
[Route("/")]
@@ -35,9 +35,11 @@ public async Task<ActionResult> Post()
3535
var outputFile = $"{inputFile}.html";
3636
try
3737
{
38-
await using var tempFileStream = System.IO.File.Open(inputFile, FileMode.Truncate);
39-
await Request.Body.CopyToAsync(tempFileStream);
40-
_logger.LogInformation($"Copied {FormatToMb(new FileInfo(inputFile).Length)} to {inputFile}");
38+
await using (var tempFileStream = System.IO.File.Open(inputFile, FileMode.Truncate))
39+
{
40+
await Request.Body.CopyToAsync(tempFileStream);
41+
_logger.LogInformation($"Copied {FormatToMb(new FileInfo(inputFile).Length)} to {inputFile}");
42+
}
4143

4244
_logger.LogInformation("Starting conversion...");
4345
var (success, logs) = await ConvertAsync(inputFile, outputFile);
@@ -56,7 +58,6 @@ public async Task<ActionResult> Post()
5658
System.IO.File.Delete(inputFile);
5759
System.IO.File.Delete(outputFile);
5860
}
59-
6061
}
6162

6263
private async Task<(bool Success, ICollection<string> logs)> ConvertAsync(string inputFile, string outputFile)
File renamed without changes.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Version>1.0.0</Version>
8+
<AssemblyName>Pdf2html</AssemblyName>
9+
<RootNamespace>Pdf2html</RootNamespace>
810
</PropertyGroup>
911

1012
<ItemGroup>
File renamed without changes.

tests/E2E.Tests/ConvertPdfTest.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using System.Net;
2+
3+
namespace E2E.Tests;
4+
5+
public class ConvertPdfTest
6+
{
7+
private HttpClient _client = null!;
8+
9+
[SetUp]
10+
public void SetUp()
11+
{
12+
_client = new HttpClient
13+
{ BaseAddress = new Uri(Environment.GetEnvironmentVariable("TEST_SERVICE_URI") ?? "http://localhost:8080") };
14+
}
15+
16+
[TearDown]
17+
public void TearDown()
18+
{
19+
_client.Dispose();
20+
}
21+
22+
[Test]
23+
public async Task TestGetStatus()
24+
{
25+
var response = await _client.GetAsync("/");
26+
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
27+
}
28+
29+
[Test]
30+
public async Task TestConvertPdf()
31+
{
32+
var response = await _client.PostAsync("/", new StreamContent(GetResourceStream("CS_cheat_sheet.pdf")));
33+
Assert.Multiple(async () =>
34+
{
35+
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
36+
Assert.That(await response.Content.ReadAsStreamAsync(), Is.EqualTo(GetResourceStream("CS_cheat_sheet.html")));
37+
});
38+
}
39+
40+
private static Stream GetResourceStream(string resourceName)
41+
{
42+
return typeof(ConvertPdfTest).Assembly.GetManifestResourceStream($"E2E.Tests.Resources.{resourceName}") ??
43+
throw new InvalidOperationException($"No resource with name '{resourceName}'");
44+
}
45+
}

0 commit comments

Comments
 (0)