@@ -525,44 +525,58 @@ public void CaptureError_WithDifferentModes_ReturnsExpectedResult(TracingCapture
525
525
}
526
526
527
527
[ Fact ]
528
- public void CaptureResponse_WhenTracingIsDisabled_ReturnsFalseDirectly ( )
528
+ public async Task Around_AsyncMethodWithResult_HandlesTaskResultProperty ( )
529
529
{
530
530
// Arrange
531
- _mockConfigurations . TracingDisabled . Returns ( true ) ;
532
- var methodName = "TestMethod" ;
533
- var result = "test result" ;
534
- Func < object [ ] , object > target = _ => result ;
531
+ var attribute = new TracingAttribute ( ) ;
532
+ var methodName = "TestAsyncMethod" ;
533
+ var expectedResult = "test result" ;
534
+ var taskWithResult = Task . FromResult ( expectedResult ) ;
535
+ Func < object [ ] , object > target = _ => taskWithResult ;
535
536
536
537
// Act
537
- _handler . Around ( methodName , Array . Empty < object > ( ) , target , new Attribute [ ] { new TracingAttribute ( ) } ) ;
538
+ var taskResult = _handler . Around ( methodName , Array . Empty < object > ( ) , target , new Attribute [ ] { attribute } ) ;
538
539
539
- // Assert - No metadata should be added since we return false immediately
540
- _mockXRayRecorder . DidNotReceive ( ) . AddMetadata (
541
- Arg . Any < string > ( ) ,
542
- Arg . Any < string > ( ) ,
543
- Arg . Any < object > ( ) ) ;
540
+ // Wait for the async operation to complete
541
+ if ( taskResult is Task task )
542
+ {
543
+ await task ;
544
+ }
545
+
546
+ // Assert with wait
547
+ await Task . Delay ( 100 ) ; // Give time for the continuation to complete
548
+
549
+ _mockXRayRecorder . Received ( 1 ) . AddMetadata (
550
+ "TestService" , // This matches what's set in the test constructor
551
+ $ "{ methodName } response",
552
+ expectedResult ) ;
544
553
}
545
554
546
555
[ Fact ]
547
- public void CaptureError_WhenTracingIsDisabled_ReturnsFalseDirectly ( )
556
+ public async Task Around_AsyncMethodWithoutResult_HandlesNullTaskResultProperty ( )
548
557
{
549
558
// Arrange
550
- _mockConfigurations . TracingDisabled . Returns ( true ) ;
551
- var methodName = "TestMethod" ;
552
- var expectedException = new Exception ( "Test exception" ) ;
553
- Func < object [ ] , object > target = _ => throw expectedException ;
559
+ var attribute = new TracingAttribute ( ) ;
560
+ var methodName = "TestAsyncMethod" ;
561
+ var taskWithoutResult = new Task ( ( ) => { } ) ; // Task without Result property
562
+ taskWithoutResult . Start ( ) ;
563
+ Func < object [ ] , object > target = _ => taskWithoutResult ;
554
564
555
- // Act & Assert
556
- Assert . Throws < Exception > ( ( ) => _handler . Around (
557
- methodName ,
558
- Array . Empty < object > ( ) ,
559
- target ,
560
- new Attribute [ ] { new TracingAttribute ( ) } ) ) ;
565
+ // Act
566
+ var taskResult = _handler . Around ( methodName , Array . Empty < object > ( ) , target , new Attribute [ ] { attribute } ) ;
561
567
562
- // Verify no error metadata was added since we return false immediately
563
- _mockXRayRecorder . DidNotReceive ( ) . AddMetadata (
564
- Arg . Any < string > ( ) ,
565
- Arg . Any < string > ( ) ,
566
- Arg . Any < string > ( ) ) ;
568
+ // Wait for the async operation to complete
569
+ if ( taskResult is Task task )
570
+ {
571
+ await task ;
572
+ }
573
+
574
+ // Assert with wait
575
+ await Task . Delay ( 100 ) ; // Give time for the continuation to complete
576
+
577
+ _mockXRayRecorder . Received ( 1 ) . AddMetadata (
578
+ "TestService" ,
579
+ $ "{ methodName } response",
580
+ null ) ;
567
581
}
568
582
}
0 commit comments