Skip to content

Commit 330e186

Browse files
committed
Added doc comments to the MockFactory closes #630.
Also removed some dead code.
1 parent e814efb commit 330e186

File tree

3 files changed

+88
-15
lines changed

3 files changed

+88
-15
lines changed

RubberduckTests/Mocks/MockFactory.cs

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
74
using Microsoft.Vbe.Interop;
85
using Moq;
96

107
namespace RubberduckTests.Mocks
118
{
129
static class MockFactory
1310
{
11+
/// <summary>
12+
/// Creates a mock <see cref="Window"/> that is particularly useful for passing into <see cref="MockWindowsCollection"/>'s ctor.
13+
/// </summary>
14+
/// <returns>
15+
/// A <see cref="Mock{Window}"/>that has all the properties needed for <see cref="Rubberduck.UI.DockablePresenterBase"/> pre-setup.
16+
/// </returns>
1417
internal static Mock<Window> CreateWindowMock()
1518
{
1619
var window = new Mock<Window>();
@@ -22,6 +25,14 @@ internal static Mock<Window> CreateWindowMock()
2225
return window;
2326
}
2427

28+
/// <summary>
29+
/// Creates a new <see cref="Mock{VBE}"/> that returns the <see cref="Windows"/> collection argument out of the Windows property.
30+
/// </summary>
31+
/// <param name="windows">
32+
/// A <see cref="MockWindowsCollection"/> is expected.
33+
/// Other objects implementing the<see cref="Windows"/> interface could cause issues.
34+
/// </param>
35+
/// <returns></returns>
2536
internal static Mock<VBE> CreateVbeMock(Windows windows)
2637
{
2738
var vbe = new Mock<VBE>();
@@ -30,6 +41,15 @@ internal static Mock<VBE> CreateVbeMock(Windows windows)
3041
return vbe;
3142
}
3243

44+
/// <summary>
45+
/// Creates a new <see cref="Mock{VBE}"/> with the <see cref="VBE.Windows"/> and <see cref="VBE.VBProjects"/> properties setup.
46+
/// </summary>
47+
/// <param name="windows">
48+
/// A <see cref="MockWindowsCollection"/> is expected.
49+
/// Other objects implementing the<see cref="Windows"/> interface could cause issues.
50+
/// </param>
51+
/// <param name="projects"><see cref="VBProjects"/> collecction.</param>
52+
/// <returns></returns>
3353
internal static Mock<VBE> CreateVbeMock(Windows windows, VBProjects projects)
3454
{
3555
var vbe = CreateVbeMock(windows);
@@ -38,16 +58,37 @@ internal static Mock<VBE> CreateVbeMock(Windows windows, VBProjects projects)
3858
return vbe;
3959
}
4060

61+
/// <summary>
62+
/// Creates a new <see cref="Mock{CodeModule}"/> with <see cref="CodeModule.get_Lines"/> and <see cref="CodeModule.CountOfLines"/>
63+
/// setup to appropriately mimic getting code out of the <see cref="CodeModule"/>.
64+
/// </summary>
65+
/// <param name="code">A block of VBA code.</param>
66+
/// <returns></returns>
4167
internal static Mock<CodeModule> CreateCodeModuleMock(string code)
4268
{
43-
var lineCount = code.Split(new string[] { Environment.NewLine }, StringSplitOptions.None).Length;
69+
var lineCount = code.Split(new [] { Environment.NewLine }, StringSplitOptions.None).Length;
4470

4571
var codeModule = new Mock<CodeModule>();
4672
codeModule.SetupGet(c => c.CountOfLines).Returns(lineCount);
73+
74+
// ReSharper disable once UseIndexedProperty
75+
// No R#, the indexed property breaks the expression. I tried that first.
4776
codeModule.SetupGet(c => c.get_Lines(1, lineCount)).Returns(code);
4877
return codeModule;
4978
}
5079

80+
/// <summary>
81+
/// Creates a new <see cref="Mock{VBComponent}"/>.
82+
/// </summary>
83+
/// <param name="name">The name to return from the <see cref="VBComponent.Name"/> property.</param>
84+
/// <param name="codeModule">The <see cref="CodeModule"/> to return from the CodeModule property.</param>
85+
/// <param name="componentType">
86+
/// The type of component to be simulated.
87+
/// Use vbext_ct_StdModule for standard modules.
88+
/// Use vbext_ct_ClassModule for classes.
89+
/// vbext_ct_ActiveXDesigner is invalid for the VBE.
90+
/// </param>
91+
/// <returns></returns>
5192
internal static Mock<VBComponent> CreateComponentMock(string name, CodeModule codeModule, vbext_ComponentType componentType)
5293
{
5394
var component = new Mock<VBComponent>();
@@ -57,16 +98,44 @@ internal static Mock<VBComponent> CreateComponentMock(string name, CodeModule co
5798
return component;
5899
}
59100

60-
internal static Mock<VBComponents> CreateComponentsMock(List<VBComponent> componentList, VBProject project)
101+
/// <summary>
102+
/// Creates a new <see cref="Mock{VBComponets}"/> that can be iterated over as an <see cref="IEnumerable"/>.
103+
/// </summary>
104+
/// <param name="componentList">The collection to be iterated over.</param>
105+
/// <returns></returns>
106+
internal static Mock<VBComponents> CreateComponentsMock(List<VBComponent> componentList)
61107
{
62108
var components = new Mock<VBComponents>();
63109
components.Setup(c => c.GetEnumerator()).Returns(componentList.GetEnumerator());
64110
components.As<IEnumerable>().Setup(c => c.GetEnumerator()).Returns(componentList.GetEnumerator());
111+
112+
return components;
113+
}
114+
115+
/// <summary>
116+
/// Creates a new <see cref="Mock{VBComponets}"/> that can be iterated over as an <see cref="IEnumerable"/>.
117+
/// </summary>
118+
/// <param name="componentList">The collection to be iterated over.</param>
119+
/// <param name="project">The <see cref="VBComponents.Parent"/> property.</param>
120+
/// <returns></returns>
121+
internal static Mock<VBComponents> CreateComponentsMock(List<VBComponent> componentList, VBProject project)
122+
{
123+
var components = CreateComponentsMock(componentList);
65124
components.SetupGet(c => c.Parent).Returns(project);
66125

67126
return components;
68127
}
69128

129+
/// <summary>
130+
/// Creates a new <see cref="Mock{VBProject}"/>.
131+
/// </summary>
132+
/// <param name="name">The <see cref="VBProject.Name"/> property.</param>
133+
/// <param name="protectionLevel">
134+
/// The <see cref="VBProject.Protection"/> property.
135+
/// Use vbext_pp_none to simulate a normal project.
136+
/// Use vbext_pp_locked to simulate a password protected, or otherwise unavailable, project.
137+
/// </param>
138+
/// <returns></returns>
70139
internal static Mock<VBProject> CreateProjectMock(string name, vbext_ProjectProtection protectionLevel)
71140
{
72141
var project = new Mock<VBProject>();
@@ -75,20 +144,18 @@ internal static Mock<VBProject> CreateProjectMock(string name, vbext_ProjectProt
75144
return project;
76145
}
77146

78-
internal static Mock<VBProjects> CreateProjectsMock(List<VBProject> projectList, VBProject project)
147+
/// <summary>
148+
/// Creates a new <see cref="Mock{VBProjects}"/> that can be iterated over as an <see cref="IEnumerable"/>.
149+
/// </summary>
150+
/// <param name="projectList">The collection to be iterated over.</param>
151+
/// <returns></returns>
152+
internal static Mock<VBProjects> CreateProjectsMock(List<VBProject> projectList)
79153
{
80154
var projects = new Mock<VBProjects>();
81155
projects.Setup(p => p.GetEnumerator()).Returns(projectList.GetEnumerator());
82156
projects.As<IEnumerable>().Setup(p => p.GetEnumerator()).Returns(projectList.GetEnumerator());
83157

84158
return projects;
85159
}
86-
87-
//internal static Mock<VBProjects> CreateProjectsMock(List<VBProject> projectList, VBProject project, VBComponents components)
88-
//{
89-
// CreateProjectsMock(projectList, project);
90-
// project.SetupGet(p => p.VBComponents).Returns(components.Object);
91-
// return projects;
92-
//}
93160
}
94161
}

RubberduckTests/Mocks/MockWindowsCollection.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@ namespace RubberduckTests.Mocks
99
/// <summary>
1010
/// Fake Windows collection to get around Moq's inability to deal with ref params.
1111
/// </summary>
12+
/// <remarks>
13+
/// The <see cref="Window"/> passed into MockWindowCollection's ctor will be returned from <see cref="CreateToolWindow"/>.
14+
/// </remarks>
1215
class MockWindowsCollection : Windows
1316
{
17+
/// <param name="window">
18+
/// Expects a window created by <see cref="MockFactory.CreateWindowMock"/>.
19+
/// This argument will be returned from <see cref="CreateToolWindow"/>.
20+
/// </param>
1421
internal MockWindowsCollection(Window window)
1522
{
1623
_window = window;

RubberduckTests/TodoExplorerTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public void Intialize()
3838
_markers = _loader.GetDefaultTodoMarkers();
3939

4040
_gridViewSorter = new GridViewSort<ToDoItem>("Priority", false);
41-
4241
}
4342

4443
[TestMethod]
@@ -62,7 +61,7 @@ Public Sub Bazzer()
6261

6362
var projectList = new List<VBProject>() {project.Object};
6463

65-
var projects = RdMockFacotry.CreateProjectsMock(projectList, project.Object);
64+
var projects = RdMockFacotry.CreateProjectsMock(projectList);
6665
project.SetupGet(p => p.VBComponents).Returns(components.Object);
6766

6867
_vbe = RdMockFacotry.CreateVbeMock(_windows, projects.Object);

0 commit comments

Comments
 (0)