如何为我的单元测试创建内存中图标
我有一个资源程序集,其中包含我的应用程序使用的各种字符串、图标和位图。
我编写了一个资源管理器类,我想对其进行单元测试。我已经成功创建了具有内存字符串(废话)和位图的单元测试,但我正在努力解决如何处理图标资源。
只需高度和宽度参数即可轻松创建位图,但图标似乎需要有效的流。
我已经尝试过了:
Icon icon = new Icon(new MemoryStream(), new Size(10, 15));
但这给了我错误“参数'图片'必须是可以用作图标的图片”。
显然,我正在尝试编写单元测试,因此希望避免从文件系统加载真实的图标。此外,ResourceManager 类正在处理程序集中的嵌入资源,因此我不想在单元测试程序集中嵌入真正的图标,否则我将使用类似的代码来促进测试,这似乎违反直觉。
有什么想法吗?
干杯, 本
I have a resource assembly that contains various strings, icons, and bitmaps that my application uses.
I have written a Resource Manager class that I would like to unit test. I have managed to create unit tests that have in-memory strings (duh) and bitmaps but I am struggling with how to handle the icon resources.
Bitmaps can be easily created with just a height and width params but Icons seem to require a valid stream.
I've tried:
Icon icon = new Icon(new MemoryStream(), new Size(10, 15));
But this gives me the error "Argument 'picture' must be a picture that can be used as an icon".
Obviously I'm trying to write unit tests so want to avoid having to load a real icon from the file system. Also the ResourceManager class is dealing with embedded resources within an assembly so I don't want to embed a real icon within my unit test assembly otherwise I'll be using similar code to facilitate the test which seems counter intuitive.
Any ideas?
Cheers,
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不只使用标准系统图标之一?喜欢
Why not just use one of the standard system icons? Like