Skip to content

Commit fe3928a

Browse files
authored
Warnings6 (#829)
* Fix warnings * Fix warnings * Fix regex * Rewrite handlers * Format * Move files * Format * Remove * Rename
1 parent 023ec7e commit fe3928a

File tree

66 files changed

+298
-150
lines changed

Some content is hidden

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

66 files changed

+298
-150
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,5 +377,5 @@ dotnet_separate_import_directive_groups = false
377377

378378
dotnet_style_prefer_foreach_explicit_cast_in_source = when_strongly_typed
379379

380-
MA0051.maximum_lines_per_method = 100
380+
MA0051.maximum_lines_per_method = 150
381381
MA0051.maximum_statements_per_method = 60

Directory.Build.props

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@
8484
<PrivateAssets>all</PrivateAssets>
8585
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
8686
</PackageReference>
87-
<!--
88-
<PackageReference Include="Meziantou.Analyzer" Version="2.0.80">
87+
<PackageReference Include="Meziantou.Analyzer" Version="2.0.81">
8988
<PrivateAssets>all</PrivateAssets>
9089
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
9190
</PackageReference>
92-
<PackageReference Include="IDisposableAnalyzers" Version="4.0.6">
91+
<!--
92+
<PackageReference Include="AsyncFixer" Version="1.6.0">
9393
<PrivateAssets>all</PrivateAssets>
9494
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9595
</PackageReference>
96-
<PackageReference Include="AsyncFixer" Version="1.6.0">
96+
<PackageReference Include="IDisposableAnalyzers" Version="4.0.6">
9797
<PrivateAssets>all</PrivateAssets>
9898
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9999
</PackageReference>

Minio.Examples/Cases/MyRequestLogger.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
using System.Text;
1818
using Minio.DataModel.Tracing;
19+
using Minio.Handlers;
1920

2021
namespace Minio.Examples.Cases;
2122

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Minio.DataModel.Result;
2+
using Minio.Handlers;
3+
using Polly;
4+
5+
namespace Minio.Examples.Cases;
6+
7+
public class RetryPolicyHandler : IRetryPolicyHandler
8+
{
9+
private readonly AsyncPolicy<ResponseResult> policy;
10+
11+
public RetryPolicyHandler(AsyncPolicy<ResponseResult> policy)
12+
{
13+
this.policy = policy ?? throw new ArgumentNullException(nameof(policy));
14+
}
15+
16+
public Task<ResponseResult> Handle(Func<Task<ResponseResult>> executeRequestCallback)
17+
{
18+
return policy.ExecuteAsync(executeRequestCallback);
19+
}
20+
}

Minio.Examples/Cases/RetryPolicyHelper.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
* limitations under the License.
1515
*/
1616

17+
using Minio.DataModel.Result;
1718
using Minio.Exceptions;
19+
using Minio.Handlers;
1820
using Polly;
1921

2022
namespace Minio.Examples.Cases;
2123

2224
internal static class RetryPolicyHelper
2325
{
24-
private const int defaultRetryCount = 3;
26+
private const int DefaultRetryCount = 3;
2527
private static readonly TimeSpan defaultRetryInterval = TimeSpan.FromMilliseconds(200);
2628

2729
private static readonly TimeSpan defaultMaxRetryInterval = TimeSpan.FromSeconds(10);
@@ -49,7 +51,7 @@ public static PolicyBuilder<ResponseResult> CreatePolicyBuilder()
4951

5052
public static AsyncPolicy<ResponseResult> GetDefaultRetryPolicy()
5153
{
52-
return GetDefaultRetryPolicy(defaultRetryCount, defaultRetryInterval, defaultMaxRetryInterval);
54+
return GetDefaultRetryPolicy(DefaultRetryCount, defaultRetryInterval, defaultMaxRetryInterval);
5355
}
5456

5557
public static AsyncPolicy<ResponseResult> GetDefaultRetryPolicy(
@@ -63,11 +65,11 @@ public static AsyncPolicy<ResponseResult> GetDefaultRetryPolicy(
6365
i => CalcBackoff(i, retryInterval, maxRetryInterval));
6466
}
6567

66-
public static RetryPolicyHandler AsRetryDelegate(this AsyncPolicy<ResponseResult> policy)
68+
public static IRetryPolicyHandler AsRetryDelegate(this AsyncPolicy<ResponseResult> policy)
6769
{
6870
return policy is null
6971
? null
70-
: policy.ExecuteAsync;
72+
: new RetryPolicyHandler(policy);
7173
}
7274

7375
public static MinioClient WithRetryPolicy(this MinioClient client, AsyncPolicy<ResponseResult> policy)

Minio.Examples/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
using System.Diagnostics.CodeAnalysis;
1718
using System.Globalization;
1819
using System.Net;
1920
using System.Runtime.InteropServices;
@@ -53,7 +54,8 @@ public static string GetRandomName()
5354
return "minio-dotnet-example-" + result;
5455
}
5556

56-
public static async Task Main(string[] args)
57+
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "Needs to run all tests")]
58+
public static async Task Main()
5759
{
5860
string endPoint = null;
5961
string accessKey = null;

Minio.Functional.Tests/FunctionalTest.cs

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ internal static async Task ListBuckets_Test(MinioClient minio)
513513
{
514514
var list = await minio.ListBucketsAsync().ConfigureAwait(false);
515515
bucketList = list.Buckets;
516-
bucketList = bucketList.Where(x => x.Name.EndsWith(bucketNameSuffix)).ToList();
516+
bucketList = bucketList.Where(x => x.Name.EndsWith(bucketNameSuffix, StringComparison.OrdinalIgnoreCase))
517+
.ToList();
517518
Assert.AreEqual(noOfBuckets, bucketList.Count);
518519
bucketList.ToList().Sort((x, y) =>
519520
{
@@ -729,7 +730,7 @@ internal static async Task PutGetStatEncryptedObject_Test1(MinioClient minio)
729730
.WithObjectSize(filestream.Length)
730731
.WithServerSideEncryption(ssec)
731732
.WithContentType(contentType);
732-
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
733+
_ = await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
733734

734735
var getObjectArgs = new GetObjectArgs()
735736
.WithBucket(bucketName)
@@ -752,8 +753,8 @@ internal static async Task PutGetStatEncryptedObject_Test1(MinioClient minio)
752753
.WithBucket(bucketName)
753754
.WithObject(objectName)
754755
.WithServerSideEncryption(ssec);
755-
await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
756-
await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
756+
_ = await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
757+
_ = await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
757758
}
758759

759760
new MintLogger("PutGetStatEncryptedObject_Test1", putObjectSignature,
@@ -816,7 +817,7 @@ internal static async Task PutGetStatEncryptedObject_Test2(MinioClient minio)
816817
.WithObjectSize(filestream.Length)
817818
.WithContentType(contentType)
818819
.WithServerSideEncryption(ssec);
819-
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
820+
_ = await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
820821

821822
var getObjectArgs = new GetObjectArgs()
822823
.WithBucket(bucketName)
@@ -839,8 +840,8 @@ internal static async Task PutGetStatEncryptedObject_Test2(MinioClient minio)
839840
.WithBucket(bucketName)
840841
.WithObject(objectName)
841842
.WithServerSideEncryption(ssec);
842-
await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
843-
await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
843+
_ = await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
844+
_ = await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
844845
}
845846

846847
new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature,
@@ -901,7 +902,7 @@ internal static async Task PutGetStatEncryptedObject_Test3(MinioClient minio)
901902
.WithObjectSize(filestream.Length)
902903
.WithServerSideEncryption(sses3)
903904
.WithContentType(contentType);
904-
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
905+
_ = await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
905906

906907
var getObjectArgs = new GetObjectArgs()
907908
.WithBucket(bucketName)
@@ -922,8 +923,8 @@ internal static async Task PutGetStatEncryptedObject_Test3(MinioClient minio)
922923
var statObjectArgs = new StatObjectArgs()
923924
.WithBucket(bucketName)
924925
.WithObject(objectName);
925-
await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
926-
await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
926+
_ = await minio.StatObjectAsync(statObjectArgs).ConfigureAwait(false);
927+
_ = await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
927928
}
928929

929930
new MintLogger("PutGetStatEncryptedObject_Test3", putObjectSignature,
@@ -1308,7 +1309,7 @@ internal static async Task DownloadObjectAsync(MinioClient minio, string url, st
13081309
{
13091310
using var response = await minio.WrapperGetAsync(url).ConfigureAwait(false);
13101311
if (string.IsNullOrEmpty(Convert.ToString(response.Content)) || !HttpStatusCode.OK.Equals(response.StatusCode))
1311-
throw new ArgumentNullException(nameof(response.Content), "Unable to download via presigned URL");
1312+
throw new InvalidOperationException("Unable to download via presigned URL" + nameof(response.Content));
13121313

13131314
using var fs = new FileStream(filePath, FileMode.CreateNew);
13141315
await response.Content.CopyToAsync(fs, cancellationToken).ConfigureAwait(false);
@@ -1340,7 +1341,9 @@ internal static async Task PresignedPostPolicy_Test1(MinioClient minio)
13401341
var args = new Dictionary<string, string>
13411342
(StringComparer.Ordinal)
13421343
{
1343-
{ "bucketName", bucketName }, { "objectName", objectName }, { "expiresOn", expiresOn.ToString() }
1344+
{ "bucketName", bucketName },
1345+
{ "objectName", objectName },
1346+
{ "expiresOn", expiresOn.ToString(CultureInfo.InvariantCulture) }
13441347
};
13451348

13461349
// File to be uploaded
@@ -2160,6 +2163,7 @@ internal static async Task ObjectVersioningAsync_Test1(MinioClient minio)
21602163

21612164
#region Object Lock Configuration
21622165

2166+
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "TODO")]
21632167
internal static async Task ObjectLockConfigurationAsync_Test1(MinioClient minio)
21642168
{
21652169
var startTime = DateTime.Now;
@@ -2376,9 +2380,8 @@ internal static async Task ObjectRetentionAsync_Test1(MinioClient minio)
23762380
.WithRetentionUntilDate(untilDate);
23772381
await minio.SetObjectRetentionAsync(setRetentionArgs).ConfigureAwait(false);
23782382
new MintLogger(nameof(ObjectRetentionAsync_Test1), setObjectRetentionSignature,
2379-
"Tests whether SetObjectRetentionAsync passes", TestStatus.PASS, DateTime.Now - startTime,
2380-
args: args)
2381-
.Log();
2383+
"Tests whether SetObjectRetentionAsync passes", TestStatus.PASS, DateTime.Now - startTime,
2384+
args: args).Log();
23822385
}
23832386
catch (NotImplementedException ex)
23842387
{
@@ -2407,9 +2410,8 @@ internal static async Task ObjectRetentionAsync_Test1(MinioClient minio)
24072410
var untilDate = DateTime.Parse(config.RetainUntilDate, null, DateTimeStyles.RoundtripKind);
24082411
Assert.AreEqual(Math.Ceiling((untilDate - DateTime.Now).TotalDays), plusDays);
24092412
new MintLogger(nameof(ObjectRetentionAsync_Test1), getObjectRetentionSignature,
2410-
"Tests whether GetObjectRetentionAsync passes", TestStatus.PASS, DateTime.Now - startTime,
2411-
args: args)
2412-
.Log();
2413+
"Tests whether GetObjectRetentionAsync passes", TestStatus.PASS, DateTime.Now - startTime,
2414+
args: args).Log();
24132415
}
24142416
catch (NotImplementedException ex)
24152417
{
@@ -2809,8 +2811,8 @@ void Notify(MinioNotificationRaw data)
28092811
rxEventData = ev;
28102812
Notify(rxEventData);
28112813
},
2812-
ex => throw new ArgumentException($"OnError: {ex.Message}"),
2813-
() => throw new ArgumentException("STOPPED LISTENING FOR BUCKET NOTIFICATIONS\n"));
2814+
ex => throw new InvalidOperationException($"OnError: {ex.Message}"),
2815+
() => throw new InvalidOperationException("STOPPED LISTENING FOR BUCKET NOTIFICATIONS\n"));
28142816

