2011-12-16 33 views
0

我有一個測試提供無效的TFS憑證以驗證失敗的情況。但是,TfsTeamProjectCollection正在提取我自己的憑據,並且總是成功撥打Authenticate()。有沒有辦法強制無效的憑據?下面是我在做什麼:爲測試目的提供無效的TFS憑證

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 

NetworkCredentialsProvider類簡單地返回它的構造函數提供的NetworkCredential

以前這可能與TeamFoundationServer類(現在已被棄用)。

回答

3

這是我一直在尋找的答案:

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

很抱歉的噪音!