@@ -159,6 +159,75 @@ public void TestCheckRequiredService(
159
159
Assert . AreEqual ( expectedTimer , ExecuteTimer ) ;
160
160
}
161
161
162
+ [ DataRow ( true , true , true , true , false , false ) ]
163
+ [ DataRow ( true , true , true , false , false , false ) ]
164
+ [ DataRow ( true , true , false , false , false , true ) ]
165
+ [ DataRow ( true , false , true , true , false , false ) ]
166
+ [ DataRow ( true , false , false , true , false , true ) ]
167
+ [ DataRow ( true , false , false , true , false , true ) ]
168
+ [ DataRow ( false , true , true , true , true , false ) ]
169
+ [ DataRow ( true , false , true , false , true , false ) ]
170
+ [ DataTestMethod ]
171
+ public async Task PublishAndUnitOfWorkAsync (
172
+ bool isAddEventBus ,
173
+ bool isAddIntegrationEventBus ,
174
+ bool isAddUnitOfWork ,
175
+ bool isLocalEvent ,
176
+ bool expectedThrowExceptionByPublish ,
177
+ bool expectedThrowExceptionByCommit )
178
+ {
179
+ IEventBus ? eventBus = isAddEventBus ? _eventBus . Object : null ;
180
+ IIntegrationEventBus ? integrationEventBus = isAddIntegrationEventBus ? _integrationEventBus . Object : null ;
181
+ var unitOfWorkMock = new Mock < IUnitOfWork > ( ) ;
182
+ IUnitOfWork ? unitOfWork = isAddUnitOfWork ? unitOfWorkMock . Object : null ;
183
+
184
+ var domainEventBus = new DomainEventBus ( eventBus , integrationEventBus , unitOfWork ) ;
185
+
186
+ if ( isLocalEvent )
187
+ {
188
+ var registerUserEvent = new RegisterUserEvent ( ) ;
189
+
190
+ if ( expectedThrowExceptionByPublish )
191
+ {
192
+ await Assert . ThrowsExceptionAsync < MasaArgumentException > ( ( ) => domainEventBus . PublishAsync ( registerUserEvent ) ) ;
193
+ }
194
+ else
195
+ {
196
+ await domainEventBus . PublishAsync ( registerUserEvent ) ;
197
+
198
+ _integrationEventBus . Verify ( bus => bus . PublishAsync ( It . IsAny < IIntegrationEvent > ( ) , default ) , Times . Never ) ;
199
+ _eventBus . Verify ( bus => bus . PublishAsync ( It . IsAny < IEvent > ( ) , default ) , Times . Once ) ;
200
+ }
201
+ }
202
+ else
203
+ {
204
+ var changeOrderStateIntegrationEvent = new ChangeOrderStateIntegrationEvent ( ) ;
205
+
206
+ if ( expectedThrowExceptionByPublish )
207
+ {
208
+ await Assert . ThrowsExceptionAsync < MasaArgumentException > ( ( )
209
+ => domainEventBus . PublishAsync ( changeOrderStateIntegrationEvent ) ) ;
210
+ }
211
+ else
212
+ {
213
+ await _domainEventBus . PublishAsync ( changeOrderStateIntegrationEvent ) ;
214
+
215
+ _integrationEventBus . Verify ( bus => bus . PublishAsync ( It . IsAny < IIntegrationEvent > ( ) , default ) , Times . Once ) ;
216
+ _eventBus . Verify ( bus => bus . PublishAsync ( It . IsAny < IEvent > ( ) , default ) , Times . Never ) ;
217
+ }
218
+ }
219
+
220
+ if ( expectedThrowExceptionByCommit )
221
+ {
222
+ await Assert . ThrowsExceptionAsync < MasaArgumentException > ( ( ) => domainEventBus . CommitAsync ( ) ) ;
223
+ }
224
+ else
225
+ {
226
+ await domainEventBus . CommitAsync ( ) ;
227
+ unitOfWorkMock . Verify ( uow => uow . CommitAsync ( default ) , Times . Once ) ;
228
+ }
229
+ }
230
+
162
231
private static ConcurrentQueue < IDomainEvent > GetEventQueue ( DomainEventBus domainEventBus )
163
232
{
164
233
var eventQueue = EventQueueFileInfo . GetValue ( domainEventBus ) as ConcurrentQueue < IDomainEvent > ;
0 commit comments