|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the MIT license. |
| 3 | + |
| 4 | +#nullable enable |
| 5 | + |
| 6 | +using System.Drawing; |
| 7 | + |
| 8 | +namespace System.Windows.Forms.Design.Tests; |
| 9 | + |
| 10 | +public sealed class ImageListImageTests |
| 11 | +{ |
| 12 | + [Fact] |
| 13 | + public void Constructor_WithImage_ShouldSetImageProperty() |
| 14 | + { |
| 15 | + using Bitmap bitmap = new(10, 10); |
| 16 | + ImageListImage imageListImage = new(bitmap); |
| 17 | + |
| 18 | + imageListImage.Image.Should().Be(bitmap); |
| 19 | + imageListImage.Name.Should().BeEmpty(); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public void Constructor_WithImageAndName_ShouldSetImageAndNameProperties() |
| 24 | + { |
| 25 | + using Bitmap bitmap = new(10, 10); |
| 26 | + string name = "TestImage"; |
| 27 | + ImageListImage imageListImage = new(bitmap, name); |
| 28 | + |
| 29 | + imageListImage.Image.Should().Be(bitmap); |
| 30 | + imageListImage.Name.Should().Be(name); |
| 31 | + } |
| 32 | + |
| 33 | + [Fact] |
| 34 | + public void NameProperty_ShouldGetAndSetCorrectly() |
| 35 | + { |
| 36 | + using Bitmap bitmap = new(10, 10); |
| 37 | + string name = "TestImage"; |
| 38 | + ImageListImage imageListImage = new(bitmap) |
| 39 | + { |
| 40 | + Name = name |
| 41 | + }; |
| 42 | + |
| 43 | + imageListImage.Name.Should().Be(name); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void NameProperty_ShouldReturnEmptyString_WhenNameIsNull() |
| 48 | + { |
| 49 | + using Bitmap bitmap = new(10, 10); |
| 50 | + ImageListImage imageListImage = new(bitmap) |
| 51 | + { |
| 52 | + Name = null |
| 53 | + }; |
| 54 | + |
| 55 | + imageListImage.Name.Should().BeEmpty(); |
| 56 | + } |
| 57 | + |
| 58 | + [Fact] |
| 59 | + public void ImageListImageFromStream_ShouldCreateImageListImageFromBitmapStream() |
| 60 | + { |
| 61 | + using Bitmap bitmap = new(10, 10); |
| 62 | + using MemoryStream memoryStream = new(); |
| 63 | + bitmap.Save(memoryStream, Drawing.Imaging.ImageFormat.Bmp); |
| 64 | + memoryStream.Seek(0, SeekOrigin.Begin); |
| 65 | + |
| 66 | + var result = ImageListImage.ImageListImageFromStream(memoryStream, imageIsIcon: false); |
| 67 | + |
| 68 | + result.Should().NotBeNull(); |
| 69 | + result.Image.Should().NotBeNull(); |
| 70 | + result.Image.Size.Should().Be(bitmap.Size); |
| 71 | + result.Image.RawFormat.Should().Be(expected: Drawing.Imaging.ImageFormat.Bmp); |
| 72 | + } |
| 73 | + |
| 74 | + [Fact] |
| 75 | + public void ImageListImageFromStream_ShouldCreateImageListImageFromIconStream() |
| 76 | + { |
| 77 | + using Icon icon = SystemIcons.Application; |
| 78 | + using MemoryStream memoryStream = new(); |
| 79 | + icon.Save(memoryStream); |
| 80 | + memoryStream.Seek(0, SeekOrigin.Begin); |
| 81 | + |
| 82 | + var result = ImageListImage.ImageListImageFromStream(memoryStream, imageIsIcon: true); |
| 83 | + |
| 84 | + result.Should().NotBeNull(); |
| 85 | + result.Image.Should().NotBeNull(); |
| 86 | + result.Image.Size.Should().Be(icon.Size); |
| 87 | + result.Image.RawFormat.Should().Be(Drawing.Imaging.ImageFormat.MemoryBmp); |
| 88 | + } |
| 89 | +} |
0 commit comments