@@ -239,17 +239,14 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_CachedAuthority_
239239 [ Fact ]
240240 public async Task AzureReposProvider_GetCredentialAsync_JwtMode_CachedAuthority_DevAzureUrlOrgName_ReturnsCredential ( )
241241 {
242-
243242 var input = new InputArguments ( new Dictionary < string , string >
244243 {
245244 [ "protocol" ] = "https" ,
246245 [ "host" ] = "dev.azure.com" ,
247- [ "path" ] = "org/project/_git/repo" ,
248246 [ "username" ] = "org"
249247 } ) ;
250248
251249 var expectedOrgUri = new Uri ( "https://dev.azure.com/org" ) ;
252- var remoteUri = new Uri ( "https://dev.azure.com/org/project/_git/repo" ) ;
253250 var authorityUrl = "https://login.microsoftonline.com/common" ;
254251 var expectedClientId = AzureDevOpsConstants . AadClientId ;
255252 var expectedRedirectUri = AzureDevOpsConstants . AadRedirectUri ;
@@ -385,7 +382,6 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_CachedAuthority_
385382 [ Fact ]
386383 public async Task AzureReposProvider_GetCredentialAsync_JwtMode_NoCachedAuthority_NoUser_ReturnsCredential ( )
387384 {
388-
389385 var input = new InputArguments ( new Dictionary < string , string >
390386 {
391387 [ "protocol" ] = "https" ,
@@ -433,9 +429,52 @@ public async Task AzureReposProvider_GetCredentialAsync_JwtMode_NoCachedAuthorit
433429 }
434430
435431 [ Fact ]
436- public async Task AzureReposProvider_GetCredentialAsync_PatMode_NoExistingPat_GeneratesCredential ( )
432+ public async Task AzureReposProvider_GetCredentialAsync_PatMode_OrgInUserName_NoExistingPat_GeneratesCredential ( )
437433 {
434+ var input = new InputArguments ( new Dictionary < string , string >
435+ {
436+ [ "protocol" ] = "https" ,
437+ [ "host" ] = "dev.azure.com" ,
438+ [ "username" ] = "org"
439+ } ) ;
440+
441+ var expectedOrgUri = new Uri ( "https://dev.azure.com/org" ) ;
442+ var authorityUrl = "https://login.microsoftonline.com/common" ;
443+ var expectedClientId = AzureDevOpsConstants . AadClientId ;
444+ var expectedRedirectUri = AzureDevOpsConstants . AadRedirectUri ;
445+ var expectedScopes = AzureDevOpsConstants . AzureDevOpsDefaultScopes ;
446+ var accessToken = "ACCESS-TOKEN" ;
447+ var personalAccessToken = "PERSONAL-ACCESS-TOKEN" ;
448+ var account = "john.doe" ;
449+ var authResult = CreateAuthResult ( account , accessToken ) ;
450+
451+ var context = new TestCommandContext ( ) ;
452+
453+ var azDevOpsMock = new Mock < IAzureDevOpsRestApi > ( MockBehavior . Strict ) ;
454+ azDevOpsMock . Setup ( x => x . GetAuthorityAsync ( expectedOrgUri ) ) . ReturnsAsync ( authorityUrl ) ;
455+ azDevOpsMock . Setup ( x => x . CreatePersonalAccessTokenAsync ( expectedOrgUri , accessToken , It . IsAny < IEnumerable < string > > ( ) ) )
456+ . ReturnsAsync ( personalAccessToken ) ;
457+
458+ var msAuthMock = new Mock < IMicrosoftAuthentication > ( MockBehavior . Strict ) ;
459+ msAuthMock . Setup ( x => x . GetTokenForUserAsync ( authorityUrl , expectedClientId , expectedRedirectUri , expectedScopes , null , true ) )
460+ . ReturnsAsync ( authResult ) ;
461+
462+ var authorityCacheMock = new Mock < IAzureDevOpsAuthorityCache > ( MockBehavior . Strict ) ;
463+
464+ var userMgrMock = new Mock < IAzureReposBindingManager > ( MockBehavior . Strict ) ;
438465
466+ var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object , authorityCacheMock . Object , userMgrMock . Object ) ;
467+
468+ ICredential credential = await provider . GetCredentialAsync ( input ) ;
469+
470+ Assert . NotNull ( credential ) ;
471+ Assert . Equal ( account , credential . Account ) ;
472+ Assert . Equal ( personalAccessToken , credential . Password ) ;
473+ }
474+
475+ [ Fact ]
476+ public async Task AzureReposProvider_GetCredentialAsync_PatMode_NoExistingPat_GeneratesCredential ( )
477+ {
439478 var input = new InputArguments ( new Dictionary < string , string >
440479 {
441480 [ "protocol" ] = "https" ,
0 commit comments