如何测试 NavigationService 是否已配置?
How to test that NavigationService is configured?
希望测试验证所有导航路径都符合预期,这样如果有人更改导航路径,测试就会捕获它。
[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);
}
}
希望测试验证所有导航路径都符合预期,这样如果有人更改导航路径,测试就会捕获它。
[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);
}
}