@@ -83,6 +83,9 @@ public static class FunctionalTest
8383 private const string listenBucketNotificationsSignature =
8484 "IObservable<MinioNotificationRaw> ListenBucketNotificationsAsync(ListenBucketNotificationsArgs args, CancellationToken cancellationToken = default(CancellationToken))" ;
8585
86+ private const string listenNotificationsSignature =
87+ "IObservable<MinioNotificationRaw> ListenNotificationsAsync(IList<EventType> events, CancellationToken cancellationToken = default(CancellationToken))" ;
88+
8689 private const string copyObjectSignature =
8790 "Task<CopyObjectResult> CopyObjectAsync(CopyObjectArgs args, CancellationToken cancellationToken = default(CancellationToken))" ;
8891
@@ -1034,6 +1037,19 @@ internal static async Task<ObjectStat> PutObject_Tester(IMinioClient minio,
10341037 return statObject ;
10351038 }
10361039
1040+ internal static async Task < bool > CreateBucket_Tester ( IMinioClient minio , string bucketName )
1041+ {
1042+ // Create a new bucket
1043+ await minio . MakeBucketAsync ( new MakeBucketArgs ( ) . WithBucket ( bucketName ) ) . ConfigureAwait ( false ) ;
1044+
1045+ // Verify the bucket exists
1046+ var bucketExists = await minio . BucketExistsAsync ( new BucketExistsArgs ( ) . WithBucket ( bucketName ) )
1047+ . ConfigureAwait ( false ) ;
1048+ Assert . IsTrue ( bucketExists , $ "Bucket { bucketName } was not created successfully.") ;
1049+
1050+ return bucketExists ;
1051+ }
1052+
10371053 internal static async Task StatObject_Test1 ( IMinioClient minio )
10381054 {
10391055 var startTime = DateTime . Now ;
@@ -2621,6 +2637,84 @@ await ListObjects_Test(minio, bucketName, singleObjectName, 1, headers: extractH
26212637 }
26222638 }
26232639
2640+ #region Global Notifications
2641+
2642+ internal static async Task ListenNotificationsAsync_Test1 ( IMinioClient minio )
2643+ {
2644+ var startTime = DateTime . Now ;
2645+ var bucketName = GetRandomName ( 15 ) ;
2646+ var args = new Dictionary < string , string >
2647+ ( StringComparer . Ordinal ) { { "bucketName" , bucketName } } ;
2648+ try
2649+ {
2650+ var received = new List < MinioNotificationRaw > ( ) ;
2651+
2652+ var eventsList = new List < EventType > { EventType . BucketCreatedAll } ;
2653+
2654+ var events = minio . ListenNotificationsAsync ( eventsList ) ;
2655+ var subscription = events . Subscribe (
2656+ received . Add ,
2657+ ex => Console . WriteLine ( $ "OnError: { ex } ") ,
2658+ ( ) => Console . WriteLine ( "Stopped listening for bucket notifications\n " ) ) ;
2659+
2660+ // Ensure the subscription is established
2661+ await Task . Delay ( 1000 ) . ConfigureAwait ( false ) ;
2662+
2663+ // Trigger the event by creating a new bucket
2664+ var isBucketCreated1 = await CreateBucket_Tester ( minio , bucketName ) . ConfigureAwait ( false ) ;
2665+
2666+ var eventDetected = false ;
2667+ for ( var attempt = 0 ; attempt < 20 ; attempt ++ )
2668+ {
2669+ if ( received . Count > 0 )
2670+ {
2671+ var notification = JsonSerializer . Deserialize < MinioNotification > ( received [ 0 ] . Json ) ;
2672+
2673+ if ( notification . Records is not null )
2674+ {
2675+ Assert . AreEqual ( 1 , notification . Records . Count ) ;
2676+ eventDetected = true ;
2677+ break ;
2678+ }
2679+ }
2680+
2681+ await Task . Delay ( 500 ) . ConfigureAwait ( false ) ; // Delay between attempts
2682+ }
2683+
2684+ subscription . Dispose ( ) ;
2685+ if ( ! eventDetected )
2686+ throw new UnexpectedMinioException ( "Failed to detect the expected bucket notification event." ) ;
2687+
2688+ new MintLogger ( nameof ( ListenNotificationsAsync_Test1 ) ,
2689+ listenNotificationsSignature ,
2690+ "Tests whether ListenNotifications passes" ,
2691+ TestStatus . PASS , DateTime . Now - startTime , args : args ) . Log ( ) ;
2692+ }
2693+ catch ( NotImplementedException ex )
2694+ {
2695+ new MintLogger ( nameof ( ListenNotificationsAsync_Test1 ) ,
2696+ listenNotificationsSignature ,
2697+ "Tests whether ListenNotifications passes" ,
2698+ TestStatus . NA , DateTime . Now - startTime , ex . Message ,
2699+ ex . ToString ( ) , args : args ) . Log ( ) ;
2700+ }
2701+ catch ( Exception ex )
2702+ {
2703+ new MintLogger ( nameof ( ListenNotificationsAsync_Test1 ) ,
2704+ listenNotificationsSignature ,
2705+ "Tests whether ListenNotifications passes" ,
2706+ TestStatus . FAIL , DateTime . Now - startTime , ex . Message ,
2707+ ex . ToString ( ) , args : args ) . Log ( ) ;
2708+ throw ;
2709+ }
2710+ finally
2711+ {
2712+ await TearDown ( minio , bucketName ) . ConfigureAwait ( false ) ;
2713+ }
2714+ }
2715+
2716+ #endregion
2717+
26242718 #region Bucket Notifications
26252719
26262720 internal static async Task ListenBucketNotificationsAsync_Test1 ( IMinioClient minio )
@@ -2655,6 +2749,7 @@ internal static async Task ListenBucketNotificationsAsync_Test1(IMinioClient min
26552749 ( ) => { }
26562750 ) ;
26572751
2752+
26582753 _ = await PutObject_Tester ( minio , bucketName , objectName , null , contentType ,
26592754 0 , null , rsg . GenerateStreamFromSeed ( 1 * KB ) ) . ConfigureAwait ( false ) ;
26602755
0 commit comments