Skip to content

Commit db33528

Browse files
samgibsonmojryankearsley-moj
authored andcommitted
Adds additional integration/unit tests (#34)
1 parent 2ea3866 commit db33528

10 files changed

+3278
-3
lines changed

tests/Api.Tests/AggregateServiceTests.cs

Lines changed: 625 additions & 0 deletions
Large diffs are not rendered by default.

tests/Api.Tests/SearchEndpointsTests.cs

Lines changed: 440 additions & 0 deletions
Large diffs are not rendered by default.

tests/Api.Tests/SentenceInformationServiceTests.cs

Lines changed: 618 additions & 0 deletions
Large diffs are not rendered by default.

tests/Api.Tests/VisualisationRepositoryTests.cs

Lines changed: 699 additions & 0 deletions
Large diffs are not rendered by default.

tests/Offloc.Parser.Tests/AddressWriterTests.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,38 @@ private string[] CreateRecordWithNoAddresses()
304304
return contents;
305305
}
306306

307+
[Fact]
308+
public async Task WriteAsync_UsesCrlfLineEndings()
309+
{
310+
// Arrange
311+
var context = new AddressFieldsContext([]);
312+
var writer = new AddressWriter(_testDirectory, context);
313+
var contents = CreateFullRecordArray();
314+
315+
// Act
316+
await writer.WriteAsync("NOMS001", contents);
317+
await writer.WriteAsync("NOMS002", contents);
318+
writer.Dispose();
319+
320+
// Assert
321+
var outputFile = Path.Combine(_testDirectory, "Addresses.txt");
322+
var fileContent = await File.ReadAllTextAsync(outputFile);
323+
Assert.Contains("\r\n", fileContent);
324+
Assert.DoesNotContain("\n", fileContent.Replace("\r\n", string.Empty));
325+
}
326+
307327
public void Dispose()
308328
{
309329
if (Directory.Exists(_testDirectory))
310330
{
311-
Directory.Delete(_testDirectory, recursive: true);
331+
try
332+
{
333+
Directory.Delete(_testDirectory, recursive: true);
334+
}
335+
catch
336+
{
337+
// Ignore cleanup errors
338+
}
312339
}
313340
}
314341
}

tests/Offloc.Parser.Tests/AgenciesWriterTests.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,40 @@ public async Task WriteAsync_WithDuplicateAgencyCodes_WritesNonDuplicates()
9090
Assert.Contains(lines, l => l.Contains("AGY002"));
9191
Assert.DoesNotContain(lines, l => l.Contains("Duplicate"));
9292
}
93+
94+
[Fact]
95+
public async Task WriteAsync_UsesCrlfLineEndings()
96+
{
97+
// Arrange
98+
var writer = new AgenciesWriter(_testDirectory, []);
99+
100+
var record1 = new[]{ string.Empty, "Agency One", "AGY001" };
101+
var record2 = new[]{ string.Empty, "Agency Two", "AGY002" };
102+
103+
// Act
104+
await writer.WriteAsync("NOMS001", record1);
105+
await writer.WriteAsync("NOMS002", record2);
106+
writer.Dispose();
107+
108+
// Assert
109+
var outputFile = Path.Combine(_testDirectory, "Agencies.txt");
110+
var fileContent = await File.ReadAllTextAsync(outputFile);
111+
Assert.Contains("\r\n", fileContent);
112+
Assert.DoesNotContain("\n", fileContent.Replace("\r\n", string.Empty));
113+
}
93114

94115
public void Dispose()
95116
{
96117
if (Directory.Exists(_testDirectory))
97118
{
98-
Directory.Delete(_testDirectory, recursive: true);
119+
try
120+
{
121+
Directory.Delete(_testDirectory, recursive: true);
122+
}
123+
catch
124+
{
125+
// Ignore cleanup errors
126+
}
99127
}
100128
}
101129
}

tests/Offloc.Parser.Tests/CustomWriterTests.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ public void Dispose()
7575
{
7676
if (Directory.Exists(_testDirectory))
7777
{
78-
Directory.Delete(_testDirectory, recursive: true);
78+
try
79+
{
80+
Directory.Delete(_testDirectory, recursive: true);
81+
}
82+
catch
83+
{
84+
// Ignore cleanup errors
85+
}
7986
}
8087
}
8188
}

0 commit comments

Comments
 (0)