@@ -33,8 +33,10 @@ namespace AWS.Lambda.Powertools.Idempotency.Tests.Internal;
3333[ Collection ( "Sequential" ) ]
3434public class IdempotentAspectTests : IDisposable
3535{
36- [ Fact ]
37- public async Task Handle_WhenFirstCall_ShouldPutInStore ( )
36+ [ Theory ]
37+ [ InlineData ( typeof ( IdempotencyEnabledFunction ) ) ]
38+ [ InlineData ( typeof ( IdempotencyEnabledSyncFunction ) ) ]
39+ public async Task Handle_WhenFirstCall_ShouldPutInStore ( Type type )
3840 {
3941 //Arrange
4042 var store = new Mock < BasePersistenceStore > ( ) ;
@@ -44,11 +46,11 @@ public async Task Handle_WhenFirstCall_ShouldPutInStore()
4446 . WithOptions ( optionsBuilder => optionsBuilder . WithEventKeyJmesPath ( "Id" ) )
4547 ) ;
4648
47- var function = new IdempotencyEnabledFunction ( ) ;
49+ var function = Activator . CreateInstance ( type ) as IIdempotencyEnabledFunction ;
4850 var product = new Product ( 42 , "fake product" , 12 ) ;
4951
5052 //Act
51- var basket = await function . Handle ( product , new TestLambdaContext ( ) ) ;
53+ var basket = await function ! . HandleTest ( product , new TestLambdaContext ( ) ) ;
5254
5355 //Assert
5456 basket . Products . Count . Should ( ) . Be ( 1 ) ;
@@ -61,8 +63,10 @@ public async Task Handle_WhenFirstCall_ShouldPutInStore()
6163 . Verify ( x=> x . SaveSuccess ( It . IsAny < JsonDocument > ( ) , It . Is < Basket > ( y => y . Equals ( basket ) ) , It . IsAny < DateTimeOffset > ( ) ) ) ;
6264 }
6365
64- [ Fact ]
65- public async Task Handle_WhenSecondCall_AndNotExpired_ShouldGetFromStore ( )
66+ [ Theory ]
67+ [ InlineData ( typeof ( IdempotencyEnabledFunction ) ) ]
68+ [ InlineData ( typeof ( IdempotencyEnabledSyncFunction ) ) ]
69+ public async Task Handle_WhenSecondCall_AndNotExpired_ShouldGetFromStore ( Type type )
6670 {
6771 //Arrange
6872 var store = new Mock < BasePersistenceStore > ( ) ;
@@ -87,18 +91,20 @@ public async Task Handle_WhenSecondCall_AndNotExpired_ShouldGetFromStore()
8791 store . Setup ( x=> x . GetRecord ( It . IsAny < JsonDocument > ( ) , It . IsAny < DateTimeOffset > ( ) ) )
8892 . ReturnsAsync ( record ) ;
8993
90- var function = new IdempotencyEnabledFunction ( ) ;
94+ var function = Activator . CreateInstance ( type ) as IIdempotencyEnabledFunction ;
9195
9296 // Act
93- var resultBasket = await function . Handle ( product , new TestLambdaContext ( ) ) ;
97+ var resultBasket = await function ! . HandleTest ( product , new TestLambdaContext ( ) ) ;
9498
9599 // Assert
96100 resultBasket . Should ( ) . Be ( basket ) ;
97101 function . HandlerExecuted . Should ( ) . BeFalse ( ) ;
98102 }
99103
100- [ Fact ]
101- public async Task Handle_WhenSecondCall_AndStatusInProgress_ShouldThrowIdempotencyAlreadyInProgressException ( )
104+ [ Theory ]
105+ [ InlineData ( typeof ( IdempotencyEnabledFunction ) ) ]
106+ [ InlineData ( typeof ( IdempotencyEnabledSyncFunction ) ) ]
107+ public async Task Handle_WhenSecondCall_AndStatusInProgress_ShouldThrowIdempotencyAlreadyInProgressException ( Type type )
102108 {
103109 // Arrange
104110 var store = new Mock < BasePersistenceStore > ( ) ;
@@ -123,15 +129,17 @@ public async Task Handle_WhenSecondCall_AndStatusInProgress_ShouldThrowIdempoten
123129 . ReturnsAsync ( record ) ;
124130
125131 // Act
126- var function = new IdempotencyEnabledFunction ( ) ;
127- Func < Task > act = async ( ) => await function . Handle ( product , new TestLambdaContext ( ) ) ;
132+ var function = Activator . CreateInstance ( type ) as IIdempotencyEnabledFunction ;
133+ Func < Task > act = async ( ) => await function ! . HandleTest ( product , new TestLambdaContext ( ) ) ;
128134
129135 // Assert
130136 await act . Should ( ) . ThrowAsync < IdempotencyAlreadyInProgressException > ( ) ;
131137 }
132138
133- [ Fact ]
134- public async Task Handle_WhenThrowException_ShouldDeleteRecord_AndThrowFunctionException ( )
139+ [ Theory ]
140+ [ InlineData ( typeof ( IdempotencyWithErrorFunction ) ) ]
141+ [ InlineData ( typeof ( IdempotencyWithErrorSyncFunction ) ) ]
142+ public async Task Handle_WhenThrowException_ShouldDeleteRecord_AndThrowFunctionException ( Type type )
135143 {
136144 // Arrange
137145 var store = new Mock < BasePersistenceStore > ( ) ;
@@ -142,20 +150,22 @@ public async Task Handle_WhenThrowException_ShouldDeleteRecord_AndThrowFunctionE
142150 . WithOptions ( optionsBuilder => optionsBuilder . WithEventKeyJmesPath ( "Id" ) )
143151 ) ;
144152
145- var function = new IdempotencyWithErrorFunction ( ) ;
153+ var function = Activator . CreateInstance ( type ) as IIdempotencyWithErrorFunction ;
146154 var product = new Product ( 42 , "fake product" , 12 ) ;
147155
148156 // Act
149- Func < Task > act = async ( ) => await function . Handle ( product , new TestLambdaContext ( ) ) ;
157+ Func < Task > act = async ( ) => await function ! . HandleTest ( product , new TestLambdaContext ( ) ) ;
150158
151159 // Assert
152160 await act . Should ( ) . ThrowAsync < IndexOutOfRangeException > ( ) ;
153161 store . Verify (
154162 x => x . DeleteRecord ( It . IsAny < JsonDocument > ( ) , It . IsAny < IndexOutOfRangeException > ( ) ) ) ;
155163 }
156164
157- [ Fact ]
158- public async Task Handle_WhenIdempotencyDisabled_ShouldJustRunTheFunction ( )
165+ [ Theory ]
166+ [ InlineData ( typeof ( IdempotencyEnabledFunction ) ) ]
167+ [ InlineData ( typeof ( IdempotencyEnabledSyncFunction ) ) ]
168+ public async Task Handle_WhenIdempotencyDisabled_ShouldJustRunTheFunction ( Type type )
159169 {
160170
161171 // Arrange
@@ -169,18 +179,18 @@ public async Task Handle_WhenIdempotencyDisabled_ShouldJustRunTheFunction()
169179 . WithOptions ( optionsBuilder => optionsBuilder . WithEventKeyJmesPath ( "Id" ) )
170180 ) ;
171181
172- var function = new IdempotencyEnabledFunction ( ) ;
182+ var function = Activator . CreateInstance ( type ) as IIdempotencyEnabledFunction ;
173183 var product = new Product ( 42 , "fake product" , 12 ) ;
174184
175185 // Act
176- var basket = await function . Handle ( product , new TestLambdaContext ( ) ) ;
186+ var basket = await function ! . HandleTest ( product , new TestLambdaContext ( ) ) ;
177187
178188 // Assert
179189 store . Invocations . Count . Should ( ) . Be ( 0 ) ;
180190 basket . Products . Count . Should ( ) . Be ( 1 ) ;
181191 function . HandlerExecuted . Should ( ) . BeTrue ( ) ;
182192 }
183-
193+
184194 [ Fact ]
185195 public void Idempotency_Set_Execution_Environment_Context ( )
186196 {
0 commit comments