【问题标题】:WPF unit test DirectoryNotFoundExceptionWPF 单元测试 DirectoryNotFoundException
【发布时间】:2011-03-17 12:05:05
【问题描述】:

我无法实例化从资源加载图像的视图模型。

我正在测试的程序集中失败的行是:

get { return new ImageSourceConverter().ConvertFromString("pack://application:,,,/Resources/Icons/Commands/DisabledNewSessionIcon.png") as ImageSource; }

例外是: 无法创建类的实例

GPAnalysisSuite.Tests.View_Models.Session_Controller.SessionControllerViewModel_NonDefaultConstructorTester。 错误: System.IO.DirectoryNotFoundException: 找不到路径的一部分 'C:\TGP\GP 分析 Suite\Application\Tests\TestResults\Paul_PAUL-GP 2011-03-17 11_27_28\Out\Resources\Icons\Commands\DisabledNewSessionIcon.png'..

我已经找到了一个类似问题的解决方案,并将以下内容包含在 TestClass 中:

 [AssemblyInitialize]
    public static void InitialisePackageUriHelper(TestContext context)
    {
        PackUriHelper.Create(new Uri("reliable://0"));
        new FrameworkElement();
        System.Windows.Application.ResourceAssembly = typeof(App).Assembly; 
    }

我可以看到我需要保留我正在测试的程序集的 Uri,但不知道该怎么做,有人可以帮忙吗?

【问题讨论】:

    标签: wpf unit-testing resources path


    【解决方案1】:

    我似乎通过将资源构建操作从 Content 更改为 Resource 解决了这个问题。
    虽然每次我想运行单元测试时我都必须重新构建解决方案,但至少现在这是可行的。

    【讨论】:

      猜你喜欢
      • 2010-09-24
      • 2011-06-28
      • 2023-03-17
      • 2012-09-02
      • 2011-09-21
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 2011-01-18
      相关资源
      最近更新 更多