Skip to content

Commit

Permalink
Add unit tests for ContextMenuStripGroupCollection (#11952)
Browse files Browse the repository at this point in the history
Related #10773
Add unit test ContextMenuStripGroupCollectionTests.cs for public properties and method of the ContextMenuStripGroupCollection.
Enable nullability in ContextMenuStripGroupCollection.
  • Loading branch information
Philip-Wang01 authored Aug 24, 2024
1 parent abbccaa commit 14acefa
Showing 1 changed file with 55 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#nullable enable

namespace System.Windows.Forms.Design.Tests;

public class ContextMenuStripGroupCollectionTests
{
[Fact]
public void Indexer_ShouldCreateNewGroupIfKeyDoesNotExist()
{
ContextMenuStripGroupCollection collection = new();

ContextMenuStripGroup group = collection["newKey"];

group.Should().NotBeNull();
group.Should().BeOfType<ContextMenuStripGroup>();
collection.ContainsKey("newKey").Should().BeTrue();
}

[Fact]
public void ContainsKey_ShouldReturnFalseIfKeyDoesNotExist()
{
ContextMenuStripGroupCollection collection = new();

bool containsKey = collection.ContainsKey("nonExistentKey");

containsKey.Should().BeFalse();
}

[Fact]
public void Indexer_ShouldReturnSameGroupForSameKey()
{
ContextMenuStripGroupCollection collection = new();

ContextMenuStripGroup group1 = collection["newKey"];
ContextMenuStripGroup group2 = collection["newKey"];

group1.Should().BeSameAs(group2);
}

[Fact]
public void Indexer_ShouldReturnDifferentGroupsForDifferentKeys()
{
ContextMenuStripGroupCollection collection = new();

ContextMenuStripGroup group1 = collection["key1"];
ContextMenuStripGroup group2 = collection["key2"];

group1.Should().NotBeSameAs(group2);
collection.ContainsKey("key1").Should().BeTrue();
collection.ContainsKey("key2").Should().BeTrue();
}
}

0 comments on commit 14acefa

Please sign in to comment.