如何模拟Application.Current进行unit testing?

我有这个:

   

还有这个:

 public class GrayscaleEffect : ShaderEffect{ private static PixelShader _pixelShader = new PixelShader() { UriSource = new Uri(@"pack://application:,,,/Effects/GrayscaleEffect.ps") }; /* ... rest of the class ... */ } 

当我对它进行unit testing( MSTest )时,它显然会引发IOException (因为Application.Current为null,因此pack://application:,,,/...指向无处),并出现此错误:

Assembly.GetEntryAssembly() returns null. Set the Application.ResourceAssembly property or use the pack://application:,,,/assemblyname;component/ syntax to specify the assembly to load the resource from.

我如何模拟/注入解决它所需的一切?

好的,得到它,感谢Will :

 if(Application.ResourceAssembly == null) Application.ResourceAssembly = typeof(MainWindow).Assembly; var window = new MainWindow(); 

Tal的答案对我没有用,我只是在运行测试之前调用下面的Application.Current填充:

 var app = new Application();