Skip to content

Commit fc48b8f

Browse files
author
Ricardo Bossan (BEYONDSOFT CONSULTING INC) (from Dev Box)
committed
Adds code coverage for public members of ChangeToolStripParentVerb.
Related dotnet#10773 - Adds code coverage for public members of `ChangeToolStripParentVerb`. - None - No - Minimal - Unit tests - 10.0.100-preview.3.25201.16
1 parent 140a1e7 commit fc48b8f

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/System.Windows.Forms.Design/tests/UnitTests/System/Windows/Forms/Design/ChangeToolStripParentVerbTests.cs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,65 +9,65 @@ namespace System.Windows.Forms.Design.Tests;
99

1010
public class ChangeToolStripParentVerbTests : IDisposable
1111
{
12+
private readonly Mock<IDesignerHost> _designerHostMock = new();
13+
private readonly Mock<IServiceProvider> _serviceProviderMock = new();
14+
private readonly Mock<ISite> _siteMock = new();
15+
private readonly Mock<IComponentChangeService> _componentChangeServiceMock = new() ;
1216
private readonly ToolStripDesigner _designer = new();
13-
private readonly ToolStrip _toolStrip;
14-
15-
public ChangeToolStripParentVerbTests()
16-
{
17-
_toolStrip = MockToolStrip();
18-
_designer.Initialize(_toolStrip);
19-
}
17+
private ToolStrip _toolStrip = new();
2018

2119
public void Dispose()
2220
{
2321
_toolStrip?.Dispose();
2422
_designer.Dispose();
2523
}
2624

27-
private ToolStrip MockToolStrip()
25+
private ToolStrip MockMinimalControl()
2826
{
29-
Mock<ISite> mockSite = new();
3027
Mock<ISelectionService> mockSelectionService = new();
31-
mockSite.Setup(s => s.GetService(typeof(ISelectionService))).Returns(mockSelectionService.Object);
32-
33-
Mock<IDesignerHost> mockDesignerHost = new();
34-
mockSite.Setup(s => s.GetService(typeof(IDesignerHost))).Returns(mockDesignerHost.Object);
35-
36-
Mock<IComponentChangeService> mockComponentChangeService = new();
37-
mockDesignerHost
28+
_siteMock
29+
.Setup(s => s.GetService(typeof(ISelectionService)))
30+
.Returns(mockSelectionService.Object);
31+
_siteMock
32+
.Setup(s => s.GetService(typeof(IDesignerHost)))
33+
.Returns(_designerHostMock.Object);
34+
_serviceProviderMock
35+
.Setup(s => s.GetService(typeof(IDesignerHost)))
36+
.Returns(_designerHostMock.Object);
37+
_serviceProviderMock
38+
.Setup(s => s.GetService(typeof(IComponentChangeService)))
39+
.Returns(new Mock<IComponentChangeService>().Object);
40+
_designerHostMock
3841
.Setup(dh => dh.GetService(typeof(IComponentChangeService)))
39-
.Returns(mockComponentChangeService.Object);
42+
.Returns(_componentChangeServiceMock.Object);
43+
_designerHostMock
44+
.Setup(dh => dh.GetDesigner(It.IsAny<IComponent>()))
45+
.Returns(new Mock<ParentControlDesigner>().Object);
4046

41-
ToolStrip toolStrip = new() { Site = mockSite.Object };
47+
ToolStrip toolStrip = new() { Site = _siteMock.Object };
4248

4349
return toolStrip;
4450
}
4551

4652
[Fact]
47-
public void Constructor_WithNullDesigner_Throws()
53+
public void ChangeParent_WithoutDesignerActionUIService_DoesNotChangeParent()
4854
{
49-
Action action = () => new ChangeToolStripParentVerb(null);
50-
51-
action.Should().Throw<Exception>();
52-
}
55+
Control? oldParent = _toolStrip.Parent;
56+
_toolStrip = MockMinimalControl();
57+
_designer.Initialize(_toolStrip);
5358

54-
[Fact]
55-
public void ChangeParent_DeepestPossibleTest()
56-
{
57-
var changeToolStripParentVerb = new ChangeToolStripParentVerb(_designer);
59+
ChangeToolStripParentVerb changeToolStripParentVerb = new(_designer);
5860

5961
changeToolStripParentVerb.ChangeParent();
60-
61-
throw new NotImplementedException();
62+
Control? newParent = _toolStrip.Parent;
63+
newParent.Should().Be(oldParent);
6264
}
6365

6466
[Fact]
65-
public void ChangeParent_WithNullRootDesigner_DoesNotChangesParent()
67+
public void Constructor_WithNullDesigner_Throws()
6668
{
67-
var changeToolStripParentVerb = new ChangeToolStripParentVerb(_designer);
68-
69-
changeToolStripParentVerb.ChangeParent();
69+
Action action = () => new ChangeToolStripParentVerb(null);
7070

71-
throw new NotImplementedException();
71+
action.Should().Throw<Exception>();
7272
}
7373
}

0 commit comments

Comments
 (0)