Skip to content

Commit 33170b0

Browse files
author
MHD\nialan
committed
Completed azure data lake service mocking and started addeding unit tests
1 parent 34c8cf8 commit 33170b0

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

DataPipelineTools.Tests/DataLake/DataLakeServiceTests.cs

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ public class DataLakeServiceTests: TestBase
2424
private const string ContainerName = "mycontainer";
2525

2626
private readonly IEnumerable<PathItem> TestData;
27-
private readonly Mock<DataLakeFileSystemClient> mockFileSystemClient;
28-
29-
//private readonly Mock<DataLakeDirectoryClient> mockDirectoryClient;
30-
//private readonly Mock<DataLakeFileClient> mockFileClient;
3127

28+
private readonly Mock<DataLakeFileSystemClient> mockFileSystemClient;
3229
private readonly Mock<ILogger<DataLakeServiceFactory>> mockLogger;
3330

3431
private readonly DataLakeService Sut;
@@ -64,14 +61,14 @@ private Mock<DataLakeFileSystemClient> BuildMockDataLakeFileSystemClient()
6461

6562
mockFileSystemClient
6663
.Setup(x => x.GetPaths(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<CancellationToken>()))
67-
.Returns((string p, bool r) =>
64+
.Returns((string path, bool recursive, bool userPrinciaplName, CancellationToken token) =>
6865
{
6966
var items = TestData
7067
// Include all files starting with the test path
71-
.Where(x => x.Name.StartsWith(p))
68+
.Where(x => x.Name.StartsWith(path ?? string.Empty) && path != null)
7269
// Still include them if the recursive flag is set, otherwise check if the relative path after the search path contains
7370
// directory separator to exclude sub dirs
74-
.Where(x => r || !x.Name.Substring(p.Length).Contains('/'))
71+
.Where(x => recursive || !x.Name.Substring(path.Length).Contains('/'))
7572
.ToList()
7673
.AsReadOnly();
7774

@@ -117,21 +114,7 @@ private IEnumerable<PathItem> GetTestData()
117114
);
118115
}).ToArray();
119116
}
120-
121-
//private IEnumerable<DataLakeItem> GetTestData()
122-
// {
123-
// return GetTestData(",", properties =>
124-
// {
125-
// return new DataLakeItem()
126-
// {
127-
// Directory = properties[nameof(DataLakeItem.Directory)],
128-
// Name = properties[nameof(DataLakeItem.Name)],
129-
// IsDirectory = Convert.ToBoolean(properties[nameof(DataLakeItem.IsDirectory)]),
130-
// ContentLength = Convert.ToInt32(properties[nameof(DataLakeItem.ContentLength)]),
131-
// LastModified = Convert.ToDateTime(properties[nameof(DataLakeItem.LastModified)])
132-
// };
133-
// }).ToArray();
134-
// }
117+
135118

136119
[SetUp]
137120
public void Setup()
@@ -140,11 +123,50 @@ public void Setup()
140123
}
141124

142125
[Test]
143-
public void CheckPathAsync_ShouldReturn_()
126+
public void CheckPathAsync_ShouldReturnThePath_WhenTheDirectoryPathExists()
144127
{
128+
var testPath = "raw/database";
129+
var correctPath = Sut.CheckPathAsync(testPath, true).Result;
145130

131+
Assert.That(testPath, Is.EqualTo(correctPath));
146132
}
147-
148133

134+
[Test]
135+
public void CheckPathAsync_ShouldReturnThePath_WhenTheFilePathExists()
136+
{
137+
var testPath = "raw/database/jan/extract_1.csv";
138+
var correctPath = Sut.CheckPathAsync(testPath, false).Result;
139+
140+
Assert.That(testPath, Is.EqualTo(correctPath));
141+
}
142+
143+
[Test]
144+
public void CheckPathAsync_ShouldReturnNull_WhenTheIsDirectoryIsIncorrectlyFalse()
145+
{
146+
var testPath = "raw/database";
147+
var correctPath = Sut.CheckPathAsync(testPath, false).Result;
148+
149+
Assert.That(testPath, Is.EqualTo(correctPath));
150+
}
151+
152+
[Test]
153+
public void CheckPathAsync_ShouldReturnNull_WhenTheIsDirectoryIsIncorrectlyTrue()
154+
{
155+
var testPath = "raw/database/jan/extract_1.csv";
156+
var correctPath = Sut.CheckPathAsync(testPath, true).Result;
157+
158+
Assert.That(testPath, Is.EqualTo(correctPath));
159+
}
160+
161+
[Test]
162+
public void CheckPathAsync_ShouldReturnNull_WhenPathDoesNotExist()
163+
{
164+
var testPath = "some/invalid/path";
165+
var correctPath = Sut.CheckPathAsync(testPath, true).Result;
166+
167+
Assert.That(null, Is.EqualTo(correctPath));
168+
}
169+
170+
149171
}
150172
}

DataPipelineTools.Tests/DataPipelineTools.Tests.csproj

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818
</ItemGroup>
1919

2020
<ItemGroup>
21-
<None Update="DataLake\DataLakeServiceTests_Data_DataLakeItem - Copy.csv">
22-
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
23-
</None>
24-
<None Update="DataLake\DataLakeServiceTests_Data_DataLakeItem.csv">
21+
<None Update="DataLake\DataLakeServiceTests_Data_PathItem.csv">
2522
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
2623
</None>
2724
</ItemGroup>

0 commit comments

Comments
 (0)