@@ -90,7 +90,7 @@ public async Task GetEntityAsync_ThenInclude_NotNullAsync()
90
90
}
91
91
92
92
[ Fact ]
93
- public async Task SaveEntitiesAsync_CallBeforeUpdateForRelatedEntityAsync ( )
93
+ public async Task SaveEntitiesAsync_CallBeforeUpdateForRelatedEntity_UpdateDateUpdatedAsync ( )
94
94
{
95
95
// Arrange
96
96
var entity = new EntityGenerator < FakeBlog > ( new FakeBlog ( ) )
@@ -118,7 +118,7 @@ public async Task SaveEntitiesAsync_CallBeforeUpdateForRelatedEntityAsync()
118
118
}
119
119
120
120
[ Fact ]
121
- public async Task SaveEntitiesAsync_DispatchEntityDomainEventsAsync ( )
121
+ public async Task SaveEntitiesAsync_DispatchEntityDomainEvents_DispatchAllAsync ( )
122
122
{
123
123
// Arrange
124
124
var entity = new EntityGenerator < FakeBlog > ( new FakeBlog ( ) )
@@ -156,7 +156,7 @@ public async Task SaveEntitiesAsync_DispatchEntityDomainEventsAsync()
156
156
}
157
157
158
158
[ Fact ]
159
- public async Task SaveEntitiesAsync_DispatchRelatedEntityDomainEventsAsync ( )
159
+ public async Task SaveEntitiesAsync_DispatchRelatedEntityDomainEvents_DispatchAllAsync ( )
160
160
{
161
161
// Arrange
162
162
var entity = new EntityGenerator < FakeBlog > ( new FakeBlog ( ) )
@@ -195,7 +195,7 @@ public async Task SaveEntitiesAsync_DispatchRelatedEntityDomainEventsAsync()
195
195
}
196
196
197
197
[ Fact ]
198
- public async Task SaveEntitiesAsync_DispatchEntityDomainEventsWithGeneratedIdAsync ( )
198
+ public async Task SaveEntitiesAsync_DispatchEntityDomainEventsWithGeneratedId_DispatchAllAsync ( )
199
199
{
200
200
// Arrange
201
201
var entity = new EntityGenerator < FakeBlog > ( new FakeBlog ( ) )
@@ -228,4 +228,44 @@ public async Task SaveEntitiesAsync_DispatchEntityDomainEventsWithGeneratedIdAsy
228
228
It . IsAny < CancellationToken > ( ) ) ,
229
229
Times . Exactly ( entity . Posts . Count ) ) ;
230
230
}
231
+
232
+ [ Fact ]
233
+ public async Task SaveEntitiesAsync_DispatchEntityDomainEventsWithMultipleExceptions_ThrowAggregateExceptionsAsync ( )
234
+ {
235
+ // Arrange
236
+ var entity = new EntityGenerator < FakeBlog > ( new FakeBlog ( ) )
237
+ . Setup ( x => x . DateUpdated = DateTimeOffset . Now . AddDays ( - 1 ) )
238
+ . HasManyForEachEntity (
239
+ x => x . Posts ,
240
+ x => x . Blog ,
241
+ new EntityGenerator < FakePost > ( new FakePost ( ) ) . Setup (
242
+ x => x . DateUpdated = DateTimeOffset . Now . AddDays ( - 1 ) ) )
243
+ . GenerateSingle ( ) ;
244
+ var db = new FakeDbContext (
245
+ new DbContextOptionsBuilder < FakeDbContext > ( ) . UseInMemoryDatabase ( "inmemory" ) . Options ) ;
246
+ var mediator = new Mock < IMediator > ( ) ;
247
+ mediator . Setup ( x => x . Publish ( It . IsAny < IDomainEvent > ( ) , It . IsAny < CancellationToken > ( ) ) )
248
+ . Throws < ArgumentException > ( ) ;
249
+ var repository = new TestRepository ( mediator . Object , db ) ;
250
+
251
+ // Act
252
+ entity . AddDomainEvent ( id => new FakeDomainEvent ( id , 1 ) ) ;
253
+ entity . Posts . ForEach ( x => x . AddDomainEvent ( id => new FakeDomainEvent ( id , 2 ) ) ) ;
254
+ var act = async ( ) => await repository . AddAsync ( entity ) ;
255
+
256
+ // Assert
257
+ var eventCount = 1 + entity . Posts . Count ;
258
+ ( await act . Should ( ) . ThrowAsync < AggregateException > ( ) ) . And . InnerExceptions . Should ( )
259
+ . HaveCount ( eventCount ) ;
260
+ mediator . Verify (
261
+ x => x . Publish (
262
+ It . Is < IDomainEvent > ( d => ( ( FakeDomainEvent ) d ) . Id != 0 && ( ( FakeDomainEvent ) d ) . FakeValue == 1 ) ,
263
+ It . IsAny < CancellationToken > ( ) ) ,
264
+ Times . Once ) ;
265
+ mediator . Verify (
266
+ x => x . Publish (
267
+ It . Is < IDomainEvent > ( d => ( ( FakeDomainEvent ) d ) . Id != 0 && ( ( FakeDomainEvent ) d ) . FakeValue == 2 ) ,
268
+ It . IsAny < CancellationToken > ( ) ) ,
269
+ Times . Exactly ( entity . Posts . Count ) ) ;
270
+ }
231
271
}
0 commit comments