@@ -298,4 +298,65 @@ private async Task<string> HandlerWithProtobufKeys(ConsumerRecords<ProtobufKey,
298298
299299 return "Successfully processed Protobuf Kafka events with complex keys" ;
300300 }
301+
302+ [ Fact ]
303+ public void SimpleHandlerTest ( )
304+ {
305+ string Handler ( ConsumerRecords < int , ProtobufProduct > records , ILambdaContext context )
306+ {
307+ foreach ( var record in records )
308+ {
309+ var product = record . Value ;
310+ context . Logger . LogInformation ( $ "Processing { product . Name } at ${ product . Price } ") ;
311+ }
312+
313+ return "Successfully processed Protobuf Kafka events" ;
314+ }
315+ // Simulate the handler execution
316+ var mockLogger = new TestLambdaLogger ( ) ;
317+ var mockContext = new TestLambdaContext
318+ {
319+ Logger = mockLogger
320+ } ;
321+
322+ var records = new ConsumerRecords < int , ProtobufProduct >
323+ {
324+ Records = new Dictionary < string , List < ConsumerRecord < int , ProtobufProduct > > >
325+ {
326+ { "mytopic-0" , new List < ConsumerRecord < int , ProtobufProduct > >
327+ {
328+ new ( )
329+ {
330+ Topic = "mytopic" ,
331+ Partition = 0 ,
332+ Offset = 15 ,
333+ Key = 42 ,
334+ Value = new ProtobufProduct { Name = "Test Product" , Id = 1 , Price = 99.99 }
335+ }
336+ }
337+ }
338+ }
339+ } ;
340+
341+ // Call the handler
342+ var result = Handler ( records , mockContext ) ;
343+
344+ // Assert the result
345+ Assert . Equal ( "Successfully processed Protobuf Kafka events" , result ) ;
346+
347+ // Verify the context logger output
348+ Assert . Contains ( "Processing Test Product at $99.99" , mockLogger . Buffer . ToString ( ) ) ;
349+
350+ // Verify the records were processed
351+ Assert . Single ( records . Records ) ;
352+ Assert . Contains ( "mytopic-0" , records . Records . Keys ) ;
353+ Assert . Single ( records . Records [ "mytopic-0" ] ) ;
354+ Assert . Equal ( "mytopic" , records . Records [ "mytopic-0" ] [ 0 ] . Topic ) ;
355+ Assert . Equal ( 0 , records . Records [ "mytopic-0" ] [ 0 ] . Partition ) ;
356+ Assert . Equal ( 15 , records . Records [ "mytopic-0" ] [ 0 ] . Offset ) ;
357+ Assert . Equal ( 42 , records . Records [ "mytopic-0" ] [ 0 ] . Key ) ;
358+ Assert . Equal ( "Test Product" , records . Records [ "mytopic-0" ] [ 0 ] . Value . Name ) ;
359+ Assert . Equal ( 1 , records . Records [ "mytopic-0" ] [ 0 ] . Value . Id ) ;
360+ Assert . Equal ( 99.99 , records . Records [ "mytopic-0" ] [ 0 ] . Value . Price ) ;
361+ }
301362}
0 commit comments