2015-01-13 133 views
0

想要測試來驗證所有的導航路徑都如預期的那樣,所以如果有人改變了導航路徑,測試就會抓住它。如何測試NavigationService配置?

[TestMethod] 
    public void NavigationServiceIsConfigured() 
    { 
     NavigationService service = new NavigationService(); 

     // this is code under test put here for reference 
     service.Configure("MainPage", typeof(MainPage)); 
     service.NavigateTo("MainPage"); 

     // Verify 
     Assert.AreEqual("MainPage", service.CurrentPageKey);    
    } 

但是,它並沒有真正測試我想要測試的東西。

沒有辦法訪問存儲字符串和類型的字典嗎?

回答

0

走遍這樣說:

public class DefaultNavigationService : NavigationService 
{ 
    public Dictionary<string, Type> Configuration 
    { 
     get; 
     private set; 
    }  
    public DefaultNavigationService() : base() 
    { 
     Configuration = new Dictionary<string, Type>();    
    } 
    public new void Configure(string key, Type pageType) 
    { 
     Configuration.Add(key, pageType); 
     base.Configure(key, pageType); 
    } 
}