Skip to content

Commit

Permalink
Merge pull request #76 from nunit-legacy/issue-75
Browse files Browse the repository at this point in the history
Create an ID filter for use by v2 framework driver
  • Loading branch information
CharliePoole authored Aug 19, 2019
2 parents b259eb5 + 591db45 commit 85eb2b5
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ os: linux
dist: trusty
mono: latest
script:
- msbuild nunit.sln /t:Rebuild /p:Configuration=Release
- msbuild nunitv2.sln /t:Rebuild /p:Configuration=Release

2 changes: 1 addition & 1 deletion build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var configuration = Argument("configuration", "Release");
// CHANGE TO SET PACKAGE AND ASSEMBLY VERSIONS
//////////////////////////////////////////////////////////////////////

var version = "2.7.0";
var version = "2.7.1";
var modifier = ""; // for example "-beta2"

var dbgSuffix = configuration == "Debug" ? "-dbg" : "";
Expand Down
5 changes: 3 additions & 2 deletions nunitv2.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.28307.421
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A65042E1-D8BC-48DD-8DE1-F0991F07EA77}"
ProjectSection(SolutionItems) = preProject
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
build.cake = build.cake
build.ps1 = build.ps1
Expand Down
4 changes: 2 additions & 2 deletions src/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:

[assembly: AssemblyVersion("2.7.0")]
[assembly: AssemblyInformationalVersion("2.7.0")]
[assembly: AssemblyVersion("2.7.1")]
[assembly: AssemblyInformationalVersion("2.7.1")]
45 changes: 45 additions & 0 deletions src/NUnitCore/interfaces/Filters/IdFilter.cs
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;
}
}
}
1 change: 1 addition & 0 deletions src/NUnitCore/interfaces/nunit.core.interfaces.dll.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<Compile Include="Extensibility\TestFramework.cs" />
<Compile Include="Filters\AndFilter.cs" />
<Compile Include="Filters\CategoryFilter.cs" />
<Compile Include="Filters\IdFilter.cs" />
<Compile Include="Filters\NameFilter.cs" />
<Compile Include="Filters\NotFilter.cs" />
<Compile Include="Filters\OrFilter.cs" />
Expand Down
109 changes: 109 additions & 0 deletions src/NUnitCore/tests/IdFilterTests.cs
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);
}
}
}
1 change: 1 addition & 0 deletions src/NUnitCore/tests/nunit.core.tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
<Compile Include="Generic\SimpleGenericFixture.cs" />
<Compile Include="Generic\SimpleGenericMethods.cs" />
<Compile Include="Generic\TypeParameterUsedWithTestMethod.cs" />
<Compile Include="IdFilterTests.cs" />
<Compile Include="IgnoreFixture.cs" />
<Compile Include="LegacySuiteTests.cs" />
<Compile Include="MaxTimeTests.cs" />
Expand Down
2 changes: 1 addition & 1 deletion src/tests/simple-assembly/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="nunit.framework" publicKeyToken="2638cd05610744eb" />
<codeBase version="2.7.0.0" href="lib\nunit.framework.dll" />
<codeBase version="2.7.1.0" href="lib\nunit.framework.dll" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Expand Down

0 comments on commit 85eb2b5

Please sign in to comment.