Skip to content

Commit 032f696

Browse files
committed
Code cleanup
1 parent dd89640 commit 032f696

File tree

377 files changed

+1927
-2447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

377 files changed

+1927
-2447
lines changed

.globalconfig

+6
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,12 @@ dotnet_diagnostic.CA1711.severity = none # Identifiers should not have incorrect
206206
dotnet_diagnostic.S2997.severity = error # "IDisposables" created in a "using" statement should not be returned
207207
dotnet_diagnostic.S125.severity = none # Sections of code should not be commented out
208208

209+
dotnet_diagnostic.RCS1003.severity = none # Add braces to if-else (when expression spans over multiple lines)
210+
dotnet_diagnostic.MA0003.severity = none # Add parameter name to improve readability
211+
dotnet_diagnostic.RCS1063.severity = none # Avoid usage of do statement to create an infinite loop
212+
213+
214+
209215
# Broken
210216
dotnet_diagnostic.S2589.severity = none # Boolean expressions should not be gratuitous
211217
dotnet_diagnostic.S2583.severity = none # Conditionally executed code should be reachable

SimpleS3.sln.DotSettings

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConvertIfStatementToSwitchStatement/@EntryIndexedValue">DO_NOT_SHOW</s:String>
3+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForCanBeConvertedToForeach/@EntryIndexedValue">DO_NOT_SHOW</s:String>
4+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator/@EntryIndexedValue">DO_NOT_SHOW</s:String>
5+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator/@EntryIndexedValue">DO_NOT_SHOW</s:String>
6+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=InvertIf/@EntryIndexedValue">DO_NOT_SHOW</s:String>
7+
<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=LoopCanBeConvertedToQuery/@EntryIndexedValue">DO_NOT_SHOW</s:String></wpf:ResourceDictionary>

Src/ProviderTests/.globalconfig

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dotnet_diagnostic.CA1515.severity = none # Consider making public types internal
2+
dotnet_diagnostic.CS8618.severity = none # Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
3+
dotnet_diagnostic.CA1822.severity = none # Mark members as static

