views:

33

answers:

1

Hi,

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

+1  A: 

Why not just use one of the standard system icons? Like

Icon icon = System.Drawing.SystemIcons.WinLogo;
odd parity
Hi, that's a good idea. I wasn't aware of this collection of system icons. This does allow me to have an in-memory icon but I am still having a few problems.I can convert the WinLogo into a stream using the Icon.Save method but when I use this stream to re-create my icon using the icon constructor I get the same error message regarding 'valid picture'
Ben Cawley
Ok, it was because after the icon was written to the stream I neglected to reset the position to zero. Works now! Thanks.
Ben Cawley