开发者

WPF unit test DirectoryNotFoundException

I am having trouble instantiating a view model wich loads an image from Resources.

The line that fails in the assembly I'm testing is:

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

the exception is: Unable to create instance of class

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'..

I have already found a solution to a simular problem and included the following to the TestClass:

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

I can see that I need to preserve the Uri of the assembly I'm testing开发者_开发问答 but have no idea how to do it, can anyone help?


I appear to have solved the problem by changing the resource build action from Content to Resource.
Although I have to rebuild the solution everytime I want to run the unit tests this is now workable at least.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