如何测试NavigationService是否已配置?

时间:2015-01-13 18:11:30

标签: c# unit-testing mvvm-light

希望测试验证所有导航路径都符合预期,因此如果有人更改导航路径,测试将会捕获它。

    [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);            
    }

然而,它并没有真正测试我想要测试的内容。

是否有办法访问存储字符串和类型的字典?

1 个答案:

答案 0 :(得分: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);
    }
}