Search code examples
tfstfs-sdk

Supplying invalid TFS credentials for test purposes


I'm having a scenario where a test is supplying invalid TFS credentials in order to fail authentication. However, TfsTeamProjectCollection is picking up my own credentials and always succeeds the call to Authenticate(). Is there a way to force invalid credentials? Here's what I am doing:

var account = new NetworkCredential(user.UserName, user.Password, user.Domain);
var provider = new NetworkCredentialsProvider(account);
teamProjectCollection = new TfsTeamProjectCollection(
    new Uri(serverUri),
    provider);
teamProjectCollection.Authenticate(); // should throw with invalid credentials

The NetworkCredentialsProviderclass simply returns the NetworkCredentialsupplied in its constructor.

Previously this was possible with the TeamFoundationServer class (which is now deprecated).


Solution

  • Here's the answer I was looking for:

    var account = new NetworkCredential(user.UserName, user.Password, user.Domain);
    teamProjectCollection = new TfsTeamProjectCollection(new Uri(serverUri),account);
    teamProjectCollection.Authenticate();
    

    Sorry for the noise!