Skip to content

Commit

Permalink
new test engine builds, ready for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
rubberduck203 committed Feb 22, 2015
1 parent 4295395 commit 6a3e6e2
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 17 deletions.
79 changes: 68 additions & 11 deletions RetailCoder.VBE/UI/UnitTesting/TestExplorerDockablePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ public TestExplorerDockablePresenter(IRubberduckParser parser, VBE vbe, AddIn ad
RegisterTestExplorerEvents();
}

public void Synchronize()
{
SynchronizeEngineWithIDE();
Control.Refresh(_testEngine.AllTests);
}

public void ShowExplorer()
{
Synchronize();
Control.Show();
}

public void SynchronizeEngineWithIDE()
{
try
Expand Down Expand Up @@ -64,61 +76,106 @@ private void RegisterTestExplorerEvents()
Control.OnAddExpectedErrorTestMethodButtonClick += OnExplorerAddExpectedErrorTestMethodButtonClick;
Control.OnAddTestMethodButtonClick += OnExplorerAddTestMethodButtonClick;
Control.OnAddTestModuleButtonClick += OnExplorerAddTestModuleButtonClick;

_testEngine.AllTestsComplete += AllTestsComplete;
_testEngine.TestComplete += TestComplete;
}

private void TestComplete(object sender, TestCompleteEventArg e)
{
Control.WriteResult(e.Test, e.Result);
}

private void AllTestsComplete(object sender, EventArgs e)
{
// not sure if this is really needed
}

private void OnExplorerRefreshListButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
Synchronize();
}

private void OnExplorerRunAllTestsButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
Control.ClearResults();
_testEngine.Run();
}

private void OnExplorerRunFailedTestsButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
Control.ClearResults();
_testEngine.RunFailedTests();
}

private void OnExplorerRunLastRunTestsButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
Control.ClearResults();
_testEngine.LastRunTests();
}

private void OnExplorerRunNotRunTestsButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
Control.ClearResults();
_testEngine.RunNotRunTests();
}

private void OnExplorerRunPassedTestsButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
Control.ClearResults();
_testEngine.RunPassedTests();
}

private void OnExplorerRunSelectedTestButtonClick(object sender, SelectedTestEventArgs e)
{
throw new NotImplementedException();
Control.ClearResults();
_testEngine.Run(e.Selection);
}

private void OnExplorerGoToSelectedTest(object sender, SelectedTestEventArgs e)
{
throw new NotImplementedException();
var controlSelection = e.Selection.FirstOrDefault();
if (controlSelection == null)
{
return;
}

var startLine = 1;
var startColumn = 1;
var endLine = -1;
var endColumn = -1;

var signature = string.Concat("Public Sub ", controlSelection.MethodName, "()");

var codeModule = this.VBE.VBProjects.Cast<VBProject>()
.First(project => project.Name == controlSelection.ProjectName)
.VBComponents.Cast<VBComponent>()
.First(component => component.Name == controlSelection.ModuleName)
.CodeModule;

if (codeModule.Find(signature, ref startLine, ref startColumn, ref endLine, ref endColumn))
{
var selection = new Selection(startLine, startColumn, endLine, endColumn);
codeModule.CodePane.SetSelection(selection);
}
}

private void OnExplorerAddExpectedErrorTestMethodButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
NewTestMethodCommand.NewExpectedErrorTestMethod(this.VBE);
Synchronize();
}

private void OnExplorerAddTestMethodButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
NewTestMethodCommand.NewTestMethod(this.VBE);
Synchronize();
}

private void OnExplorerAddTestModuleButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
NewUnitTestModuleCommand.NewUnitTestModule(this.VBE);
Synchronize();
}
}
}
16 changes: 14 additions & 2 deletions RetailCoder.VBE/UnitTesting/ITestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
namespace Rubberduck.UnitTesting
{
interface ITestEngine
public interface ITestEngine
{
IDictionary<TestMethod, TestResult> AllTests { get; set; }
IEnumerable<TestMethod> FailedTests();
Expand All @@ -16,7 +16,19 @@ interface ITestEngine
void RunNotRunTests();
void RunPassedTests();

event EventHandler<EventArgs> TestComplete;
event EventHandler<TestCompleteEventArg> TestComplete;
event EventHandler<EventArgs> AllTestsComplete;
}

public class TestCompleteEventArg : EventArgs
{
public TestResult Result { get; private set; }
public TestMethod Test { get; private set; }

public TestCompleteEventArg(TestMethod test, TestResult result)
{
this.Test = test;
this.Result = result;
}
}
}
2 changes: 1 addition & 1 deletion RetailCoder.VBE/UnitTesting/TestEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace Rubberduck.UnitTesting
{
public class TestEngine : IDisposable, Rubberduck.UnitTesting.ITestEngine
public class TestEngine : IDisposable
{
private readonly VBE _vbe;
private readonly TestExplorerWindow _explorer;
Expand Down
22 changes: 19 additions & 3 deletions RetailCoder.VBE/UnitTesting/TestEngine2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,20 @@ public class TestEngine2 : ITestEngine
{
private IEnumerable<TestMethod> _lastRun;

public event EventHandler<EventArgs> TestComplete;
public event EventHandler<TestCompleteEventArg> TestComplete;
public event EventHandler<EventArgs> AllTestsComplete;

//public TestEngine2()
//{
// TestComplete += TestComplete;
// AllTestsComplete += AllTestsComplete;
//}

void TestEngine2_AllTestsComplete(object sender, EventArgs e)
{
throw new NotImplementedException();
}

public IDictionary<TestMethod, TestResult> AllTests
{
get; set;
Expand Down Expand Up @@ -45,6 +56,7 @@ public IEnumerable<TestMethod> PassedTests()

public void ReRun()
{
//todo: implement or remove
throw new NotImplementedException();
}

Expand Down Expand Up @@ -98,8 +110,7 @@ private void AssignResults(IEnumerable<TestMethod> testMethods)
{
var result = test.Run();
this.AllTests[test] = result;
//todo: fix up event
TestComplete(this, EventArgs.Empty);
OnTestComplete(new TestCompleteEventArg(test, result));
}
else
{
Expand All @@ -110,5 +121,10 @@ private void AssignResults(IEnumerable<TestMethod> testMethods)
//todo: fix up event
AllTestsComplete(this, EventArgs.Empty);
}

protected virtual void OnTestComplete(TestCompleteEventArg arg)
{
TestComplete(this, arg);
}
}
}

0 comments on commit 6a3e6e2

Please sign in to comment.