-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
89 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
...m.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/ImageListImageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
#nullable enable | ||
|
||
using System.Drawing; | ||
|
||
namespace System.Windows.Forms.Design.Tests; | ||
|
||
public sealed class ImageListImageTests | ||
{ | ||
[Fact] | ||
public void Constructor_WithImage_ShouldSetImageProperty() | ||
{ | ||
using Bitmap bitmap = new(10, 10); | ||
ImageListImage imageListImage = new(bitmap); | ||
|
||
imageListImage.Image.Should().Be(bitmap); | ||
imageListImage.Name.Should().BeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_WithImageAndName_ShouldSetImageAndNameProperties() | ||
{ | ||
using Bitmap bitmap = new(10, 10); | ||
string name = "TestImage"; | ||
ImageListImage imageListImage = new(bitmap, name); | ||
|
||
imageListImage.Image.Should().Be(bitmap); | ||
imageListImage.Name.Should().Be(name); | ||
} | ||
|
||
[Fact] | ||
public void NameProperty_ShouldGetAndSetCorrectly() | ||
{ | ||
using Bitmap bitmap = new(10, 10); | ||
string name = "TestImage"; | ||
ImageListImage imageListImage = new(bitmap) | ||
{ | ||
Name = name | ||
}; | ||
|
||
imageListImage.Name.Should().Be(name); | ||
} | ||
|
||
[Fact] | ||
public void NameProperty_ShouldReturnEmptyString_WhenNameIsNull() | ||
{ | ||
using Bitmap bitmap = new(10, 10); | ||
ImageListImage imageListImage = new(bitmap) | ||
{ | ||
Name = null | ||
}; | ||
|
||
imageListImage.Name.Should().BeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void ImageListImageFromStream_ShouldCreateImageListImageFromBitmapStream() | ||
{ | ||
using Bitmap bitmap = new(10, 10); | ||
using MemoryStream memoryStream = new(); | ||
bitmap.Save(memoryStream, Drawing.Imaging.ImageFormat.Bmp); | ||
memoryStream.Seek(0, SeekOrigin.Begin); | ||
|
||
var result = ImageListImage.ImageListImageFromStream(memoryStream, imageIsIcon: false); | ||
|
||
result.Should().NotBeNull(); | ||
result.Image.Should().NotBeNull(); | ||
result.Image.Size.Should().Be(bitmap.Size); | ||
result.Image.RawFormat.Should().Be(expected: Drawing.Imaging.ImageFormat.Bmp); | ||
} | ||
|
||
[Fact] | ||
public void ImageListImageFromStream_ShouldCreateImageListImageFromIconStream() | ||
{ | ||
using Icon icon = SystemIcons.Application; | ||
using MemoryStream memoryStream = new(); | ||
icon.Save(memoryStream); | ||
memoryStream.Seek(0, SeekOrigin.Begin); | ||
|
||
var result = ImageListImage.ImageListImageFromStream(memoryStream, imageIsIcon: true); | ||
|
||
result.Should().NotBeNull(); | ||
result.Image.Should().NotBeNull(); | ||
result.Image.Size.Should().Be(icon.Size); | ||
result.Image.RawFormat.Should().Be(Drawing.Imaging.ImageFormat.MemoryBmp); | ||
} | ||
} |