28152817
// Sleep to give enough time for the subscriber to be ready
28162818
var sleepTime = 1000; // Milliseconds
@@ -2836,7 +2838,7 @@ void Notify(MinioNotificationRaw data)
28362838
{
28372839
await Task.Delay(waitTime).ConfigureAwait(false);
28382840
if ((DateTime.UtcNow - stTime).TotalMilliseconds >= timeout)
2839-
throw new ArgumentException("Timeout: while waiting for events");
2841+
throw new TimeoutException("Timeout: while waiting for events");
28402842
}
28412843

28422844
foreach (var ev in rxEventsList) Assert.AreEqual("s3:ObjectCreated:Put", ev.EventName);
@@ -2922,7 +2924,7 @@ internal static async Task ListenBucketNotificationsAsync_Test3(MinioClient mini
29222924
{
29232925
await Task.Delay(waitTime).ConfigureAwait(false);
29242926
if ((DateTime.UtcNow - stTime).TotalMilliseconds >= timeout)
2925-
throw new ArgumentException("Timeout: while waiting for events");
2927+
throw new TimeoutException("Timeout: while waiting for events");
29262928
}
29272929

29282930
if (!string.IsNullOrEmpty(rxEventData.json))
@@ -2941,7 +2943,7 @@ internal static async Task ListenBucketNotificationsAsync_Test3(MinioClient mini
29412943
}
29422944
else
29432945
{
2944-
throw new ArgumentException("Missed Event: Bucket notification failed.");
2946+
throw new InvalidDataException("Missed Event: Bucket notification failed.");
29452947
}
29462948
}
29472949
catch (Exception ex)
@@ -4638,7 +4640,7 @@ internal static async Task GetObject_Test1(MinioClient minio)
46384640
.WithStreamData(filestream)
46394641
.WithObjectSize(filestream.Length)
46404642
.WithContentType(contentType);
4641-
await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
4643+
_ = await minio.PutObjectAsync(putObjectArgs).ConfigureAwait(false);
46424644

