Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/Build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ on:
workflow_dispatch:
push:
branches:
- 'master'
- 'develop'
- '*'

jobs:
build:
Expand Down
4 changes: 2 additions & 2 deletions FileSystem.Adapters.AmazonS3/src/AmazonS3Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ namespace SharpGrip.FileSystem.Adapters.AmazonS3
{
public class AmazonS3Adapter : Adapter
{
private readonly AmazonS3Client client;
private readonly IAmazonS3 client;
private readonly string bucketName;

public AmazonS3Adapter(string prefix, string rootPath, AmazonS3Client client, string bucketName) : base(prefix, rootPath)
public AmazonS3Adapter(string prefix, string rootPath, IAmazonS3 client, string bucketName) : base(prefix, rootPath)
{
this.client = client;
this.bucketName = bucketName;
Expand Down
6 changes: 5 additions & 1 deletion Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.console" Version="2.5.0">
<PrivateAssets>all</PrivateAssets>
Expand Down
22 changes: 10 additions & 12 deletions Tests/src/FileSystem.Adapters.AmazonS3/AmazonS3AdapterTest.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
using System;
using System.Threading.Tasks;
using Amazon;
using Amazon.S3;
using Amazon.S3.Model;
using Moq;
using NSubstitute;
using SharpGrip.FileSystem.Adapters.AmazonS3;
using SharpGrip.FileSystem.Models;
using Xunit;
Expand All @@ -15,8 +14,8 @@ public class AmazonS3AdapterTest
[Fact]
public void Test_Instantiation()
{
var amazonS3Client = new Mock<AmazonS3Client>("awsAccessKeyId", "awsSecretAccessKey", RegionEndpoint.USEast2);
var amazonS3Adapter = new AmazonS3Adapter("prefix", "/root-path", amazonS3Client.Object, "bucket");
var amazonS3Client = Substitute.For<IAmazonS3>();
var amazonS3Adapter = new AmazonS3Adapter("prefix", "/root-path", amazonS3Client, "bucket");

Assert.Equal("prefix", amazonS3Adapter.Prefix);
Assert.Equal("/root-path", amazonS3Adapter.RootPath);
Expand All @@ -25,17 +24,16 @@ public void Test_Instantiation()
[Fact]
public async Task Test_Get_File_Async()
{
var amazonS3Client = new Mock<AmazonS3Client>("awsAccessKeyId", "awsSecretAccessKey", RegionEndpoint.USEast2);
var amazonS3Adapter = new AmazonS3Adapter("prefix-1", "/root-path-1", amazonS3Client.Object, "bucket-1");
var amazonS3Client = Substitute.For<IAmazonS3>();
var amazonS3Adapter = new AmazonS3Adapter("prefix-1", "/root-path-1", amazonS3Client, "bucket-1");

var getObjectResponse = new Mock<GetObjectResponse>();
var getObjectResponse = Substitute.For<GetObjectResponse>();

getObjectResponse.SetupAllProperties();
getObjectResponse.Object.Key = "test.txt";
getObjectResponse.Object.ContentLength = 1;
getObjectResponse.Object.LastModified = new DateTime(1970, 1, 1);
getObjectResponse.Key = "test.txt";
getObjectResponse.ContentLength = 1;
getObjectResponse.LastModified = new DateTime(1970, 1, 1);

amazonS3Client.Setup(o => o.GetObjectAsync("bucket-1", "/root-path-1/test.txt", default)).ReturnsAsync(getObjectResponse.Object);
amazonS3Client.GetObjectAsync("bucket-1", "/root-path-1/test.txt").Returns(getObjectResponse);

var fileModel = new FileModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Azure.Storage.Blobs;
using Moq;
using NSubstitute;
using SharpGrip.FileSystem.Adapters.AzureBlobStorage;
using Xunit;

Expand All @@ -10,8 +10,8 @@ public class AzureBlobStorageAdapterTest
[Fact]
public void Test_Instantiation()
{
var blobContainerClient = new Mock<BlobContainerClient>();
var azureBlobStorageAdapter = new AzureBlobStorageAdapter("prefix", "/root-path", blobContainerClient.Object);
var blobContainerClient = Substitute.For<BlobContainerClient>();
var azureBlobStorageAdapter = new AzureBlobStorageAdapter("prefix", "/root-path", blobContainerClient);

Assert.Equal("prefix", azureBlobStorageAdapter.Prefix);
Assert.Equal("/root-path", azureBlobStorageAdapter.RootPath);
Expand Down
14 changes: 7 additions & 7 deletions Tests/src/FileSystem.Adapters.Sftp/SftpAdapterTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Threading.Tasks;
using Moq;
using NSubstitute;
using Renci.SshNet;
using SharpGrip.FileSystem.Adapters.Sftp;
using SharpGrip.FileSystem.Exceptions;
Expand All @@ -12,8 +12,8 @@ public class SftpAdapterTest
[Fact]
public void Test_Instantiation()
{
var sftpClient = new Mock<SftpClient>("hostName", "userName", "password");
var sftpAdapter = new SftpAdapter("prefix", "/root-path", sftpClient.Object);
var sftpClient = Substitute.For<SftpClient>("hostName", "userName", "password");
var sftpAdapter = new SftpAdapter("prefix", "/root-path", sftpClient);

Assert.Equal("prefix", sftpAdapter.Prefix);
Assert.Equal("/root-path", sftpAdapter.RootPath);
Expand All @@ -22,17 +22,17 @@ public void Test_Instantiation()
[Fact]
public void Test_Connect()
{
var sftpClient = new Mock<SftpClient>("hostName", "userName", "password");
var sftpAdapter = new SftpAdapter("prefix-1", "/root-path-1", sftpClient.Object);
var sftpClient = Substitute.For<SftpClient>("hostName", "userName", "password");
var sftpAdapter = new SftpAdapter("prefix-1", "/root-path-1", sftpClient);

Assert.Throws<ConnectionException>(() => sftpAdapter.Connect());
}

[Fact]
public async Task Test_Get_File_Async()
{
var sftpClient = new Mock<SftpClient>("hostName", "userName", "password");
var sftpAdapter = new SftpAdapter("prefix-1", "/root-path-1", sftpClient.Object);
var sftpClient = Substitute.For<SftpClient>("hostName", "userName", "password");
var sftpAdapter = new SftpAdapter("prefix-1", "/root-path-1", sftpClient);

await Assert.ThrowsAsync<ConnectionException>(async () => await sftpAdapter.GetFileAsync("prefix-1://test.txt"));
}
Expand Down