【发布时间】:2013-08-01 08:48:08
【问题描述】:
我有这个:
<Image.Effect>
<fx:GrayscaleEffect DesaturationFactor="0"/>
</Image.Effect>
还有这个:
public class GrayscaleEffect : ShaderEffect{
private static PixelShader _pixelShader = new PixelShader()
{
UriSource = new Uri(@"pack://application:,,,/Effects/GrayscaleEffect.ps")
};
/* ... rest of the class ... */
}
当我对它进行单元测试 (MSTest) 时,它显然会引发 IOException(因为 Application.Current 为空,所以 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.
我如何模拟/注入解决它所需的任何东西?
【问题讨论】:
-
我认为将 Uri 注入到 GrayscaleEffect 中会更容易。这对你有用吗?
-
@DanielSklenitzka:是的。怎么样?
标签: c# wpf unit-testing mocking mstest