forked from rubberduck-vba/Rubberduck
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c5ff88
commit 4295395
Showing
5 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |