Skip to content

Commit b5bbdff

Browse files
committed
Replace checking null with checking IsNullOrEmpty as well as fix some warning in project and unit tests
#2
1 parent 3954754 commit b5bbdff

4 files changed

Lines changed: 6 additions & 8 deletions

File tree

src/Services/AmazonS3Connection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public class AmazonS3Connection : IAmazonS3Connection
99
{
1010
public AmazonS3Client Connect(AmazonS3Specifications specifications)
1111
{
12-
if (specifications.AccessKey == null)
12+
if (string.IsNullOrEmpty(specifications.AccessKey))
1313
throw new ArgumentNullException(nameof(specifications.AccessKey));
1414

15-
if (specifications.SecretKey == null)
15+
if (string.IsNullOrEmpty(specifications.SecretKey))
1616
throw new ArgumentNullException(nameof(specifications.SecretKey));
1717

1818
var awsCredentials = string.IsNullOrEmpty(specifications.SessionToken)

src/Services/AmazonS3Manager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ private async Task WriteEntity(WriteParameters writeParameters, CancellationToke
324324

325325
private PluginContext CreateContextFromStringData(string path, string data)
326326
{
327-
var root = Path.GetPathRoot(path);
327+
var root = Path.GetPathRoot(path) ?? string.Empty;
328328
var relativePath = Path.GetRelativePath(root, path);
329329
var dataBytesArray = data.IsBase64String() ? data.Base64ToByteArray() : data.ToByteArray();
330330

tests/FlowSynx.Plugins.Amazon.S3.UnitTests/PathHelperTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ public void GetParent_ShouldReturnCorrectParent(string input, string expected)
7777
[Theory]
7878
[InlineData("folder/../subfolder", "subfolder")]
7979
[InlineData("a/b/../c", "a/c")]
80-
[InlineData(null, "/")]
8180
[InlineData("", "/")]
8281
public void Normalize_ShouldResolvePathsCorrectly(string input, string expected)
8382
{
@@ -111,7 +110,6 @@ public void Split_ShouldReturnEmptyArray_WhenNullOrEmpty()
111110
}
112111

113112
[Theory]
114-
[InlineData(null, true)]
115113
[InlineData("", true)]
116114
[InlineData("/", true)]
117115
[InlineData("folder", false)]
@@ -132,7 +130,7 @@ public void ComparePath_ShouldReturnTrueForEquivalentPaths(string p1, string p2,
132130
[Theory]
133131
[InlineData(null, "")]
134132
[InlineData(@"folder\subfolder\file.txt", "folder/subfolder/file.txt")]
135-
public void ToUnixPath_ShouldConvertBackslashesToForwardSlashes(string input, string expected)
133+
public void ToUnixPath_ShouldConvertBackslashesToForwardSlashes(string? input, string expected)
136134
{
137135
Assert.Equal(expected, PathHelper.ToUnixPath(input));
138136
}

tests/FlowSynx.Plugins.Amazon.S3.UnitTests/Services/AmazonS3ConnectionTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void Connect_WithNullAccessKey_ThrowsArgumentNullException()
2121
// Arrange
2222
var specs = new AmazonS3Specifications
2323
{
24-
AccessKey = null,
24+
AccessKey = string.Empty,
2525
SecretKey = "secret"
2626
};
2727

@@ -37,7 +37,7 @@ public void Connect_WithNullSecretKey_ThrowsArgumentNullException()
3737
var specs = new AmazonS3Specifications
3838
{
3939
AccessKey = "access",
40-
SecretKey = null
40+
SecretKey = string.Empty
4141
};
4242

4343
// Act & Assert

0 commit comments

Comments
 (0)