-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from nunit-legacy/issue-75
Create an ID filter for use by v2 framework driver
- Loading branch information
Showing
9 changed files
with
164 additions
and
7 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
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,45 @@ | ||
// **************************************************************** | ||
// Copyright 2002-2018, Charlie Poole | ||
// This is free software licensed under the NUnit license, a copy | ||
// of which should be included with this software. If not, you may | ||
// obtain a copy at https://github.com/nunit-legacy/nunitv2. | ||
// **************************************************************** | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace NUnit.Core.Filters | ||
{ | ||
/// <summary> | ||
/// Summary description for NameFilter. | ||
/// </summary> | ||
/// | ||
[Serializable] | ||
public class IdFilter : TestFilter | ||
{ | ||
private int _runnerID; | ||
private TestID _testID; | ||
|
||
/// <summary> | ||
/// Construct a IdFilter for a single TestID | ||
/// </summary> | ||
/// <param name="runnerID">The ID of the expected runner</param> | ||
/// <param name="testID">The ID of the test itself</param> | ||
public IdFilter(int runnerID, TestID testID) | ||
{ | ||
_runnerID = runnerID; | ||
_testID = testID; | ||
} | ||
|
||
/// <summary> | ||
/// Check if a test matches the filter | ||
/// </summary> | ||
/// <param name="test">The test to match</param> | ||
/// <returns>True if it matches, false if not</returns> | ||
public override bool Match(ITest test) | ||
{ | ||
return test.TestName.RunnerID == _runnerID | ||
&& test.TestName.TestID == _testID; | ||
} | ||
} | ||
} |
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,109 @@ | ||
// **************************************************************** | ||
// Copyright 2019, Charlie Poole | ||
// This is free software licensed under the NUnit license, a copy | ||
// of which should be included with this software. If not, you may | ||
// obtain a copy at https://github.com/nunit-legacy/nunitv2. | ||
// **************************************************************** | ||
|
||
using System; | ||
using System.Collections; | ||
using NUnit.Framework; | ||
using NUnit.Tests.Assemblies; | ||
using NUnit.Core.Builders; | ||
using NUnit.Core.Filters; | ||
using NUnit.Tests.Singletons; | ||
using NUnit.TestUtilities; | ||
|
||
namespace NUnit.Core.Tests | ||
{ | ||
[TestFixture] | ||
public class IdFilterTests | ||
{ | ||
private TestSuite _suite; | ||
private TestSuite _fixture; | ||
private Test _mock1; | ||
private Test _mock2; | ||
private Test _mock3; | ||
private Test _explicitTest; | ||
|
||
[SetUp] | ||
public void SetUp() | ||
{ | ||
_suite = new TestSuite("TopLevelSuite"); | ||
_fixture = TestBuilder.MakeFixture(typeof(MockTestFixture)); | ||
_suite.Add(_fixture); | ||
_mock1 = TestFinder.Find("MockTest1", _fixture, false); | ||
_mock2 = TestFinder.Find("MockTest2", _fixture, false); | ||
_mock3 = TestFinder.Find("MockTest3", _fixture, false); | ||
_explicitTest = TestFinder.Find("ExplicitlyRunTest", _fixture, false); | ||
Assert.NotNull(_mock1, "MockTest1 not found"); | ||
Assert.NotNull(_mock2, "MockTest2 not found"); | ||
Assert.NotNull(_mock3, "MockTest3 not found"); | ||
} | ||
|
||
[Test] | ||
public void TestCaseIdMatch() | ||
{ | ||
IdFilter filter = CreateIdFilter(_mock3); | ||
Assert.IsFalse(filter.Pass(_mock1), "Filter should not have passed MockTest1"); | ||
Assert.IsFalse(filter.Pass(_mock2), "Filter should not have passed MockTest2"); | ||
Assert.IsTrue(filter.Pass(_mock3), "Filter did not pass MockTest3"); | ||
Assert.IsFalse(filter.Pass(_explicitTest), "Filter should not have passed ExplicitlyRunTest"); | ||
Assert.IsTrue(filter.Pass(_fixture), "Filter did not pass MockTestFixture"); | ||
Assert.IsTrue(filter.Pass(_suite), "Filter did not pass TopLevelSuite"); | ||
} | ||
|
||
[Test] | ||
public void ExplicitTestCaseMatch() | ||
{ | ||
IdFilter filter = CreateIdFilter(_explicitTest); | ||
Assert.IsFalse(filter.Pass(_mock1), "Filter should not have passed MockTest1"); | ||
Assert.IsFalse(filter.Pass(_mock2), "Filter should not have passed MockTest2"); | ||
Assert.IsFalse(filter.Pass(_mock3), "Filter should not have passed MockTest3"); | ||
Assert.IsTrue(filter.Pass(_explicitTest), "Filter did not pass ExplicitlyRunTest"); | ||
Assert.IsTrue(filter.Pass(_fixture), "Filter did not pass MockTestFixture"); | ||
Assert.IsTrue(filter.Pass(_suite), "Filter did not pass TopLevelSuite"); | ||
} | ||
|
||
[Test] | ||
public void FixtureIdMatch() | ||
{ | ||
IdFilter filter = CreateIdFilter(_fixture); | ||
Assert.IsTrue(filter.Pass(_mock1), "Filter did not pass MockTest1"); | ||
Assert.IsTrue(filter.Pass(_mock2), "Filter did not pass MockTest2"); | ||
Assert.IsTrue(filter.Pass(_mock3), "Filter did not pass MockTest3"); | ||
Assert.IsFalse(filter.Pass(_explicitTest), "Filter should not have passed ExplicitlyRunTest"); | ||
Assert.IsTrue(filter.Pass(_fixture), "Filter did not pass MockTestFixture"); | ||
Assert.IsTrue(filter.Pass(_suite), "Filter did not pass TopLevelSuite"); | ||
} | ||
|
||
[Test] | ||
public void TopLevelIdMatch() | ||
{ | ||
IdFilter filter = CreateIdFilter(_suite); | ||
Assert.IsTrue(filter.Pass(_mock1), "Filter did not pass MockTest1"); | ||
Assert.IsTrue(filter.Pass(_mock2), "Filter did not pass MockTest2"); | ||
Assert.IsTrue(filter.Pass(_mock3), "Filter did not pass MockTest3"); | ||
Assert.IsFalse(filter.Pass(_explicitTest), "Filter should not have passed ExplicitlyRunTest"); | ||
Assert.IsTrue(filter.Pass(_fixture), "Filter did not pass MockTestFixture"); | ||
Assert.IsTrue(filter.Pass(_suite), "Filter did not pass TopLevelSuite"); | ||
} | ||
|
||
[Test] | ||
public void MulitpleTestCaseIdMatch() | ||
{ | ||
OrFilter filter = new OrFilter(CreateIdFilter(_mock1), CreateIdFilter(_mock3)); | ||
Assert.IsTrue(filter.Pass(_mock1), "Filter did not pass MockTest1"); | ||
Assert.IsFalse(filter.Pass(_mock2), "Filter should not have passed MockTest2"); | ||
Assert.IsTrue(filter.Pass(_mock3), "Filter did not pass MockTest3"); | ||
Assert.IsFalse(filter.Pass(_explicitTest), "Filter should not have passed ExplicitlyRunTest"); | ||
Assert.IsTrue(filter.Pass(_fixture), "Filter did not pass MockTestFixture"); | ||
Assert.IsTrue(filter.Pass(_suite), "Filter did not pass TopLevelSuite"); | ||
} | ||
|
||
private IdFilter CreateIdFilter(Test test) | ||
{ | ||
return new IdFilter(test.TestName.RunnerID, test.TestName.TestID); | ||
} | ||
} | ||
} |
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