WinUI3欢迎屏项目单元测试抛出异常的解决方案咨询
WinUI 3欢迎屏项目单元测试异常解决求助
我有一个WinUI 3欢迎屏项目,运行正常,但执行单元测试函数时会抛出异常,现寻求解决办法。当前ViewModel中创建了Frame对象ContentFrame以绑定View中的Frame控件,也接受将Frame移出ViewModel的解决方案。
单元测试代码
[TestClass()] public class WelcomeScreenPageViewModelTests { [TestMethod()] public void WelcomeScreenPageViewModelTest() { WelcomeScreenPage welcomeScreenPage = new WelcomeScreenPage(); WelcomeScreenPageViewModel _viewModel = new WelcomeScreenPageViewModel(welcomeScreenPage);// 抛出异常 Assert.AreEqual(_viewModel.IsCheckBoxVisible, false); Assert.AreEqual(_viewModel.IsBackButtonVisible, false); Assert.AreEqual(_viewModel.NextButtonText, "Next"); Assert.AreEqual(_viewModel.CurrentPageIndex, 0); } }
ViewModel代码
public class WelcomeScreenPageViewModel : ObservableObject { private WelcomeScreenPage welcomeScreenPage; public WelcomeScreenPageViewModel(WelcomeScreenPage welcomeScreenPage) { this.welcomeScreenPage = welcomeScreenPage; } public Frame ContentFrame = new(); // 抛出异常 }
View代码
<Frame x:Name="NavigationFrame" Content="{x:Bind ViewModel.ContentFrame,Mode=TwoWay}" />
异常信息
- 尝试实例化
Frame对象时抛出System.Runtime.InteropServices.COMException,错误提示为“类未注册” - 调用堆栈显示异常源自
WinRT.Runtime内部调用及Frame的构造函数
项目源码已提供。
内容的提问来源于stack exchange,提问作者Ming
相关产品推荐
相关产品推荐

