Skip to content

Commit

Permalink
created new TestEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
rubberduck203 committed Feb 22, 2015
1 parent 6c5ff88 commit 4295395
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 2 deletions.
2 changes: 2 additions & 0 deletions RetailCoder.VBE/Rubberduck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@
</Compile>
<Compile Include="UI\Refactorings\ExtractMethod\ValueChangedEventArgs.cs" />
<Compile Include="UI\ToDoItems\IToDoExplorerWindow.cs" />
<Compile Include="UnitTesting\ITestEngine.cs" />
<Compile Include="UnitTesting\TestEngine2.cs" />
<Compile Include="VBA\Nodes\OptionNode.cs" />
<Compile Include="VBA\Nodes\EnumNode.cs" />
<Compile Include="VBA\Nodes\DeclaredIdentifierNode.cs" />
Expand Down
26 changes: 25 additions & 1 deletion RetailCoder.VBE/UI/UnitTesting/TestExplorerDockablePresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
using Microsoft.Vbe.Interop;
using Rubberduck.VBA;
using Rubberduck.VBA.Grammar;
using Rubberduck.UnitTesting;
using Rubberduck.UI.UnitTesting;
using Rubberduck.Extensions;

namespace Rubberduck.UI.UnitTesting
{
Expand All @@ -16,14 +19,35 @@ public class TestExplorerDockablePresenter : DockablePresenterBase

private readonly IRubberduckParser _parser;
private TestExplorerWindow Control { get { return UserControl as TestExplorerWindow; } }
private readonly ITestEngine _testEngine;

public TestExplorerDockablePresenter(IRubberduckParser parser, VBE vbe, AddIn addin, IDockableUserControl control)
public TestExplorerDockablePresenter(IRubberduckParser parser, VBE vbe, AddIn addin, IDockableUserControl control, ITestEngine testEngine)
: base(vbe, addin, control)
{
_parser = parser;
_testEngine = testEngine;
RegisterTestExplorerEvents();
}

public void SynchronizeEngineWithIDE()
{
try
{
_testEngine.AllTests = this.VBE.VBProjects
.Cast<VBProject>()
.SelectMany(project => project.TestMethods())
.ToDictionary(test => test, test => _testEngine.AllTests.ContainsKey(test) ? _testEngine.AllTests[test] : null);

}
catch (ArgumentException)
{
System.Windows.Forms.MessageBox.Show(
"Two or more projects containing test methods have the same name and identically named tests. Please rename one to continue.",
"Warning", System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Exclamation);
}
}

private void RegisterTestExplorerEvents()
{
Control.OnRefreshListButtonClick += OnExplorerRefreshListButtonClick;
Expand Down
22 changes: 22 additions & 0 deletions RetailCoder.VBE/UnitTesting/ITestEngine.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
namespace Rubberduck.UnitTesting
{
interface ITestEngine
{
IDictionary<TestMethod, TestResult> AllTests { get; set; }
IEnumerable<TestMethod> FailedTests();
IEnumerable<TestMethod> LastRunTests(TestOutcome? outcome = null);
IEnumerable<TestMethod> NotRunTests();
IEnumerable<TestMethod> PassedTests();
void ReRun();
void Run();
void Run(System.Collections.Generic.IEnumerable<TestMethod> tests);
void RunFailedTests();
void RunNotRunTests();
void RunPassedTests();

event EventHandler<EventArgs> TestComplete;
event EventHandler<EventArgs> AllTestsComplete;
}
}
3 changes: 2 additions & 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
public class TestEngine : IDisposable, Rubberduck.UnitTesting.ITestEngine
{
private readonly VBE _vbe;
private readonly TestExplorerWindow _explorer;
Expand Down Expand Up @@ -106,6 +106,7 @@ public IEnumerable<TestMethod> LastRunTests(TestOutcome? outcome = null)
/// <summary>
/// Finds all tests in all opened projects.
/// </summary>
//note: belongs in presenter
public void SynchronizeTests()
{
try
Expand Down
114 changes: 114 additions & 0 deletions RetailCoder.VBE/UnitTesting/TestEngine2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rubberduck.UnitTesting
{
public class TestEngine2 : ITestEngine
{
private IEnumerable<TestMethod> _lastRun;

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

public IDictionary<TestMethod, TestResult> AllTests
{
get; set;
}

public IEnumerable<TestMethod> FailedTests()
{
return this.AllTests.Where(test => test.Value != null && test.Value.Outcome == TestOutcome.Failed)
.Select(test => test.Key);
}

public IEnumerable<TestMethod> LastRunTests(TestOutcome? outcome = null)
{
return this.AllTests.Where(test => test.Value != null
&& test.Value.Outcome == (outcome ?? test.Value.Outcome))
.Select(test => test.Key);
}

public IEnumerable<TestMethod> NotRunTests()
{
return this.AllTests.Where(test => test.Value == null)
.Select(test => test.Key);
}

public IEnumerable<TestMethod> PassedTests()
{
return this.AllTests.Where(test => test.Value != null && test.Value.Outcome == TestOutcome.Succeeded)
.Select(test => test.Key);
}

public void ReRun()
{
throw new NotImplementedException();
}

public void Run()
{
if (!this.AllTests.Any())
{
_lastRun = null;
return;
}

Run(this.AllTests.Keys);
}

public void Run(IEnumerable<TestMethod> tests)
{
if (tests.Any())
{
var methods = tests.ToDictionary(test => test, test => null as TestResult);
AssignResults(methods.Keys);
_lastRun = methods.Keys;
}
else
{
_lastRun = null;
}
}

public void RunFailedTests()
{
Run(FailedTests());
}

public void RunNotRunTests()
{
Run(NotRunTests());
}

public void RunPassedTests()
{
Run(PassedTests());
}

private void AssignResults(IEnumerable<TestMethod> testMethods)
{
var tests = testMethods.ToList();
var keys = this.AllTests.Keys.ToList();
foreach (var test in keys)
{
if (tests.Contains(test))
{
var result = test.Run();
this.AllTests[test] = result;
//todo: fix up event
TestComplete(this, EventArgs.Empty);
}
else
{
this.AllTests[test] = null;
}
}

//todo: fix up event
AllTestsComplete(this, EventArgs.Empty);
}
}
}

0 comments on commit 4295395

Please sign in to comment.