Skip to content

Commit 4a8875a

Browse files
author
Niall Langley
committed
Added unit tests to achive 100% test coverage on DataLakeService.CheckPathAsync
1 parent b044bce commit 4a8875a

File tree

2 files changed

+72
-6
lines changed

2 files changed

+72
-6
lines changed

DataPipelineTools.Tests/DataLake/DataLakeServiceTests.cs

Lines changed: 71 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using NUnit.Framework;
1+
using System;
2+
using NUnit.Framework;
23
using SqlCollaborative.Azure.DataPipelineTools.DataLake;
34

45
namespace DataPipelineTools.Tests.DataLake
@@ -50,9 +51,19 @@ public void CheckPathAsync_Given_ValidFilePath_Should_ReturnValidPath()
5051
}
5152

5253
[Test]
53-
public void CheckPathAsync_Given_FilePathWithIncorrectCase_Should_ReturnCorrectedFilePath()
54+
public void CheckPathAsync_Given_FilePathWithIncorrectFilenameCase_Should_ReturnCorrectedFilePath()
5455
{
55-
var testPath = "raw/DATABASE/jan/extract_1.csv";
56+
var testPath = "raw/database/jan/eXTRact_1.csv";
57+
var resultPath = Sut.CheckPathAsync(testPath, false).Result;
58+
59+
Assert.That("raw/database/jan/extract_1.csv", Is.EqualTo(resultPath));
60+
}
61+
62+
63+
[Test]
64+
public void CheckPathAsync_Given_FilePathWithIncorrectDirectoryCase_Should_ReturnCorrectedFilePath()
65+
{
66+
var testPath = "raw/database/JAN/extract_1.csv";
5667
var resultPath = Sut.CheckPathAsync(testPath, false).Result;
5768

5869
Assert.That("raw/database/jan/extract_1.csv", Is.EqualTo(resultPath));
@@ -101,15 +112,69 @@ public void CheckPathAsync_Given_DirectoryPathWithIncorrectCase_When_MatchesMult
101112

102113
Assert.CatchAsync(() => Sut.CheckPathAsync(testPath, true));
103114
}
115+
116+
[Test]
117+
public void CheckPathAsync_Given_NullPath_Should_Return_EmptyString()
118+
{
119+
string testPath = null;
120+
var resultPath = Sut.CheckPathAsync(testPath, true).Result;
121+
122+
Assert.That(string.Empty, Is.EqualTo(resultPath));
123+
}
104124

105125
[Test]
106-
public void CheckPathAsync_Given_FilePathWithIncorrectCase_When_MatchesMultiplePaths_Should_Throw()
126+
public void CheckPathAsync_Given_EmptyStringPath_Should_Return_EmptyString()
107127
{
108-
var testPath = "raw/aPi/jan/delta_extract_1.json";
128+
var testPath = string.Empty;
129+
var resultPath = Sut.CheckPathAsync(testPath, true).Result;
109130

110-
Assert.CatchAsync(() => Sut.CheckPathAsync(testPath, true));
131+
Assert.That(string.Empty, Is.EqualTo(resultPath));
132+
}
133+
134+
[Test]
135+
public void CheckPathAsync_Given_WhitespacePath_Should_Return_EmptyString()
136+
{
137+
var testPath = " \t\r\n ";
138+
var resultPath = Sut.CheckPathAsync(testPath, true).Result;
139+
140+
Assert.That(string.Empty, Is.EqualTo(resultPath));
111141
}
112142

143+
[Test]
144+
public void CheckPathAsync_Given_ForwardSlashPath_Should_Return_EmptyString()
145+
{
146+
var testPath = "/";
147+
var resultPath = Sut.CheckPathAsync(testPath, true).Result;
148+
149+
Assert.That(string.Empty, Is.EqualTo(resultPath));
150+
}
151+
152+
[Test]
153+
public void CheckPathAsync_Given_DirectoryPathWithIncorrectCase_Should_ThrowWhenMultipleDirectoriesMatch()
154+
{
155+
var testPath = "RaW/api/jan";
156+
157+
var exception = Assert.CatchAsync(() => Sut.CheckPathAsync(testPath, true));
158+
Assert.That(exception, Is.TypeOf(typeof(Exception)));
159+
}
160+
161+
[Test]
162+
public void CheckPathAsync_Given_FilePathWithIncorrectCase_Should_ThrowWhenMultipleDirectoriesMatch()
163+
{
164+
var testPath = "RaW/api/jan/delta_extract_1.json";
165+
166+
var exception = Assert.CatchAsync(() => Sut.CheckPathAsync(testPath, false));
167+
Assert.That(exception, Is.TypeOf(typeof(Exception)));
168+
}
169+
170+
[Test]
171+
public void CheckPathAsync_Given_FilePathWithIncorrectCase_Should_ThrowWhenMultipleFilesMatch()
172+
{
173+
var testPath = "raw/database/feb/Extract_2.csv";
174+
175+
var exception = Assert.CatchAsync(() => Sut.CheckPathAsync(testPath, false));
176+
Assert.That(exception, Is.TypeOf(typeof(Exception)));
177+
}
113178

114179

115180
//[Test]

DataPipelineTools.Tests/DataLake/DataLakeServiceTests_Data_PathItem.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Name,IsDirectory,ContentLength,LastModified
22
raw/database/jan/extract_1.csv,FALSE,10,02/01/2021 13:00
33
raw/database/feb/extract_2.csv,FALSE,20,03/01/2021 13:00
4+
raw/database/feb/EXTRACT_2.csv,FALSE,25,03/01/2021 13:00
45
raw/api/jan/delta_extract_1.json,FALSE,10,01/01/2021 14:00
56
raw/api/jan/delta_extract_2.json,FALSE,20,02/01/2021 14:00
67
raw/api/feb/delta_extract_3.json,FALSE,30,03/01/2021 14:00

0 commit comments

Comments
 (0)