-
Notifications
You must be signed in to change notification settings - Fork 1k
Adds code coverage to StandardMenuStripVerb #13492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ricardobossan
wants to merge
3
commits into
dotnet:main
Choose a base branch
from
ricardobossan:Issue_10773_Add_Coverage_For_StandardMenuStripVerb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
132 changes: 132 additions & 0 deletions
132
...ws.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/StandardMenuStripVerbTests.cs
This file contains hidden or 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,132 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.ComponentModel; | ||
using System.ComponentModel.Design; | ||
using System.ComponentModel.Design.Serialization; | ||
using System.Windows.Forms.Design.Behavior; | ||
using Moq; | ||
|
||
namespace System.Windows.Forms.Design.Tests; | ||
public class StandardMenuStripVerbTests : IDisposable | ||
{ | ||
private readonly Mock<IDesignerHost> _designerHostMock = new(); | ||
private readonly Mock<IServiceProvider> _serviceProviderMock = new(); | ||
private readonly Mock<ISelectionService> _selectionServiceMock = new(); | ||
private readonly Mock<IComponentChangeService> _componentChangeServiceMock = new(); | ||
private readonly Mock<ISite> _siteMock = new(); | ||
private readonly Mock<DesignerTransaction> _mockTransaction = new(MockBehavior.Loose); | ||
|
||
private readonly DesignerFrame _designerFrame; | ||
private readonly SelectionManager _selectionManager; | ||
private readonly BehaviorService _behaviorService; | ||
private readonly DesignerActionUIService _designerActionUIService; | ||
|
||
private readonly ToolStripDesigner _designer = new(); | ||
private readonly ParentControlDesigner _parentControlDesigner = new(); | ||
private readonly MenuStrip _menuStrip = new(); | ||
|
||
public StandardMenuStripVerbTests() | ||
{ | ||
_siteMock.Setup(s => s.GetService(typeof(INestedContainer))).Returns(new Mock<IContainer>().Object); | ||
_siteMock.Setup(s => s.Container).Returns(new Mock<ServiceContainer>().Object as IContainer); | ||
_siteMock.Setup(s => s.GetService(typeof(UndoEngine))).Returns(null!); | ||
_siteMock.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(_designerHostMock.Object); | ||
_siteMock.Setup(s => s.GetService(typeof(IComponentChangeService))).Returns(_componentChangeServiceMock.Object); | ||
|
||
_designerFrame = new(_siteMock.Object); | ||
_behaviorService = new(_serviceProviderMock.Object, _designerFrame); | ||
_siteMock.Setup(s => s.GetService(typeof(BehaviorService))).Returns(_behaviorService); | ||
_siteMock.Setup(s => s.GetService(typeof(ToolStripAdornerWindowService))).Returns(null!); | ||
_siteMock.Setup(s => s.GetService(typeof(DesignerActionService))).Returns(new Mock<DesignerActionService>(_siteMock.Object).Object); | ||
|
||
Mock<INameCreationService> nameCreationServiceMock = new(); | ||
nameCreationServiceMock.Setup(n => n.IsValidName(It.IsAny<string>())).Returns(true); | ||
_siteMock.Setup(s => s.GetService(typeof(INameCreationService))).Returns(nameCreationServiceMock.Object); | ||
_designerActionUIService = new(_siteMock.Object); | ||
_siteMock.Setup(s => s.GetService(typeof(DesignerActionUIService))).Returns(_designerActionUIService); | ||
|
||
_serviceProviderMock.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(_designerHostMock.Object); | ||
_serviceProviderMock.Setup(s => s.GetService(typeof(IComponentChangeService))).Returns(new Mock<IComponentChangeService>().Object); | ||
|
||
_designerHostMock.Setup(h => h.RootComponent).Returns(_menuStrip); | ||
_designerHostMock.Setup(h => h.CreateTransaction(It.IsAny<string>())).Returns(_mockTransaction.Object); | ||
_designerHostMock.Setup(h => h.GetService(typeof(IComponentChangeService))).Returns(_componentChangeServiceMock.Object); | ||
_designerHostMock.Setup(h => h.AddService(typeof(ToolStripKeyboardHandlingService), It.IsAny<object>())); | ||
_designerHostMock.Setup(h => h.AddService(typeof(ISupportInSituService), It.IsAny<object>())); | ||
_designerHostMock.Setup(h => h.AddService(typeof(DesignerActionService), It.IsAny<object>())); | ||
_designerHostMock.Setup(h => h.GetDesigner(_menuStrip)).Returns(_parentControlDesigner); | ||
_designerHostMock.Setup(h => h.AddService(typeof(DesignerActionUIService), It.IsAny<object>())); | ||
Mock<ToolStripMenuItem> toolStripMenuItemMock = new(); | ||
using ToolStripDropDownMenu toolStripDropDownMenu = new(); | ||
toolStripMenuItemMock.Object.DropDown = toolStripDropDownMenu; | ||
|
||
string[] menuItemImageNames = | ||
[ | ||
"file", "new", "open", "save", "saveAs", "print", "printPreview", "cut", "copy", "paste", "undo", "redo", | ||
"delete", "selectAll", "edit", "exit", "saveAs", "saveAll", "tool", "tools", "customize", "options", "help", | ||
"contents", "index", "search", "about", "cut", "copy", "Paste", "undo", "redo" | ||
ricardobossan marked this conversation as resolved.
Show resolved
Hide resolved
ricardobossan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
]; | ||
|
||
foreach (string item in menuItemImageNames) | ||
{ | ||
_designerHostMock.Setup(h => h.CreateComponent(typeof(ToolStripMenuItem), item + "ToolStripMenuItem")).Returns(toolStripMenuItemMock.Object); | ||
} | ||
|
||
_designerHostMock.Setup(h => h.CreateComponent(typeof(ToolStripSeparator), "toolStripSeparator")).Returns(new Mock<ToolStripSeparator>().Object); | ||
_selectionServiceMock.Setup(s => s.GetComponentSelected(_menuStrip)).Returns(true); | ||
_siteMock.Setup(s => s.GetService(typeof(ISelectionService))).Returns(_selectionServiceMock.Object); | ||
_designerHostMock.Setup(h => h.AddService(typeof(ISelectionService), _selectionServiceMock.Object)); | ||
_serviceProviderMock.Setup(s => s.GetService(typeof(ISelectionService))).Returns(_selectionServiceMock.Object); | ||
_selectionManager = new(_serviceProviderMock.Object, _behaviorService!); | ||
_siteMock.Setup(s => s.GetService(typeof(SelectionManager))).Returns(_selectionManager); | ||
|
||
_menuStrip.Site = _siteMock.Object; | ||
|
||
_designer.Initialize(_menuStrip); | ||
_parentControlDesigner.Initialize(_menuStrip); | ||
|
||
IComponent[] components = []; | ||
ComponentCollection componentCollection = new(components); | ||
_selectionServiceMock.Setup(s => s.GetSelectedComponents()).Returns(components); | ||
|
||
Mock<IContainer> containerMock = new(); | ||
containerMock.Setup(c => c.Components).Returns(componentCollection); | ||
_designerHostMock.Setup(d => d.Container).Returns(containerMock.Object); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_menuStrip?.Dispose(); | ||
_parentControlDesigner.Dispose(); | ||
_behaviorService?.Dispose(); | ||
_selectionManager?.Dispose(); | ||
_designerFrame.Dispose(); | ||
_designer.Dispose(); | ||
} | ||
|
||
[WinFormsFact] | ||
public void StandardMenuStripVerb_Ctor() | ||
{ | ||
StandardMenuStripVerb standardMenuStripVerb = new(_designer); | ||
standardMenuStripVerb.Should().BeOfType<StandardMenuStripVerb>(); | ||
ToolStripDesigner toolStripDesigner = standardMenuStripVerb.TestAccessor().Dynamic._designer; | ||
toolStripDesigner.Should().Be(_designer); | ||
} | ||
|
||
[WinFormsFact] | ||
public void StandardMenuStripVerb_InsertsMenuStrip() | ||
{ | ||
StandardMenuStripVerb standardMenuStripVerb = new(_designer); | ||
|
||
ToolStripItemCollection toolStripItemCollection = _parentControlDesigner.Component.TestAccessor().Dynamic._toolStripItemCollection; | ||
|
||
toolStripItemCollection.Count.Should().Be(0); | ||
|
||
standardMenuStripVerb.InsertItems(); | ||
|
||
toolStripItemCollection = _parentControlDesigner.Component.TestAccessor().Dynamic._toolStripItemCollection; | ||
|
||
toolStripItemCollection.Count.Should().Be(1); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.