Skip to content

Commit bc12886

Browse files
committed
improve tests
1 parent d9892e4 commit bc12886

4 files changed

Lines changed: 168 additions & 3 deletions

File tree

Tests/src/FileSystem.Adapters.AmazonS3/AmazonS3AdapterTest.cs

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace Tests.FileSystem.Adapters.AmazonS3
1717
{
18-
public class AmazonS3AdapterTest
18+
public class AmazonS3AdapterTest : IAdapterTests
1919
{
2020
private readonly AmazonS3Exception amazonS3NoSuchKeyException = new("NoSuchKey", ErrorType.Receiver, "NoSuchKey", "12345", HttpStatusCode.NotFound);
2121
private readonly AmazonS3Exception amazonS3InvalidAccessKeyIdException = new("InvalidAccessKeyId", ErrorType.Receiver, "InvalidAccessKeyId", "12345", HttpStatusCode.Unauthorized);
@@ -31,6 +31,12 @@ public void Test_Instantiation()
3131
Assert.Equal("/root-path", amazonS3Adapter.RootPath);
3232
}
3333

34+
[Fact]
35+
public async Task Test_Connect()
36+
{
37+
await Task.CompletedTask;
38+
}
39+
3440
[Fact]
3541
public async Task Test_Get_File_Async()
3642
{
@@ -294,6 +300,30 @@ public async Task Test_Create_Directory_Async()
294300
await fileSystem.CreateDirectoryAsync("prefix-1://test5");
295301
}
296302

303+
[Fact]
304+
public async Task Test_Delete_File_Async()
305+
{
306+
var amazonS3Client = Substitute.For<IAmazonS3>();
307+
var amazonS3Adapter = new AmazonS3Adapter("prefix-1", "root-path-1", amazonS3Client, "bucket-1");
308+
var fileSystem = new SharpGrip.FileSystem.FileSystem(new List<IAdapter> {amazonS3Adapter});
309+
310+
var getObjectResponse = Substitute.For<GetObjectResponse>();
311+
312+
getObjectResponse.Key = "test4.txt";
313+
getObjectResponse.ContentLength = 1;
314+
getObjectResponse.LastModified = new DateTime(1970, 1, 1);
315+
316+
amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test1.txt").ThrowsAsync(amazonS3NoSuchKeyException);
317+
amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test2.txt").ThrowsAsync(amazonS3InvalidAccessKeyIdException);
318+
amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test3.txt").ThrowsAsync(amazonS3InvalidSecurityException);
319+
amazonS3Client.GetObjectAsync("bucket-1", "root-path-1/test4.txt").Returns(getObjectResponse);
320+
321+
await Assert.ThrowsAsync<FileNotFoundException>(() => fileSystem.DeleteFileAsync("prefix-1://test1.txt"));
322+
await Assert.ThrowsAsync<ConnectionException>(() => fileSystem.DeleteFileAsync("prefix-1://test2.txt"));
323+
await Assert.ThrowsAsync<ConnectionException>(() => fileSystem.DeleteFileAsync("prefix-1://test3.txt"));
324+
await fileSystem.DeleteFileAsync("prefix-1://test4.txt");
325+
}
326+
297327
[Fact]
298328
public async Task Test_Delete_Directory_Async()
299329
{
@@ -325,5 +355,29 @@ public async Task Test_Delete_Directory_Async()
325355
await Assert.ThrowsAsync<ConnectionException>(() => fileSystem.DeleteDirectoryAsync("prefix-1://test4"));
326356
await fileSystem.DeleteDirectoryAsync("prefix-1://test5");
327357
}
358+
359+
[Fact]
360+
public async Task Test_Read_File_Async()
361+
{
362+
await Task.CompletedTask;
363+
}
364+
365+
[Fact]
366+
public async Task Test_Read_Text_File_Async()
367+
{
368+
await Task.CompletedTask;
369+
}
370+
371+
[Fact]
372+
public async Task Test_Write_File_Async()
373+
{
374+
await Task.CompletedTask;
375+
}
376+
377+
[Fact]
378+
public async Task Test_Append_File_Async()
379+
{
380+
await Task.CompletedTask;
381+
}
328382
}
329383
}
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1-
namespace Tests.FileSystem.Adapters.MicrosoftOneDrive
1+
using System.Net.Http.Headers;
2+
using System.Threading.Tasks;
3+
using Microsoft.Graph;
4+
using NSubstitute;
5+
using SharpGrip.FileSystem.Adapters.MicrosoftOneDrive;
6+
using Xunit;
7+
8+
namespace Tests.FileSystem.Adapters.MicrosoftOneDrive
29
{
310
public class MicrosoftOneDriveAdapterTest
411
{
12+
[Fact]
13+
public void Test_Instantiation()
14+
{
15+
var delegateAuthenticationProvider = new DelegateAuthenticationProvider(message => Task.FromResult(message.Headers.Authorization = new AuthenticationHeaderValue("Bearer", "12345")));
16+
var graphServiceClient = Substitute.For<GraphServiceClient>(delegateAuthenticationProvider, null);
17+
var microsoftOneDriveAdapter = new MicrosoftOneDriveAdapter("prefix", "/root-path", graphServiceClient, "driveId");
18+
19+
Assert.Equal("prefix", microsoftOneDriveAdapter.Prefix);
20+
Assert.Equal("/root-path", microsoftOneDriveAdapter.RootPath);
21+
}
522
}
623
}

