【问题标题】:Testing navigation in silverlight在 Silverlight 中测试导航
【发布时间】:2010-10-18 15:47:43
【问题描述】:

我有一个使用导航框架的 Silverlight 应用程序。

我正在尝试使用 Silverlight 测试框架为该应用程序编写单元测试,但是当我执行测试方法时,我收到以下错误:

InvalidOperationException
No XAML was found at the location '/Pages/LoginPage.xaml'

单元测试方法如下:

[TestMethod]
[Asynchronous]
public void TestMethod1()
{
    var mainPage = new MainPage();
    WaitFor(mainPage, "Loaded");
    TestPanel.Children.Add(mainPage);
    EnqueueCallback(() => Assert.IsTrue(mainPage != null));
    EnqueueTestComplete();
}

这是 MainPage.xaml:

<UserControl x:Class="AccurateSilverlight.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignHeight="577" d:DesignWidth="858"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
HorizontalContentAlignment="Center">

<Grid x:Name="LayoutRoot" Background="White">
    <Grid Height="36" Name="grid1" VerticalAlignment="Top" 
          Background="#FF9A9A9A">
        <ComboBox Height="23" HorizontalAlignment="Left" Margin="6,6,0,0" 
                  Name="ModuleComboBox" VerticalAlignment="Top" 
                  Width="250" IsEnabled="False" />
        <Button Content="Logout" Height="23" Margin="0,7,6,0" 
                Name="LogoutButton" VerticalAlignment="Top" 
                HorizontalAlignment="Right"
                Width="75" IsEnabled="False" Click="LogoutButton_Click" />
    </Grid>
    <sdk:Frame Margin="0,35,0,0" Name="NavigationFrame" 
               Source="/Pages/LoginPage.xaml" 
               Navigated="NavigationFrame_Navigated" />
</Grid>
</UserControl>

如果我运行“main”xap,应用程序可以正常工作。我只是在测试时遇到了这个错误。

我怀疑该错误是由于单元测试框架执行其 xap 并将我的 xap 嵌入其中,但无法找到解决此问题的方法。

有什么线索吗?

【问题讨论】:

    标签: silverlight unit-testing silverlight-4.0 silverlight-toolkit


    【解决方案1】:

    /Pages/LoginPage.xaml 与您当前的程序集相关。您需要使用pack URIs 完全限定您的路线。

    最终结果应该是这样的:/AccurateSilverlight;component/Pages/LoginPage.xaml

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      • 2013-02-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多