@@ -114,67 +114,7 @@ public void AzureReposProvider_IsSupported_NonAzureRepos_ReturnsFalse()
114
114
}
115
115
116
116
[ Fact ]
117
- public void AzureReposProvider_GetCredentialKey_AzureHost_ReturnsCorrectKey ( )
118
- {
119
- const string expectedKey = "https://dev.azure.com/org" ;
120
- var input = new InputArguments ( new Dictionary < string , string >
121
- {
122
- [ "protocol" ] = "https" ,
123
- [ "host" ] = "dev.azure.com" ,
124
- [ "path" ] = "org/proj/_git/repo" ,
125
- } ) ;
126
-
127
- var provider = new AzureReposHostProvider ( new TestCommandContext ( ) ) ;
128
- string actualKey = provider . GetCredentialKey ( input ) ;
129
- Assert . Equal ( expectedKey , actualKey ) ;
130
- }
131
-
132
- [ Fact ]
133
- public void AzureReposProvider_GetCredentialKey_AzureHost_MissingPath_UseUserAsOrg ( )
134
- {
135
- const string expectedKey = "https://dev.azure.com/userorg" ;
136
- var input = new InputArguments ( new Dictionary < string , string >
137
- {
138
- [ "protocol" ] = "https" ,
139
- [ "host" ] = "dev.azure.com" ,
140
- [ "username" ] = "userorg" ,
141
- } ) ;
142
-
143
- var provider = new AzureReposHostProvider ( new TestCommandContext ( ) ) ;
144
- string actualKey = provider . GetCredentialKey ( input ) ;
145
- Assert . Equal ( expectedKey , actualKey ) ;
146
- }
147
-
148
- [ Fact ]
149
- public void AzureReposProvider_GetCredentialKey_AzureHost_MissingPathAndUser_ThrowsException ( )
150
- {
151
- var input = new InputArguments ( new Dictionary < string , string >
152
- {
153
- [ "protocol" ] = "https" ,
154
- [ "host" ] = "dev.azure.com" ,
155
- } ) ;
156
-
157
- var provider = new AzureReposHostProvider ( new TestCommandContext ( ) ) ;
158
- Assert . Throws < InvalidOperationException > ( ( ) => provider . GetCredentialKey ( input ) ) ;
159
- }
160
-
161
- [ Fact ]
162
- public void AzureReposProvider_GetCredentialKey_VisualStudioHost_ReturnsCorrectKey ( )
163
- {
164
- const string expectedKey = "https://org.visualstudio.com/" ;
165
- var input = new InputArguments ( new Dictionary < string , string >
166
- {
167
- [ "protocol" ] = "https" ,
168
- [ "host" ] = "org.visualstudio.com" ,
169
- } ) ;
170
-
171
- var provider = new AzureReposHostProvider ( new TestCommandContext ( ) ) ;
172
- string actualKey = provider . GetCredentialKey ( input ) ;
173
- Assert . Equal ( expectedKey , actualKey ) ;
174
- }
175
-
176
- [ Fact ]
177
- public async Task AzureReposProvider_CreateCredentialAsync_UnencryptedHttp_ThrowsException ( )
117
+ public async Task AzureReposProvider_GetCredentialAsync_UnencryptedHttp_ThrowsException ( )
178
118
{
179
119
var input = new InputArguments ( new Dictionary < string , string >
180
120
{
@@ -189,11 +129,11 @@ public async Task AzureReposProvider_CreateCredentialAsync_UnencryptedHttp_Throw
189
129
190
130
var provider = new AzureReposHostProvider ( context , azDevOps , msAuth ) ;
191
131
192
- await Assert . ThrowsAsync < Exception > ( ( ) => provider . CreateCredentialAsync ( input ) ) ;
132
+ await Assert . ThrowsAsync < Exception > ( ( ) => provider . GetCredentialAsync ( input ) ) ;
193
133
}
194
134
195
135
[ Fact ]
196
- public async Task AzureReposProvider_CreateCredentialAsync_ReturnsCredential ( )
136
+ public async Task AzureReposProvider_GetCredentialAsync_ReturnsCredential ( )
197
137
{
198
138
var input = new InputArguments ( new Dictionary < string , string >
199
139
{
@@ -208,32 +148,27 @@ public async Task AzureReposProvider_CreateCredentialAsync_ReturnsCredential()
208
148
var expectedRedirectUri = AzureDevOpsConstants . AadRedirectUri ;
209
149
var expectedResource = AzureDevOpsConstants . AadResourceId ;
210
150
var accessToken = "ACCESS-TOKEN" ;
211
- var pat = "PERSONAL-ACCESS-TOKEN" ;
212
- IEnumerable < string > expectedPatScopes = new [ ]
213
- {
214
- AzureDevOpsConstants . PersonalAccessTokenScopes . ReposWrite ,
215
- AzureDevOpsConstants . PersonalAccessTokenScopes . ArtifactsRead
216
- } ;
151
+ var personalAccessToken = "PERSONAL-ACCESS-TOKEN" ;
217
152
218
153
var context = new TestCommandContext ( ) ;
219
154
220
155
var azDevOpsMock = new Mock < IAzureDevOpsRestApi > ( ) ;
221
156
azDevOpsMock . Setup ( x => x . GetAuthorityAsync ( expectedOrgUri ) )
222
157
. ReturnsAsync ( authorityUrl ) ;
223
- azDevOpsMock . Setup ( x => x . CreatePersonalAccessTokenAsync ( expectedOrgUri , accessToken , expectedPatScopes ) )
224
- . ReturnsAsync ( pat ) ;
158
+ azDevOpsMock . Setup ( x => x . CreatePersonalAccessTokenAsync ( expectedOrgUri , accessToken , It . IsAny < IEnumerable < string > > ( ) ) )
159
+ . ReturnsAsync ( personalAccessToken ) ;
225
160
226
161
var msAuthMock = new Mock < IMicrosoftAuthentication > ( ) ;
227
162
msAuthMock . Setup ( x => x . GetAccessTokenAsync ( authorityUrl , expectedClientId , expectedRedirectUri , expectedResource ) )
228
163
. ReturnsAsync ( accessToken ) ;
229
164
230
165
var provider = new AzureReposHostProvider ( context , azDevOpsMock . Object , msAuthMock . Object ) ;
231
166
232
- GitCredential credential = await provider . CreateCredentialAsync ( input ) ;
167
+ ICredential credential = await provider . GetCredentialAsync ( input ) ;
233
168
234
169
Assert . NotNull ( credential ) ;
235
- Assert . Equal ( Constants . PersonalAccessTokenUserName , credential . UserName ) ;
236
- Assert . Equal ( pat , credential . Password ) ;
170
+ Assert . Equal ( personalAccessToken , credential . Password ) ;
171
+ // We don't care about the username value
237
172
}
238
173
}
239
174
}
0 commit comments