Skip to content

Commit

Permalink
Add unit test for image list action list (#11766)
Browse files Browse the repository at this point in the history
Add unit test for ImageListActionList
  • Loading branch information
John-Qiao authored Aug 1, 2024
1 parent 33cf608 commit ccd88e2
Showing 1 changed file with 88 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// 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.ComponentModel.Design;
using System.Drawing;

namespace System.Windows.Forms.Design.Tests;

public sealed class ImageListActionListTests : IDisposable
{
private readonly ImageListDesigner _imageListDesigner;
private readonly ImageList _imageList;
private readonly ImageListActionList _actionList;
public ImageListActionListTests()
{
_imageListDesigner = new();
_imageList = new();
_imageListDesigner.Initialize(_imageList);
_actionList = new(_imageListDesigner);
}

public void Dispose()
{
_imageListDesigner.Dispose();
_imageList.Dispose();
}

[Fact]
public void Constructor_ShouldInitializeDesigner()
{
_actionList.Should().NotBeNull();
_actionList.Should().BeOfType<ImageListActionList>();
_actionList.Component.Should().Be(_imageListDesigner.Component);
}

[Fact]
public void ColorDepth_Get_ShouldReturnColorDepth()
{
_actionList.ColorDepth.Should().Be(ColorDepth.Depth32Bit);
}

[Fact]
public void ColorDepth_Set_ShouldUpdateColorDepth()
{
_actionList.ColorDepth = ColorDepth.Depth16Bit;
_actionList.ColorDepth.Should().Be(ColorDepth.Depth16Bit);
}

[Fact]
public void ImageSize_Get_ShouldReturnImageSize()
{
Size size = new(16, 16);
_actionList.ImageSize.Should().Be(size);
}

[Fact]
public void ImageSize_Set_ShouldUpdateImageSize()
{
Size size = new(32, 32);
_actionList.ImageSize = size;
_actionList.ImageSize.Should().Be(size);
}

[Fact]
public void GetSortedActionItems_ShouldReturnExpectedItems()
{
DesignerActionItemCollection items = _actionList.GetSortedActionItems();
items.Should().NotBeNull();
items.Should().BeOfType<DesignerActionItemCollection>();

items[0].Should().BeOfType<DesignerActionPropertyItem>();
items[0].DisplayName.Should().Be(SR.ImageListActionList_ImageSizeDisplayName);
items[0].Category.Should().Be(SR.PropertiesCategoryName);
items[0].Description.Should().Be(SR.ImageListActionList_ImageSizeDescription);

items[1].Should().BeOfType<DesignerActionPropertyItem>();
items[1].DisplayName.Should().Be(SR.ImageListActionList_ColorDepthDisplayName);
items[1].Category.Should().Be(SR.PropertiesCategoryName);
items[1].Description.Should().Be(SR.ImageListActionList_ColorDepthDescription);

items[2].Should().BeOfType<DesignerActionMethodItem>();
items[2].DisplayName.Should().Be(SR.ImageListActionList_ChooseImagesDisplayName);
items[2].Category.Should().Be(SR.LinksCategoryName);
items[2].Description.Should().Be(SR.ImageListActionList_ChooseImagesDescription);
}
}

0 comments on commit ccd88e2

Please sign in to comment.