Src/ProviderTests/Buckets/BucketLifecycleConfigurationTests.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ await CreateTempBucketAsync(provider, client, async tempBucket =>
2828
rule3.Expiration = new S3Expiration(DateTimeOffset.UtcNow.AddDays(1));
2929
rule3.Filter = new S3Filter { Tag = new KeyValuePair<string, string>("type", "temp") };
3030

31-
PutBucketLifecycleConfigurationResponse putResp = await client.PutBucketLifecycleConfigurationAsync(tempBucket, new[] { rule1, rule2, rule3 });
31+
PutBucketLifecycleConfigurationResponse putResp = await client.PutBucketLifecycleConfigurationAsync(tempBucket, [rule1, rule2, rule3]);
3232
Assert.True(putResp.IsSuccess);
3333

3434
GetBucketLifecycleConfigurationResponse getResp = await client.GetBucketLifecycleConfigurationAsync(tempBucket);
@@ -67,7 +67,7 @@ await CreateTempBucketAsync(provider, client, async tempBucket =>
6767
rule.Expiration = new S3Expiration(DateTimeOffset.UtcNow.AddDays(10));
6868
rule.Filter = new S3Filter(); //Empty filter means the whole bucket is affected
6969

70-
PutBucketLifecycleConfigurationResponse putResp = await client.PutBucketLifecycleConfigurationAsync(tempBucket, new[] { rule });
70+
PutBucketLifecycleConfigurationResponse putResp = await client.PutBucketLifecycleConfigurationAsync(tempBucket, [rule]);
7171
Assert.True(putResp.IsSuccess);
7272

7373
GetBucketLifecycleConfigurationResponse getResp = await client.GetBucketLifecycleConfigurationAsync(tempBucket);
@@ -99,7 +99,7 @@ await CreateTempBucketAsync(provider, client, async tempBucket =>
9999
rule.Filter = filter;
100100
rule.Expiration = new S3Expiration(DateTimeOffset.UtcNow.AddDays(1));
101101

102-
PutBucketLifecycleConfigurationResponse putResp = await client.PutBucketLifecycleConfigurationAsync(tempBucket, new[] { rule });
102+
PutBucketLifecycleConfigurationResponse putResp = await client.PutBucketLifecycleConfigurationAsync(tempBucket, [rule]);
103103
Assert.True(putResp.IsSuccess);
104104

105105
GetBucketLifecycleConfigurationResponse getResp = await client.GetBucketLifecycleConfigurationAsync(tempBucket);

Src/ProviderTests/Misc/MultipleProvidersAttribute.cs

+6-14
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,26 @@
66

77
namespace Genbox.ProviderTests.Misc;
88

9-
public sealed class MultipleProvidersAttribute : DataAttribute
9+
internal sealed class MultipleProvidersAttribute(S3Provider providers, params object[] otherData) : DataAttribute
1010
{
11-
private readonly object[] _otherData;
12-
private readonly S3Provider _providers;
1311
private bool _shouldSkip;
1412

15-
public MultipleProvidersAttribute(S3Provider providers, params object[] otherData)
16-
{
17-
_providers = providers;
18-
_otherData = otherData;
19-
}
20-
2113
public override string? Skip => _shouldSkip ? "Not supported" : null;
2214

2315
public override IEnumerable<object?[]> GetData(MethodInfo testMethod)
2416
{
2517
foreach ((S3Provider provider, IProfile profile, ISimpleClient client) in ProviderSetup.Instance.Clients)
2618
{
27-
_shouldSkip = !_providers.HasFlag(provider);
19+
_shouldSkip = !providers.HasFlag(provider);
2820
string bucket = UtilityHelper.GetTestBucket(profile);
2921

30-
if (_otherData.Length > 0)
22+
if (otherData.Length > 0)
3123
{
32-
foreach (object o in _otherData)
33-
yield return new[] { provider, bucket, client, o };
24+
foreach (object o in otherData)
25+
yield return [provider, bucket, client, o];
3426
}
3527
else
36-
yield return new object?[] { provider, bucket, client };
28+
yield return [provider, bucket, client];
3729
}
3830
}
3931
}

Src/ProviderTests/Misc/ProviderSetup.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
namespace Genbox.ProviderTests.Misc;
88

9-
public class ProviderSetup
9+
internal class ProviderSetup
1010
{
1111
private ProviderSetup()
1212
{

Src/ProviderTests/Misc/TestConstants.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace Genbox.ProviderTests.Misc;
22

3-
public static class TestConstants
3+
internal static class TestConstants
44
{
55
public const string TestUsername = "qvistian";
66
public const string TestEmail = "[email protected]";

Src/ProviderTests/Multipart/AbortMultipartTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class AbortMultipartTests : TestBase
1111
[MultipleProviders(S3Provider.All)]
1212
public async Task AbortIncompleteUpload(S3Provider _, string bucket, ISimpleClient client)
1313
{
14-
string objectKey = nameof(AbortIncompleteUpload);
14+
const string objectKey = nameof(AbortIncompleteUpload);
1515

1616
CreateMultipartUploadResponse createResp = await client.CreateMultipartUploadAsync(bucket, objectKey);
1717
Assert.Equal(200, createResp.StatusCode);

Src/ProviderTests/Multipart/ListMultipartUploadsTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public async Task ListMultipartUploads(S3Provider provider, string _, ISimpleCli
1717
await CreateTempBucketAsync(provider, client, async tempBucket =>
1818
{
1919
//The percentage sign at the end is to test if encoding works correctly
20-
string objName = nameof(ListMultipartUploads) + "%";
20+
const string objName = nameof(ListMultipartUploads) + "%";
2121

2222
CreateMultipartUploadResponse createResp = await client.CreateMultipartUploadAsync(tempBucket, objName);
2323
Assert.Equal(200, createResp.StatusCode);

Src/ProviderTests/Multipart/ListPartsTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public async Task ListParts(S3Provider provider, string _, ISimpleClient client)
1818
await CreateTempBucketAsync(provider, client, async tempBucket =>
1919
{
2020
//We add the special characters at the end to test EncodingType support.
21-
string objName = nameof(ListParts) + "%";
21+
const string objName = nameof(ListParts) + "%";
2222

2323
CreateMultipartUploadResponse createResp = await client.CreateMultipartUploadAsync(tempBucket, objName);
2424

Src/ProviderTests/Multipart/MultipartTests.cs

+12-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class MultipartTests : TestBase
1818
[MultipleProviders(S3Provider.GoogleCloudStorage, SseAlgorithm.Aes256)]
1919
public async Task MultipartWithEncryption(S3Provider provider, string bucket, ISimpleClient client, SseAlgorithm algorithm)
2020
{
21-
string objectKey = nameof(MultipartWithEncryption);
21+
const string objectKey = nameof(MultipartWithEncryption);
2222

2323
CreateMultipartUploadResponse createResp = await client.CreateMultipartUploadAsync(bucket, objectKey, req => req.SseAlgorithm = algorithm);
2424
Assert.Equal(200, createResp.StatusCode);
@@ -54,9 +54,9 @@ public async Task MultipartWithEncryption(S3Provider provider, string bucket, IS
5454
[MultipleProviders(S3Provider.AmazonS3)]
5555
public async Task MultipartCustomerEncryption(S3Provider _, string bucket, ISimpleClient client)
5656
{
57-
string objectKey = nameof(MultipartCustomerEncryption);
57+
const string objectKey = nameof(MultipartCustomerEncryption);
5858

59-
byte[] key = { 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8 };
59+
byte[] key = [1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 3, 4, 5, 6, 7, 8];
6060
byte[] keyMd5 = CryptoHelper.Md5Hash(key);
6161

6262
CreateMultipartUploadResponse initResp = await client.CreateMultipartUploadAsync(bucket, objectKey, r =>
@@ -79,7 +79,7 @@ public async Task MultipartCustomerEncryption(S3Provider _, string bucket, ISimp
7979
Assert.Equal(SseCustomerAlgorithm.Aes256, uploadResp1.SseCustomerAlgorithm);
8080
Assert.Equal(keyMd5, uploadResp1.SseCustomerKeyMd5);
8181

82-
CompleteMultipartUploadResponse completeResp = await client.CompleteMultipartUploadAsync(bucket, objectKey, initResp.UploadId, new[] { new S3PartInfo(uploadResp1.ETag, 1) });
82+
CompleteMultipartUploadResponse completeResp = await client.CompleteMultipartUploadAsync(bucket, objectKey, initResp.UploadId, [new S3PartInfo(uploadResp1.ETag, 1)]);
8383
Assert.Equal(200, completeResp.StatusCode);
8484
Assert.Equal(SseCustomerAlgorithm.Aes256, completeResp.SseCustomerAlgorithm);
8585
}
@@ -88,7 +88,7 @@ public async Task MultipartCustomerEncryption(S3Provider _, string bucket, ISimp
8888
[MultipleProviders(S3Provider.AmazonS3 | S3Provider.GoogleCloudStorage)]
8989
public async Task MultipartLockMode(S3Provider _, string bucket, ISimpleClient client)
9090
{
91-
string objectKey = nameof(MultipartLockMode);
91+
const string objectKey = nameof(MultipartLockMode);
9292

9393
CreateMultipartUploadResponse initResp = await client.CreateMultipartUploadAsync(bucket, objectKey, r =>
9494
{
@@ -103,15 +103,15 @@ public async Task MultipartLockMode(S3Provider _, string bucket, ISimpleClient c
103103
UploadPartResponse uploadResp = await client.UploadPartAsync(bucket, objectKey, 1, initResp.UploadId, ms, r => r.ContentMd5 = CryptoHelper.Md5Hash(file));
104104
Assert.Equal(200, uploadResp.StatusCode);
105105

106-
CompleteMultipartUploadResponse completeResp = await client.CompleteMultipartUploadAsync(bucket, objectKey, initResp.UploadId, new[] { new S3PartInfo(uploadResp.ETag, 1) });
106+
CompleteMultipartUploadResponse completeResp = await client.CompleteMultipartUploadAsync(bucket, objectKey, initResp.UploadId, [new S3PartInfo(uploadResp.ETag, 1)]);
107107
Assert.Equal(200, completeResp.StatusCode);
108108
}
109109

110110
[Theory]
111111
[MultipleProviders(S3Provider.AmazonS3 | S3Provider.GoogleCloudStorage)]
112112
public async Task MultipartSinglePart(S3Provider provider, string bucket, ISimpleClient client)
113113
{
114-
string objectKey = nameof(MultipartSinglePart);
114+
const string objectKey = nameof(MultipartSinglePart);
115115

116116
CreateMultipartUploadResponse createResp = await client.CreateMultipartUploadAsync(bucket, objectKey);
117117
Assert.Equal(200, createResp.StatusCode);
@@ -135,7 +135,7 @@ public async Task MultipartSinglePart(S3Provider provider, string bucket, ISimpl
135135
Assert.Equal(200, uploadResp.StatusCode);
136136
Assert.Equal("\"10f74ef02085310ccd1f87150b83e537\"", uploadResp.ETag);
137137

138-
CompleteMultipartUploadResponse completeResp = await client.CompleteMultipartUploadAsync(bucket, objectKey, createResp.UploadId, new[] { new S3PartInfo(uploadResp.ETag, 1) });
138+
CompleteMultipartUploadResponse completeResp = await client.CompleteMultipartUploadAsync(bucket, objectKey, createResp.UploadId, [new S3PartInfo(uploadResp.ETag, 1)]);
139139
Assert.Equal(200, completeResp.StatusCode);
140140
Assert.Equal("\"bd74e21dfa8678d127240f76e518e9c2-1\"", completeResp.ETag);
141141

@@ -151,7 +151,7 @@ public async Task MultipartSinglePart(S3Provider provider, string bucket, ISimpl
151151
[MultipleProviders(S3Provider.All)]
152152
public async Task MultipartTooSmall(S3Provider provider, string bucket, ISimpleClient client)
153153
{
154-
string objectKey = nameof(MultipartTooSmall);
154+
const string objectKey = nameof(MultipartTooSmall);
155155

156156
CreateMultipartUploadResponse initResp = await client.CreateMultipartUploadAsync(bucket, objectKey);
157157
Assert.Equal(200, initResp.StatusCode);
@@ -172,15 +172,15 @@ public async Task MultipartTooSmall(S3Provider provider, string bucket, ISimpleC
172172
UploadPartResponse uploadResp2 = await client.UploadPartAsync(bucket, objectKey, 2, initResp.UploadId, ms2);
173173
Assert.Equal(200, uploadResp2.StatusCode);
174174

175-
CompleteMultipartUploadResponse completeResp = await client.CompleteMultipartUploadAsync(bucket, objectKey, initResp.UploadId, new[] { new S3PartInfo(uploadResp1.ETag, 1), new S3PartInfo(uploadResp2.ETag, 2) });
175+
CompleteMultipartUploadResponse completeResp = await client.CompleteMultipartUploadAsync(bucket, objectKey, initResp.UploadId, [new S3PartInfo(uploadResp1.ETag, 1), new S3PartInfo(uploadResp2.ETag, 2)]);
176176
Assert.Equal(400, completeResp.StatusCode);
177177
}
178178

179179
[Theory]
180180
[MultipleProviders(S3Provider.AmazonS3 | S3Provider.GoogleCloudStorage)]
181181
public async Task MultipartUpload(S3Provider provider, string bucket, ISimpleClient client)
182182
{
183-
string objectKey = nameof(MultipartUpload);
183+
const string objectKey = nameof(MultipartUpload);
184184

185185
CreateMultipartUploadResponse initResp = await client.CreateMultipartUploadAsync(bucket, objectKey);
186186
Assert.Equal(200, initResp.StatusCode);
@@ -204,7 +204,7 @@ public async Task MultipartUpload(S3Provider provider, string bucket, ISimpleCli
204204
Assert.Equal(200, uploadResp2.StatusCode);
205205
Assert.NotNull(uploadResp2.ETag);
206206

207-
CompleteMultipartUploadResponse completeResp = await client.CompleteMultipartUploadAsync(bucket, objectKey, initResp.UploadId, new[] { new S3PartInfo(uploadResp1.ETag, 1), new S3PartInfo(uploadResp2.ETag, 2) });
207+
CompleteMultipartUploadResponse completeResp = await client.CompleteMultipartUploadAsync(bucket, objectKey, initResp.UploadId, [new S3PartInfo(uploadResp1.ETag, 1), new S3PartInfo(uploadResp2.ETag, 2)]);
208208
Assert.Equal(200, completeResp.StatusCode);
209209
Assert.NotNull(uploadResp2.ETag);
210210

Src/ProviderTests/Objects/CopyObjectTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class CopyObjectTests : TestBase
1313
public async Task CopyObject(S3Provider _, string bucket, ISimpleClient client)
1414
{
1515
//Upload an object to copy
16-
string sourceKey = nameof(CopyObject);
17-
string destinationKey = sourceKey + "2";
16+
const string sourceKey = nameof(CopyObject);
17+
const string destinationKey = sourceKey + "2";
1818

1919
await client.PutObjectStringAsync(bucket, sourceKey, "test");
2020

Src/ProviderTests/Objects/GetObjectTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public async Task GetObjectString(S3Provider _, string bucket, ISimpleClient cli
3636
// - Preserve casing
3737
// - Preserve encoding
3838

39-
string stringData = "Hello 你好 ਸਤ ਸ੍ਰੀ ਅਕਾਲ Привет";
39+
const string stringData = "Hello 你好 ਸਤ ਸ੍ਰੀ ਅਕਾਲ Привет";
4040

4141
PutObjectResponse putResp = await client.PutObjectStringAsync(bucket, nameof(GetObjectString), stringData);
4242
Assert.Equal(200, putResp.StatusCode);

Src/ProviderTests/Objects/ListObjectVersionsTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public async Task ListObjectVersionsWithEncoding(S3Provider provider, string _,
185185
{
186186
await CreateTempBucketAsync(provider, client, async tempBucket =>
187187
{
188-
string tempObjName = "!#/()";
188+
const string tempObjName = "!#/()";
189189

190190
await client.PutObjectAsync(tempBucket, tempObjName, null);
191191

Src/ProviderTests/Objects/ListObjectsTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public async Task ListObjectsWithEncoding(S3Provider provider, string _, ISimple
111111
{
112112
await CreateTempBucketAsync(provider, client, async tempBucket =>
113113
{
114-
string tempObjName = "!#/()";
114+
const string tempObjName = "!#/()";
115115

116116
PutObjectResponse putResp = await client.PutObjectAsync(tempBucket, tempObjName, null);
117117
Assert.Equal(200, putResp.StatusCode);

Src/ProviderTests/Objects/ObjectAclTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ObjectAclTests : TestBase
1313
[MultipleProviders(S3Provider.AmazonS3 | S3Provider.GoogleCloudStorage)]
1414
public async Task PutGetObjectAcl(S3Provider provider, string bucket, ISimpleClient client)
1515
{
16-
string objectKey = nameof(PutGetObjectAcl);
16+
const string objectKey = nameof(PutGetObjectAcl);
1717

1818
//Create an object
1919
PutObjectResponse putResp1 = await client.PutObjectAsync(bucket, objectKey, null);

Src/ProviderTests/Objects/ObjectLegalHoldTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class ObjectLegalHoldTests : TestBase
1111
[MultipleProviders(S3Provider.AmazonS3 | S3Provider.BackBlazeB2)]
1212
public async Task PutGetObjectLegalHold(S3Provider _, string bucket, ISimpleClient client)
1313
{
14-
string objectKey = nameof(PutGetObjectLegalHold);
14+
const string objectKey = nameof(PutGetObjectLegalHold);
1515

1616
//Create an object
1717
await client.PutObjectAsync(bucket, objectKey, null);

Src/ProviderTests/Signed/SignedTests.cs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Genbox.ProviderTests.Misc;
22
using Genbox.SimpleS3.Core.Abstracts;
33
using Genbox.SimpleS3.Core.Abstracts.Enums;
4-
using Genbox.SimpleS3.Core.Extensions;
54
using Genbox.SimpleS3.Core.Network.Requests.Multipart;
65
using Genbox.SimpleS3.Core.Network.Requests.Objects;
76
using Genbox.SimpleS3.Core.Network.Requests.S3Types;

Src/SimpleS3.AmazonS3/AmazonS3Client.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
namespace Genbox.SimpleS3.AmazonS3;
2020

21-
/// <summary>This class provides a convenient way to access all the functionality related to the S3 service, buckets and
22-
/// objects at the same time.</summary>
21+
/// <summary>This class provides a convenient way to access all the functionality related to the S3 service, buckets and objects at the same time.</summary>
2322
public sealed class AmazonS3Client : ClientBase, ISimpleClient
2423
{
2524
/// <summary>Creates a new instance of <see cref="AmazonS3Client" /></summary>

Src/SimpleS3.BackBlazeB2/BackBlazeB2Client.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818

1919
namespace Genbox.SimpleS3.BackBlazeB2;
2020

21-
/// <summary>This class provides a convenient way to access all the functionality related to the S3 service, buckets and
22-
/// objects at the same time.</summary>
21+
/// <summary>This class provides a convenient way to access all the functionality related to the S3 service, buckets and objects at the same time.</summary>
2322
public sealed class BackBlazeB2Client : ClientBase, ISimpleClient
2423
{
2524
/// <summary>Creates a new instance of <see cref="BackBlazeB2Client" /></summary>

0 commit comments

Comments
 (0)