|
| 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 | +namespace System.Windows.Forms.Design.Tests; |
| 7 | + |
| 8 | +public class ContextMenuStripGroupCollectionTests |
| 9 | +{ |
| 10 | + [Fact] |
| 11 | + public void Indexer_ShouldCreateNewGroupIfKeyDoesNotExist() |
| 12 | + { |
| 13 | + ContextMenuStripGroupCollection collection = new(); |
| 14 | + |
| 15 | + ContextMenuStripGroup group = collection["newKey"]; |
| 16 | + |
| 17 | + group.Should().NotBeNull(); |
| 18 | + group.Should().BeOfType<ContextMenuStripGroup>(); |
| 19 | + collection.ContainsKey("newKey").Should().BeTrue(); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public void ContainsKey_ShouldReturnFalseIfKeyDoesNotExist() |
| 24 | + { |
| 25 | + ContextMenuStripGroupCollection collection = new(); |
| 26 | + |
| 27 | + bool containsKey = collection.ContainsKey("nonExistentKey"); |
| 28 | + |
| 29 | + containsKey.Should().BeFalse(); |
| 30 | + } |
| 31 | + |
| 32 | + [Fact] |
| 33 | + public void Indexer_ShouldReturnSameGroupForSameKey() |
| 34 | + { |
| 35 | + ContextMenuStripGroupCollection collection = new(); |
| 36 | + |
| 37 | + ContextMenuStripGroup group1 = collection["newKey"]; |
| 38 | + ContextMenuStripGroup group2 = collection["newKey"]; |
| 39 | + |
| 40 | + group1.Should().BeSameAs(group2); |
| 41 | + } |
| 42 | + |
| 43 | + [Fact] |
| 44 | + public void Indexer_ShouldReturnDifferentGroupsForDifferentKeys() |
| 45 | + { |
| 46 | + ContextMenuStripGroupCollection collection = new(); |
| 47 | + |
| 48 | + ContextMenuStripGroup group1 = collection["key1"]; |
| 49 | + ContextMenuStripGroup group2 = collection["key2"]; |
| 50 | + |
| 51 | + group1.Should().NotBeSameAs(group2); |
| 52 | + collection.ContainsKey("key1").Should().BeTrue(); |
| 53 | + collection.ContainsKey("key2").Should().BeTrue(); |
| 54 | + } |
| 55 | +} |
0 commit comments