How to create an in-memory icon for my unit test
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 i开发者_开发知识库con 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
Why not just use one of the standard system icons? Like
Icon icon = System.Drawing.SystemIcons.WinLogo;
精彩评论