46434645
var getObjectArgs = new GetObjectArgs()
46444646
.WithBucket(bucketName)
@@ -4656,7 +4658,7 @@ internal static async Task GetObject_Test1(MinioClient minio)
46564658
Assert.AreEqual(file_write_size, file_read_size);
46574659
File.Delete(tempFileName);
46584660
});
4659-
await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
4661+
_ = await minio.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
46604662
}
46614663

46624664
await Task.Delay(1000).ConfigureAwait(false);
@@ -5236,7 +5238,7 @@ internal static async Task ListObjects_Test6(MinioClient minio)
52365238
var subscription = observable.Subscribe(
52375239
item =>
52385240
{
5239-
Assert.IsTrue(item.Key.StartsWith(objectNamePrefix));
5241+
Assert.IsTrue(item.Key.StartsWith(objectNamePrefix, StringComparison.OrdinalIgnoreCase));
52405242
if (!objectNamesSet.Add(item.Key))
52415243
new MintLogger("ListObjects_Test6", listObjectsSignature,
52425244
"Tests whether ListObjects lists more than 1000 objects correctly(max-keys = 1000)",
@@ -5309,7 +5311,7 @@ internal static async Task ListObjectVersions_Test1(MinioClient minio)
53095311
var subscription = observable.Subscribe(
53105312
item =>
53115313
{
5312-
Assert.IsTrue(item.Key.StartsWith(prefix));
5314+
Assert.IsTrue(item.Key.StartsWith(prefix, StringComparison.OrdinalIgnoreCase));
53135315
count++;
53145316
objectVersions.Add(new Tuple<string, string>(item.Key, item.VersionId));
53155317
},
@@ -5526,7 +5528,7 @@ internal static async Task PresignedGetObject_Test3(MinioClient minio)
55265528
"reqParams",
55275529
"response-content-type:application/json,response-content-disposition:attachment;filename= MyDoc u m e nt.json ;"
55285530
},
5529-
{ "reqDate", reqDate.ToString() }
5531+
{ "reqDate", reqDate.ToString(CultureInfo.InvariantCulture) }
55305532
};
55315533
try
55325534
{
@@ -5562,7 +5564,7 @@ internal static async Task PresignedGetObject_Test3(MinioClient minio)
55625564

55635565
using var response = await minio.WrapperGetAsync(presigned_url).ConfigureAwait(false);
55645566
if (response.StatusCode != HttpStatusCode.OK || string.IsNullOrEmpty(Convert.ToString(response.Content)))
5565-
throw new ArgumentNullException(nameof(response.Content), "Unable to download via presigned URL");
5567+
throw new InvalidOperationException("Unable to download via presigned URL " + nameof(response.Content));
55665568

55675569
Assert.IsTrue(response.Content.Headers.GetValues("Content-Type")
55685570
.Contains(reqParams["response-content-type"], StringComparer.Ordinal));

Minio.Functional.Tests/JsonNetLogger.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
using System.Text.Json;
1818
using Minio.DataModel.Tracing;
19+
using Minio.Handlers;
1920

2021
namespace Minio.Functional.Tests;
2122

Minio.Functional.Tests/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
using System.Collections.Concurrent;
19+
using System.Diagnostics.CodeAnalysis;
1920
using System.Globalization;
2021
using System.Net;
2122
using Minio.Helper;
@@ -24,6 +25,7 @@ namespace Minio.Functional.Tests;
2425

2526
internal static class Program
2627
{
28+
[SuppressMessage("Design", "MA0051:Method is too long", Justification = "Needs to run all tests")]
2729
public static async Task Main(string[] args)
2830
{
2931
string endPoint = null;
@@ -40,7 +42,7 @@ public static async Task Main(string[] args)
4042
var posColon = endPoint.LastIndexOf(':');
4143
if (posColon != -1)
4244
{
43-
port = int.Parse(endPoint.Substring(posColon + 1, endPoint.Length - posColon - 1), NumberStyles.Integer,
45+
port = int.Parse(endPoint.AsSpan(posColon + 1, endPoint.Length - posColon - 1), NumberStyles.Integer,
4446
CultureInfo.InvariantCulture);
4547
endPoint = endPoint[..posColon];
4648
}
@@ -110,7 +112,7 @@ public static async Task Main(string[] args)
110112
// If the following test is run against AWS, then the SDK throws
111113
// "Listening for bucket notification is specific only to `minio`
112114
// server endpoints".
113-
await FunctionalTest.ListenBucketNotificationsAsync_Test1(minioClient);
115+
await FunctionalTest.ListenBucketNotificationsAsync_Test1(minioClient).ConfigureAwait(false);
114116
functionalTestTasks.Add(FunctionalTest.ListenBucketNotificationsAsync_Test2(minioClient));
115117
functionalTestTasks.Add(FunctionalTest.ListenBucketNotificationsAsync_Test3(minioClient));
116118

Minio.Tests/RegionTest.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
using Microsoft.VisualStudio.TestTools.UnitTesting;
18+
using Minio.Helper;
1819

1920
namespace Minio.Tests;
2021

@@ -37,6 +38,6 @@ public class RegionTest
3738
[DataRow("localhost:9000", "")]
3839
public void TestGetRegion(string endpoint, string expectedRegion)
3940
{
40-
Assert.AreEqual(expectedRegion, Regions.GetRegionFromEndpoint(endpoint));
41+
Assert.AreEqual(expectedRegion, RegionHelper.GetRegionFromEndpoint(endpoint));
4142
}
4243
}

0 commit comments

Comments
 (0)