如何测试导航服务是否已配置

本文关键字:服务 是否 配置 导航 何测试 测试 | 更新日期: 2023-09-27 18:37:26

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

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

但是,它并没有真正测试我想测试的内容。

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

如何测试导航服务是否已配置

这样做:

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