我在實例化從資源加載圖像的視圖模型時遇到問題。WPF單元測試DirectoryNotFoundException
,在彙編失敗行我測試的是:
get { return new ImageSourceConverter().ConvertFromString("pack://application:,,,/Resources/Icons/Commands/DisabledNewSessionIcon.png") as ImageSource; }
的例外是: 無法創建類
GPAnalysisSuite.Tests.View_Models.Session_Controller.SessionControllerViewModel_NonDefaultConstructorTester. Error: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\TGP\GP Analysis 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;
}
I可以看到我需要保留正在測試的程序集的Uri,但不知道如何去做,任何人都可以幫忙嗎?