@@ -1642,6 +1642,60 @@ public async Task GivenValidRequest_ItRemovesCredAndSendsNotificationToUser()
16421642 GetMock < IMessageService > ( ) . VerifyAll ( ) ;
16431643 }
16441644
1645+ [ Theory ]
1646+ [ MemberData ( nameof ( GivenValidRequest_ItRemovesAPIKeyWithDifferentScopesAndSendsCorrectMessageToUser_Input ) ) ]
1647+ public async Task GivenValidRequest_ItRemovesAPIKeyWithDifferentScopesAndSendsCorrectMessageToUser ( ICollection < Scope > scopes , string expectedDescription )
1648+ {
1649+ // Arrange
1650+ var fakes = Get < Fakes > ( ) ;
1651+ var apiKey = new CredentialBuilder ( ) . CreateApiKey ( TimeSpan . FromHours ( 1 ) , out string plaintextApiKey ) ;
1652+ apiKey . Description = "theApiKey" ;
1653+ apiKey . Scopes = scopes ;
1654+ apiKey . Expires -= TimeSpan . FromDays ( 1 ) ;
1655+
1656+ var user = fakes . CreateUser ( "test" , apiKey ) ;
1657+ var cred = user . Credentials . First ( ) ;
1658+ cred . Key = CredentialKey ;
1659+
1660+ var controller = GetController < UsersController > ( ) ;
1661+ controller . SetCurrentUser ( user ) ;
1662+
1663+ // Act
1664+ var result = await controller . RemoveCredential (
1665+ credentialType : apiKey . Type ,
1666+ credentialKey : CredentialKey ) ;
1667+
1668+ // Assert
1669+ GetMock < IMessageService > ( )
1670+ . Verify ( m =>
1671+ m . SendCredentialRemovedNoticeAsync (
1672+ user ,
1673+ It . Is < CredentialViewModel > ( c => c . Description == expectedDescription ) ) ) ;
1674+ }
1675+
1676+ public static IEnumerable < object [ ] > GivenValidRequest_ItRemovesAPIKeyWithDifferentScopesAndSendsCorrectMessageToUser_Input
1677+ {
1678+ get
1679+ {
1680+ return new [ ]
1681+ {
1682+ new object [ ]
1683+ {
1684+ new [ ]
1685+ {
1686+ new Scope ( "*" , NuGetScopes . All )
1687+ } ,
1688+ "theApiKey" ,
1689+ } ,
1690+ new object [ ]
1691+ {
1692+ new Scope [ 0 ] { } ,
1693+ Strings . NonScopedApiKeyDescription
1694+ }
1695+ } ;
1696+ }
1697+ }
1698+
16451699 [ Fact ]
16461700 public async Task GivenValidRequest_CanDeleteMicrosoftAccountWithMultipleMicrosoftAccounts ( )
16471701 {
0 commit comments