Skip to content

Commit 1f97ce3

Browse files
committed
more tests
1 parent d70cd6b commit 1f97ce3

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

libraries/tests/AWS.Lambda.Powertools.BatchProcessing.Tests/BatchProcessorAttributeValidationTests.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,4 +620,44 @@ public void BatchProcessorAttribute_CreateAspectHandler_WithErrorHandlingPolicyO
620620
// Assert - Should not throw, policy should be applied
621621
Assert.NotNull(handler);
622622
}
623+
624+
[Fact]
625+
public void BatchProcessorAttribute_CreateAspectHandler_WithNoHandlerProvided_ThrowsInvalidOperationException()
626+
{
627+
// Arrange - No handlers configured at all (neither traditional nor typed)
628+
var attribute = new BatchProcessorAttribute();
629+
var sqsEvent = new SQSEvent();
630+
631+
// Act & Assert
632+
var ex = Assert.Throws<InvalidOperationException>(() => attribute.CreateAspectHandler(new object[] { sqsEvent }));
633+
Assert.Contains("A record handler, record handler provider, typed record handler, or typed record handler provider is required", ex.Message);
634+
}
635+
636+
// Test class that uses reflection to directly test the CreateTypedBatchProcessingAspectHandler method
637+
[Fact]
638+
public void BatchProcessorAttribute_CreateTypedBatchProcessingAspectHandler_WithNoTypedHandlerProvided_ThrowsInvalidOperationException()
639+
{
640+
// Arrange - Create an attribute and use reflection to call the private method directly
641+
var attribute = new BatchProcessorAttribute();
642+
var sqsEvent = new SQSEvent();
643+
644+
// Use reflection to get the private method
645+
var method = typeof(BatchProcessorAttribute).GetMethod("CreateTypedBatchProcessingAspectHandler",
646+
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
647+
648+
// Create the generic method for SQSEvent and SQSMessage
649+
var genericMethod = method.MakeGenericMethod(typeof(SQSEvent), typeof(SQSEvent.SQSMessage));
650+
651+
// Create a lambda that returns a mock typed batch processor
652+
Func<ITypedBatchProcessor<SQSEvent, SQSEvent.SQSMessage>> mockProvider = () =>
653+
Substitute.For<ITypedBatchProcessor<SQSEvent, SQSEvent.SQSMessage>>();
654+
655+
// Act & Assert - Call the method with no typed handlers configured
656+
var ex = Assert.Throws<System.Reflection.TargetInvocationException>(() =>
657+
genericMethod.Invoke(attribute, new object[] { mockProvider, new object[] { sqsEvent } }));
658+
659+
// The actual exception is wrapped in TargetInvocationException
660+
Assert.IsType<InvalidOperationException>(ex.InnerException);
661+
Assert.Contains("A typed record handler or typed record handler provider is required", ex.InnerException.Message);
662+
}
623663
}

0 commit comments

Comments
 (0)