コード例 #1
0
        public void GetResource()
        {
            //Add another resource manager to the list
            Assembly ass      = Assembly.LoadWithPartialName("Spring.Core.Tests");
            string   baseName = "Spring" + "." + "Resources.Images";

            resourceManagerList.Add(new ResourceManager(baseName, ass));
            messageSource.ResourceManagers = resourceManagerList;
            object obj = messageSource.GetResourceObject("bubblechamber", CultureInfo.CurrentCulture);

            Assert.IsNotNull(obj, "expected to retrieve object form resource set");
            Bitmap bitMap = null;

            //.NET 1.0 returns this as a base64 string while .NET 1.1 returns it as a Bitmap
            //There are some isues with resx compatability between framework versions.
            if (obj is string)
            {
                //thanks dotnetdave for the string to bitmap cookbook.
                //http://www.vsdntips.com/Tips/VS.NET/Csharp/76.aspx
                string ImageText  = obj as string;
                Byte[] bitmapData = new Byte[ImageText.Length];
                bitmapData = Convert.FromBase64String(FixBase64ForImage(ImageText));
                MemoryStream streamBitmap = new MemoryStream(bitmapData);
                bitMap = new Bitmap((Bitmap)Image.FromStream(streamBitmap));
            }
            else
            {
                bitMap = obj as Bitmap;
            }
            Assert.IsNotNull(bitMap, "expected to retrieve BitMap. Instead Type = " + obj.GetType());
            Assert.AreEqual(146, bitMap.Size.Width, "Width of image wrong");
            Assert.AreEqual(119, bitMap.Size.Height, "Height of image wrong");

            object obj2 = messageSource.GetResourceObject("notExist", CultureInfo.CurrentCulture);

            Assert.IsNull(obj2, "non existent resourse found");
        }