@@ -141,6 +141,8 @@ await deleteAccountService.DeleteAccountAsync(
141141 Assert . NotEmpty ( testUser . OrganizationMigrationRequests ) ;
142142 Assert . NotEmpty ( testUser . OrganizationRequests ) ;
143143 Assert . NotEmpty ( testUser . Organizations ) ;
144+ Assert . NotNull ( testableService . PackageDeletedByUser . DeletedBy ) ;
145+ Assert . NotNull ( testableService . AccountDeletedByUser . DeletedBy ) ;
144146 }
145147 else
146148 {
@@ -159,6 +161,8 @@ await deleteAccountService.DeleteAccountAsync(
159161 Assert . Null ( testUser . OrganizationMigrationRequest ) ;
160162 Assert . Empty ( testUser . OrganizationMigrationRequests ) ;
161163 Assert . Empty ( testUser . OrganizationRequests ) ;
164+ Assert . Null ( testableService . PackageDeletedByUser . DeletedBy ) ;
165+ Assert . Null ( testableService . AccountDeletedByUser . DeletedBy ) ;
162166
163167 Assert . Empty ( testUser . Organizations ) ;
164168 foreach ( var testUserOrganization in testUserOrganizations )
@@ -185,6 +189,9 @@ await deleteAccountService.DeleteAccountAsync(
185189 // In production, they would not be deleted because the transaction they were deleted in would fail.
186190 Assert . Single ( testableService . SupportRequests ) ;
187191 Assert . Empty ( testUser . ReservedNamespaces ) ;
192+
193+ Assert . NotNull ( testableService . PackageDeletedByDifferentUser . DeletedBy ) ;
194+ Assert . NotNull ( testableService . AccountDeletedByDifferentUser . DeletedBy ) ;
188195 }
189196
190197 [ Theory ]
@@ -270,6 +277,8 @@ public async Task DeleteOrganization(bool isPackageOrphaned, AccountDeletionOrph
270277 Assert . Empty ( testableService . AuditService . Records ) ;
271278 Assert . False ( testableService . HasDeletedOwnerScope ) ;
272279 Assert . Empty ( testableService . AuditService . Records ) ;
280+ Assert . NotNull ( testableService . PackageDeletedByUser . DeletedBy ) ;
281+ Assert . NotNull ( testableService . AccountDeletedByUser . DeletedBy ) ;
273282 }
274283 else
275284 {
@@ -286,6 +295,8 @@ public async Task DeleteOrganization(bool isPackageOrphaned, AccountDeletionOrph
286295 Assert . Empty ( testableService . PackageOwnerRequests ) ;
287296 Assert . Single ( testableService . AuditService . Records ) ;
288297 Assert . True ( testableService . HasDeletedOwnerScope ) ;
298+ Assert . Null ( testableService . PackageDeletedByUser . DeletedBy ) ;
299+ Assert . Null ( testableService . AccountDeletedByUser . DeletedBy ) ;
289300
290301 var deleteRecord = testableService . AuditService . Records [ 0 ] as DeleteAccountAuditRecord ;
291302 Assert . True ( deleteRecord != null ) ;
@@ -296,6 +307,9 @@ public async Task DeleteOrganization(bool isPackageOrphaned, AccountDeletionOrph
296307 // In production, they would not be deleted because the transaction they were deleted in would fail.
297308 Assert . Empty ( organization . ReservedNamespaces ) ;
298309 Assert . Single ( testableService . SupportRequests ) ;
310+
311+ Assert . NotNull ( testableService . PackageDeletedByDifferentUser . DeletedBy ) ;
312+ Assert . NotNull ( testableService . AccountDeletedByDifferentUser . DeletedBy ) ;
299313 }
300314
301315 [ Theory ]
@@ -473,7 +487,7 @@ public class DeleteAccountTestService
473487 private PackageRegistration _userPackagesRegistration = null ;
474488 private ICollection < Package > _userPackages ;
475489 private bool _hasDeletedCredentialWithOwnerScope = false ;
476-
490+
477491 public List < AccountDelete > DeletedAccounts = new List < AccountDelete > ( ) ;
478492 public List < User > DeletedUsers = new List < User > ( ) ;
479493 public List < Issue > SupportRequests = new List < Issue > ( ) ;
@@ -483,6 +497,12 @@ public class DeleteAccountTestService
483497 public FakeAuditingService AuditService = new FakeAuditingService ( ) ;
484498 public bool HasDeletedOwnerScope => _hasDeletedCredentialWithOwnerScope ;
485499
500+ public AccountDelete AccountDeletedByUser { get ; }
501+ public AccountDelete AccountDeletedByDifferentUser { get ; }
502+ public PackageDelete PackageDeletedByUser { get ; }
503+ public PackageDelete PackageDeletedByDifferentUser { get ; }
504+
505+
486506 public DeleteAccountTestService ( User user )
487507 {
488508 _user = user ;
@@ -533,6 +553,11 @@ public DeleteAccountTestService(User user, PackageRegistration userPackagesRegis
533553 NewOwner = _user
534554 } ) ;
535555
556+ AccountDeletedByUser = new AccountDelete { DeletedBy = _user , DeletedByKey = _user . Key } ;
557+ AccountDeletedByDifferentUser = new AccountDelete { DeletedBy = new User { Key = 1111 } , DeletedByKey = 1111 } ;
558+ PackageDeletedByUser = new PackageDelete { DeletedBy = _user , DeletedByKey = _user . Key } ;
559+ PackageDeletedByDifferentUser = new PackageDelete { DeletedBy = new User { Key = 1111 } , DeletedByKey = 1111 } ;
560+
536561 PackagePushedByUser = new Package
537562 {
538563 User = _user ,
@@ -554,6 +579,7 @@ public DeleteAccountService GetDeleteAccountService(bool isPackageOrphaned, bool
554579 {
555580 return new DeleteAccountService (
556581 SetupAccountDeleteRepository ( ) . Object ,
582+ SetupPackageDeleteRepository ( ) . Object ,
557583 SetupDeprecationRepository ( ) . Object ,
558584 SetupUserRepository ( ) . Object ,
559585 SetupScopeRepository ( ) . Object ,
@@ -639,13 +665,35 @@ private Mock<ISecurityPolicyService> SetupSecurityPolicyService()
639665 private Mock < IEntityRepository < AccountDelete > > SetupAccountDeleteRepository ( )
640666 {
641667 var accountDeleteRepository = new Mock < IEntityRepository < AccountDelete > > ( ) ;
668+
669+ if ( AccountDeletedByUser != null )
670+ {
671+ accountDeleteRepository
672+ . Setup ( m => m . GetAll ( ) )
673+ . Returns ( new [ ] { AccountDeletedByUser , AccountDeletedByDifferentUser } . AsQueryable ( ) ) ;
674+ }
675+
642676 accountDeleteRepository
643677 . Setup ( m => m . InsertOnCommit ( It . IsAny < AccountDelete > ( ) ) )
644678 . Callback < AccountDelete > ( account => DeletedAccounts . Add ( account ) ) ;
645679
646680 return accountDeleteRepository ;
647681 }
648682
683+ private Mock < IEntityRepository < PackageDelete > > SetupPackageDeleteRepository ( )
684+ {
685+ var packageDeleteRepository = new Mock < IEntityRepository < PackageDelete > > ( ) ;
686+
687+ if ( PackageDeletedByUser != null )
688+ {
689+ packageDeleteRepository
690+ . Setup ( m => m . GetAll ( ) )
691+ . Returns ( new [ ] { PackageDeletedByUser , PackageDeletedByDifferentUser } . AsQueryable ( ) ) ;
692+ }
693+
694+ return packageDeleteRepository ;
695+ }
696+
649697 private Mock < IEntityRepository < PackageDeprecation > > SetupDeprecationRepository ( )
650698 {
651699 var deprecationRepository = new Mock < IEntityRepository < PackageDeprecation > > ( ) ;
0 commit comments