Skip to content

Commit 1af7ad3

Browse files
authored
Merge pull request #12 from SharpGrip/11-replace-moq-with-nsubstitute
replace moq with nsubstitute
2 parents d009ca2 + ccda522 commit 1af7ad3

6 files changed

Lines changed: 28 additions & 27 deletions

File tree

.github/workflows/Build.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ on:
1616
workflow_dispatch:
1717
push:
1818
branches:
19-
- 'master'
20-
- 'develop'
19+
- '*'
2120

2221
jobs:
2322
build:

FileSystem.Adapters.AmazonS3/src/AmazonS3Adapter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ namespace SharpGrip.FileSystem.Adapters.AmazonS3
1515
{
1616
public class AmazonS3Adapter : Adapter
1717
{
18-
private readonly AmazonS3Client client;
18+
private readonly IAmazonS3 client;
1919
private readonly string bucketName;
2020

21-
public AmazonS3Adapter(string prefix, string rootPath, AmazonS3Client client, string bucketName) : base(prefix, rootPath)
21+
public AmazonS3Adapter(string prefix, string rootPath, IAmazonS3 client, string bucketName) : base(prefix, rootPath)
2222
{
2323
this.client = client;
2424
this.bucketName = bucketName;

Tests/Tests.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
<ItemGroup>
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.0" />
11-
<PackageReference Include="Moq" Version="4.18.4" />
11+
<PackageReference Include="NSubstitute" Version="5.0.0" />
12+
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
13+
<PrivateAssets>all</PrivateAssets>
14+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
15+
</PackageReference>
1216
<PackageReference Include="xunit" Version="2.5.0" />
1317
<PackageReference Include="xunit.runner.console" Version="2.5.0">
1418
<PrivateAssets>all</PrivateAssets>

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
using System;
22
using System.Threading.Tasks;
3-
using Amazon;
43
using Amazon.S3;
54
using Amazon.S3.Model;
6-
using Moq;
5+
using NSubstitute;
76
using SharpGrip.FileSystem.Adapters.AmazonS3;
87
using SharpGrip.FileSystem.Models;
98
using Xunit;
@@ -15,8 +14,8 @@ public class AmazonS3AdapterTest
1514
[Fact]
1615
public void Test_Instantiation()
1716
{
18-
var amazonS3Client = new Mock<AmazonS3Client>("awsAccessKeyId", "awsSecretAccessKey", RegionEndpoint.USEast2);
19-
var amazonS3Adapter = new AmazonS3Adapter("prefix", "/root-path", amazonS3Client.Object, "bucket");
17+
var amazonS3Client = Substitute.For<IAmazonS3>();
18+
var amazonS3Adapter = new AmazonS3Adapter("prefix", "/root-path", amazonS3Client, "bucket");
2019

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

31-
var getObjectResponse = new Mock<GetObjectResponse>();
30+
var getObjectResponse = Substitute.For<GetObjectResponse>();
3231

33-
getObjectResponse.SetupAllProperties();
34-
getObjectResponse.Object.Key = "test.txt";
35-
getObjectResponse.Object.ContentLength = 1;
36-
getObjectResponse.Object.LastModified = new DateTime(1970, 1, 1);
32+
getObjectResponse.Key = "test.txt";
33+
getObjectResponse.ContentLength = 1;
34+
getObjectResponse.LastModified = new DateTime(1970, 1, 1);
3735

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

4038
var fileModel = new FileModel
4139
{

Tests/src/FileSystem.Adapters.AzureBlobStorage/AzureBlobStorageAdapterTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using Azure.Storage.Blobs;
2-
using Moq;
2+
using NSubstitute;
33
using SharpGrip.FileSystem.Adapters.AzureBlobStorage;
44
using Xunit;
55

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

1616
Assert.Equal("prefix", azureBlobStorageAdapter.Prefix);
1717
Assert.Equal("/root-path", azureBlobStorageAdapter.RootPath);

Tests/src/FileSystem.Adapters.Sftp/SftpAdapterTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Threading.Tasks;
2-
using Moq;
2+
using NSubstitute;
33
using Renci.SshNet;
44
using SharpGrip.FileSystem.Adapters.Sftp;
55
using SharpGrip.FileSystem.Exceptions;
@@ -12,8 +12,8 @@ public class SftpAdapterTest
1212
[Fact]
1313
public void Test_Instantiation()
1414
{
15-
var sftpClient = new Mock<SftpClient>("hostName", "userName", "password");
16-
var sftpAdapter = new SftpAdapter("prefix", "/root-path", sftpClient.Object);
15+
var sftpClient = Substitute.For<SftpClient>("hostName", "userName", "password");
16+
var sftpAdapter = new SftpAdapter("prefix", "/root-path", sftpClient);
1717

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

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

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

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

0 commit comments

Comments
 (0)