Tests/src/FileSystem/LocalAdapterTest.cs

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Tests.FileSystem
77
{
8-
public class LocalAdapterTest
8+
public class LocalAdapterTest : IAdapterTests
99
{
1010
[Fact]
1111
public void Test_Instantiation()
@@ -16,6 +16,12 @@ public void Test_Instantiation()
1616
Assert.Equal("/root-path", localAdapter.RootPath);
1717
}
1818

19+
[Fact]
20+
public async Task Test_Connect()
21+
{
22+
await Task.CompletedTask;
23+
}
24+
1925
[Fact]
2026
public async Task Test_Get_File_Async()
2127
{
@@ -47,5 +53,71 @@ public async Task Test_Get_Directories_Async()
4753

4854
await Assert.ThrowsAsync<DirectoryNotFoundException>(async () => await localAdapter.GetDirectoriesAsync("prefix-1://test"));
4955
}
56+
57+
[Fact]
58+
public async Task Test_File_Exists_Async()
59+
{
60+
var localAdapter = new LocalAdapter("prefix-1", "/root-path-1");
61+
62+
Assert.False(await localAdapter.FileExistsAsync("prefix-1://test.txt"));
63+
}
64+
65+
[Fact]
66+
public async Task Test_Directory_Exists_Async()
67+
{
68+
var localAdapter = new LocalAdapter("prefix-1", "/root-path-1");
69+
70+
Assert.False(await localAdapter.DirectoryExistsAsync("prefix-1://test"));
71+
}
72+
73+
[Fact]
74+
public async Task Test_Create_Directory_Async()
75+
{
76+
await Task.CompletedTask;
77+
}
78+
79+
[Fact]
80+
public async Task Test_Delete_File_Async()
81+
{
82+
var localAdapter = new LocalAdapter("prefix-1", "/root-path-1");
83+
84+
await Assert.ThrowsAsync<FileNotFoundException>(async () => await localAdapter.DeleteFileAsync("prefix-1://test.txt"));
85+
}
86+
87+
[Fact]
88+
public async Task Test_Delete_Directory_Async()
89+
{
90+
var localAdapter = new LocalAdapter("prefix-1", "/root-path-1");
91+
92+
await Assert.ThrowsAsync<DirectoryNotFoundException>(async () => await localAdapter.DeleteDirectoryAsync("prefix-1://test"));
93+
}
94+
95+
[Fact]
96+
public async Task Test_Read_File_Async()
97+
{
98+
var localAdapter = new LocalAdapter("prefix-1", "/root-path-1");
99+
100+
await Assert.ThrowsAsync<FileNotFoundException>(async () => await localAdapter.ReadFileAsync("prefix-1://test.txt"));
101+
}
102+
103+
[Fact]
104+
public async Task Test_Read_Text_File_Async()
105+
{
106+
var localAdapter = new LocalAdapter("prefix-1", "/root-path-1");
107+
108+
await Assert.ThrowsAsync<FileNotFoundException>(async () => await localAdapter.ReadTextFileAsync("prefix-1://test.txt"));
109+
}
110+
111+
[Fact]
112+
public async Task Test_Write_File_Async()
113+
{
114+
await Task.CompletedTask;
115+
}
116+
117+
[Fact]
118+
public async Task Test_Append_File_Async()
119+
{
120+
await Task.CompletedTask;
121+
}
50122
}
51123
}

Tests/src/IAdapterTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Threading.Tasks;
2+
3+
namespace Tests;
4+
5+
public interface IAdapterTests
6+
{
7+
public void Test_Instantiation();
8+
public Task Test_Connect();
9+
public Task Test_Get_File_Async();
10+
public Task Test_Get_Directory_Async();
11+
public Task Test_Get_Files_Async();
12+
public Task Test_Get_Directories_Async();
13+
public Task Test_File_Exists_Async();
14+
public Task Test_Directory_Exists_Async();
15+
public Task Test_Create_Directory_Async();
16+
public Task Test_Delete_File_Async();
17+
public Task Test_Delete_Directory_Async();
18+
public Task Test_Read_File_Async();
19+
public Task Test_Read_Text_File_Async();
20+
public Task Test_Write_File_Async();
21+
public Task Test_Append_File_Async();
22+
}

0 commit comments

Comments
 (0)