Skip to content

Commit de78535

Browse files
committed
Removed Reference Ensurance tests; gave up on testing it at the TestExplorer; made some ohter changes that will make it easier to test it after an overhaul. Too many dependencies and static methods.
1 parent 2c6d518 commit de78535

File tree

5 files changed

+50
-115
lines changed

5 files changed

+50
-115
lines changed

RetailCoder.VBE/UI/DockableWindowHost.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ internal void AddUserControl(UserControl control)
4848

4949
if (control != null)
5050
{
51-
control.Dock = DockStyle.Fill;
52-
Controls.Add(control);
51+
control.Dock = DockStyle.Fill;
52+
Controls.Add(control);
5353
}
5454
AdjustSize();
5555
}

RetailCoder.VBE/UI/UnitTesting/TestExplorerDockablePresenter.cs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ namespace Rubberduck.UI.UnitTesting
1313
{
1414
public class TestExplorerDockablePresenter : DockablePresenterBase
1515
{
16-
private ITestExplorerWindow Control { get { return UserControl as ITestExplorerWindow; } }
17-
private GridViewSort<TestExplorerItem> _gridViewSort;
16+
private readonly GridViewSort<TestExplorerItem> _gridViewSort;
1817
private readonly ITestEngine _testEngine;
18+
private readonly ITestExplorerWindow _view;
1919

20-
public TestExplorerDockablePresenter(VBE vbe, AddIn addin, IDockableUserControl control, ITestEngine testEngine, GridViewSort<TestExplorerItem> gridViewSort)
20+
public TestExplorerDockablePresenter(VBE vbe, AddIn addin, ITestExplorerWindow control, ITestEngine testEngine, GridViewSort<TestExplorerItem> gridViewSort)
2121
: base(vbe, addin, control)
2222
{
2323
_testEngine = testEngine;
@@ -28,18 +28,19 @@ public TestExplorerDockablePresenter(VBE vbe, AddIn addin, IDockableUserControl
2828
_testEngine.MethodInitialize += TestEngineMethodInitialize;
2929
_testEngine.MethodCleanup += TestEngineMethodCleanup;
3030

31-
Control.SortColumn += SortColumn;
31+
_view = control;
32+
_view.SortColumn += SortColumn;
3233

3334
RegisterTestExplorerEvents();
3435
}
3536

3637
private void SortColumn(object sender, DataGridViewCellMouseEventArgs e)
3738
{
38-
var columnName = Control.GridView.Columns[e.ColumnIndex].Name;
39+
var columnName = _view.GridView.Columns[e.ColumnIndex].Name;
3940

4041
// type "Image" doesn't implement "IComparable", so we need to sort by the outcome instead
4142
if (columnName == RubberduckUI.Result) { columnName = RubberduckUI.Outcome; }
42-
Control.AllTests = new BindingList<TestExplorerItem>(_gridViewSort.Sort(Control.AllTests.AsEnumerable(), columnName).ToList());
43+
_view.AllTests = new BindingList<TestExplorerItem>(_gridViewSort.Sort(_view.AllTests.AsEnumerable(), columnName).ToList());
4344
}
4445

4546

@@ -70,7 +71,7 @@ private void _testEngine_ModuleInitialize(object sender, TestModuleEventArgs e)
7071
private void Synchronize()
7172
{
7273
FindAllTests();
73-
Control.Refresh(_testEngine.AllTests);
74+
_view.Refresh(_testEngine.AllTests);
7475
}
7576

7677
public override void Show()
@@ -105,12 +106,12 @@ public void RunTests()
105106

106107
public void RunTests(IEnumerable<TestMethod> tests)
107108
{
108-
Control.ClearResults();
109+
_view.ClearResults();
109110

110111
var testMethods = tests as IList<TestMethod> ?? tests.ToList(); //bypasses multiple enumeration
111-
Control.SetPlayList(testMethods);
112+
_view.SetPlayList(testMethods);
112113

113-
Control.ClearProgress();
114+
_view.ClearProgress();
114115

115116
var projects = testMethods.Select(t => t.QualifiedMemberName.QualifiedModuleName.Project).Distinct();
116117
foreach (var project in projects)
@@ -123,7 +124,7 @@ public void RunTests(IEnumerable<TestMethod> tests)
123124

124125
private void TestComplete(object sender, TestCompletedEventArgs e)
125126
{
126-
Control.WriteResult(e.Test, e.Result);
127+
_view.WriteResult(e.Test, e.Result);
127128
}
128129

129130
private void OnExplorerRefreshListButtonClick(object sender, EventArgs e)
@@ -229,20 +230,20 @@ private void OnExplorerAddTestModuleButtonClick(object sender, EventArgs e)
229230

230231
private void RegisterTestExplorerEvents()
231232
{
232-
Control.OnRefreshListButtonClick += OnExplorerRefreshListButtonClick;
233+
_view.OnRefreshListButtonClick += OnExplorerRefreshListButtonClick;
233234

234-
Control.OnRunAllTestsButtonClick += OnExplorerRunAllTestsButtonClick;
235-
Control.OnRunFailedTestsButtonClick += OnExplorerRunFailedTestsButtonClick;
236-
Control.OnRunLastRunTestsButtonClick += OnExplorerRunLastRunTestsButtonClick;
237-
Control.OnRunNotRunTestsButtonClick += OnExplorerRunNotRunTestsButtonClick;
238-
Control.OnRunPassedTestsButtonClick += OnExplorerRunPassedTestsButtonClick;
239-
Control.OnRunSelectedTestButtonClick += OnExplorerRunSelectedTestButtonClick;
235+
_view.OnRunAllTestsButtonClick += OnExplorerRunAllTestsButtonClick;
236+
_view.OnRunFailedTestsButtonClick += OnExplorerRunFailedTestsButtonClick;
237+
_view.OnRunLastRunTestsButtonClick += OnExplorerRunLastRunTestsButtonClick;
238+
_view.OnRunNotRunTestsButtonClick += OnExplorerRunNotRunTestsButtonClick;
239+
_view.OnRunPassedTestsButtonClick += OnExplorerRunPassedTestsButtonClick;
240+
_view.OnRunSelectedTestButtonClick += OnExplorerRunSelectedTestButtonClick;
240241

241-
Control.OnGoToSelectedTest += OnExplorerGoToSelectedTest;
242+
_view.OnGoToSelectedTest += OnExplorerGoToSelectedTest;
242243

243-
Control.OnAddExpectedErrorTestMethodButtonClick += OnExplorerAddExpectedErrorTestMethodButtonClick;
244-
Control.OnAddTestMethodButtonClick += OnExplorerAddTestMethodButtonClick;
245-
Control.OnAddTestModuleButtonClick += OnExplorerAddTestModuleButtonClick;
244+
_view.OnAddExpectedErrorTestMethodButtonClick += OnExplorerAddExpectedErrorTestMethodButtonClick;
245+
_view.OnAddTestMethodButtonClick += OnExplorerAddTestMethodButtonClick;
246+
_view.OnAddTestModuleButtonClick += OnExplorerAddTestModuleButtonClick;
246247

247248
_testEngine.TestComplete += TestComplete;
248249
}

RubberduckTests/Mocks/MockFactory.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,30 @@ internal static Mock<VBProjects> CreateProjectsMock(List<VBProject> projectList,
9090
// project.SetupGet(p => p.VBComponents).Returns(components.Object);
9191
// return projects;
9292
//}
93+
94+
internal static Mock<Reference> CreateMockReference(string name, string filePath)
95+
{
96+
var reference = new Mock<Reference>();
97+
reference.SetupGet(r => r.Name).Returns(name);
98+
reference.SetupGet(r => r.FullPath).Returns(filePath);
99+
100+
return reference;
101+
}
102+
103+
internal static Mock<References> CreateReferencesMock(List<Reference> referenceList)
104+
{
105+
var references = new Mock<References>();
106+
references.Setup(r => r.GetEnumerator()).Returns(referenceList.GetEnumerator());
107+
references.As<IEnumerable>().Setup(r => r.GetEnumerator()).Returns(referenceList.GetEnumerator());
108+
return references;
109+
}
110+
111+
internal static Mock<VBProject> CreateProjectMock(string name, Mock<References> references)
112+
{
113+
var project = new Mock<VBProject>();
114+
project.SetupProperty(p => p.Name, name);
115+
project.SetupGet(p => p.References).Returns(references.Object);
116+
return project;
117+
}
93118
}
94119
}

RubberduckTests/RubberduckTests.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@
186186
<Compile Include="StringExtensionsTests.cs" />
187187
<Compile Include="Properties\AssemblyInfo.cs" />
188188
<Compile Include="ConfigurationTests.cs" />
189-
<Compile Include="TodoExplorerTests.cs" />
190189
<Compile Include="UnitTesting\AssertTests.cs" />
191190
<Compile Include="CodeInspectionTests.cs" />
192191
<Compile Include="TodoControllerTests.cs" />

RubberduckTests/UnitTesting/EngineTests.cs

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ public class EngineTests
1515
{
1616
private TestEngine _engine;
1717
private Mock<IHostApplication> _hostAppMock;
18-
private Mock<VBProject> _project;
19-
private Mock<References> _references;
2018
private readonly QualifiedModuleName _moduleName = new QualifiedModuleName("VBAProject", "TestModule1");
2119

2220
private TestMethod _successfulMethod;
@@ -36,15 +34,6 @@ public void Initialize()
3634
_engine = new TestEngine();
3735
_hostAppMock = new Mock<IHostApplication>();
3836

39-
_references = new Mock<References>();
40-
_references.Setup(r => r.GetEnumerator()).Returns(ReferenceList());
41-
_references.As<IEnumerable>().Setup(r => r.GetEnumerator()).Returns(ReferenceList);
42-
_references.Setup(r => r.AddFromFile(It.IsAny<string>()));
43-
44-
_project = new Mock<VBProject>();
45-
_project.SetupProperty(p => p.Name, "VBAProject");
46-
_project.SetupGet(p => p.References).Returns(_references.Object);
47-
4837
_successfulMethod = new TestMethod(new QualifiedMemberName(_moduleName, "TestMethod1"), _hostAppMock.Object);
4938
_failedMethod = new TestMethod(new QualifiedMemberName(_moduleName, "TestMethod2"), _hostAppMock.Object);
5039
_inconclusiveMethod = new TestMethod(new QualifiedMemberName(_moduleName, "TestMethod3"), _hostAppMock.Object);
@@ -61,30 +50,6 @@ public void Initialize()
6150
_engine.AllTests = tests;
6251
}
6352

64-
private static IEnumerator<Reference> ReferenceList()
65-
{
66-
yield return
67-
CreateMockReference("VBA", @"C:\Program Files\Common Files\Microsoft Shared\VBA\VBA7.1\VBE7.DLL").Object;
68-
69-
yield return
70-
CreateMockReference("Excel", @"C:\Program Files\Microsoft Office 15\Root\Office15\EXCEL.EXE").Object;
71-
72-
yield return
73-
CreateMockReference("stdole", @"C:\Windows\System32\stdole2.tlb").Object;
74-
75-
yield return
76-
CreateMockReference("Office", @"C:\Program Files\Common Files\Microsoft Shared\Office15\MSO.DLL").Object;
77-
}
78-
79-
private static Mock<Reference> CreateMockReference(string name, string filePath)
80-
{
81-
var reference = new Mock<Reference>();
82-
reference.SetupGet(r => r.Name).Returns(name);
83-
reference.SetupGet(r => r.FullPath).Returns(filePath);
84-
85-
return reference;
86-
}
87-
8853
[TestMethod]
8954
public void TestEngine_FailedTests()
9055
{
@@ -232,61 +197,6 @@ public void TestEngine_Run_WhenTestListIsEmpty_Bail()
232197
Assert.IsFalse(_wasEventRaised, "No methods should run when passed an empty list of tests.");
233198
}
234199

235-
//todo: move this to the "UI" layer. This code doesn't have to run for COM clients.
236-
// COM clients will have to either already have a good reference, or be late bound.
237-
// This is problematic for late bound code, because now we've *forced* them into early binding.
238-
[TestMethod]
239-
public void TestEngine_AfterRun_OldRubberduckReferenceIsRemoved()
240-
{
241-
var vbaRef = CreateMockReference("VBA", @"C:\Path\To\VBA.DLL");
242-
var rubberduckPath = @"C:\Path\To\Rubberduck.dll";
243-
var oldRubberduckRef = CreateMockReference("Rubberduck", rubberduckPath);
244-
245-
var refrenceList = new List<Reference>() {vbaRef.Object, oldRubberduckRef.Object};
246-
247-
var references = new Mock<References>();
248-
references.Setup(r => r.GetEnumerator()).Returns(refrenceList.GetEnumerator());
249-
references.As<IEnumerable>().Setup(r => r.GetEnumerator()).Returns(refrenceList.GetEnumerator());
250-
references.Setup(r => r.AddFromFile(It.IsAny<string>()));
251-
252-
var project = new Mock<VBProject>();
253-
project.SetupProperty(p => p.Name, "VBAProject");
254-
project.SetupGet(p => p.References).Returns(references.Object);
255-
256-
//act
257-
_engine.Run(_engine.AllTests.Keys);
258-
259-
//assert
260-
references.Verify(r => r.Remove(It.Is<Reference>(arg => arg == oldRubberduckRef.Object)));
261-
}
262-
263-
//todo: move this to the "UI" layer. This code doesn't have to run for COM clients.
264-
// COM clients will have to either already have a good reference, or be late bound.
265-
// This is problematic for late bound code, because now we've *forced* them into early binding.
266-
[TestMethod]
267-
public void TestEngine_AfterRun_NewRubberduckReferenceExists()
268-
{
269-
var vbaRef = CreateMockReference("VBA", @"C:\Path\To\VBA.DLL");
270-
var rubberduckPath = @"C:\Path\To\Rubberduck.dll";
271-
var oldRubberduckRef = CreateMockReference("Rubberduck", rubberduckPath);
272-
273-
var refrenceList = new List<Reference>() { vbaRef.Object, oldRubberduckRef.Object };
274-
275-
var references = new Mock<References>();
276-
references.Setup(r => r.GetEnumerator()).Returns(refrenceList.GetEnumerator());
277-
references.As<IEnumerable>().Setup(r => r.GetEnumerator()).Returns(refrenceList.GetEnumerator());
278-
279-
var project = new Mock<VBProject>();
280-
project.SetupProperty(p => p.Name, "VBAProject");
281-
project.SetupGet(p => p.References).Returns(references.Object);
282-
283-
//act
284-
_engine.Run(_engine.AllTests.Keys);
285-
286-
//assert
287-
references.Verify(r => r.AddFromFile(It.IsAny<string>()));
288-
}
289-
290200
private void EngineOnTestComplete(object sender, TestCompletedEventArgs testCompletedEventArgs)
291201
{
292202
CatchEvent();

0 commit comments

Comments
 (0)