我有這樣的:如何模擬Application.Current進行單元測試?
<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:是的。怎麼樣 ? – Tar