Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TestSelection class to implement IEnumerable interface #1136

Merged
merged 5 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/testcentric-gui-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: TestCentric.GuiRunner.CI

on:
workflow_dispatch:
pull_request:
push:
paths-ignore:
- "*.txt"
- "*.md"

env:
DOTNET_NOLOGO: true # Disable the .NET logo
DOTNET_CLI_TELEMETRY_OPTOUT: true # Disable sending .NET CLI telemetry

jobs:
ContinuousIntegration:
name: Continuous Integration
runs-on: windows-latest

env:
TESTCENTRIC_MYGET_API_KEY: ${{ secrets.TESTCENTRIC_MYGET_API_KEY }}
TESTCENTRIC_NUGET_API_KEY: ${{ secrets.TESTCENTRIC_NUGET_API_KEY }}
TESTCENTRIC_CHOCO_API_KEY: ${{ secrets.TESTCENTRIC_CHOCO_API_KEY }}
GITHUB_ACCESS_TOKEN: ${{ secrets.TESTCENTRIC_GITHUB_ACCESS_TOKEN }}

steps:
- name: ⤵️ Checkout Source
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: 🛠️ Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
2.1.x
3.1.x
5.0.x
6.0.x
7.0.x
8.0.x

- name: 🔧 Install dotnet tools
run: dotnet tool restore

- name: 🍰 Run cake
env:
TESTCENTRIC_MYGET_API_KEY: ${{ secrets.TESTCENTRIC_MYGET_API_KEY }}
TESTCENTRIC_NUGET_API_KEY: ${{ secrets.TESTCENTRIC_NUGET_API_KEY }}
TESTCENTRIC_CHOCO_API_KEY: ${{ secrets.TESTCENTRIC_CHOCO_API_KEY }}
GITHUB_ACCESS_TOKEN: ${{ secrets.TESTCENTRIC_GITHUB_ACCESS_TOKEN }}

# If you need to get more verbose logging, add the following to the dotnet-cake above: --verbosity=diagnostic
run: dotnet cake --target=ContinuousIntegration --configuration=Release

- name: 🪵 Upload build logs
if: always()
uses: actions/upload-artifact@v4
with:
name: Upload Console Logs
# This path is defined in build-settings.cake
path: "build-results/*.binlog"
# if-no-files-found: error

- name: 🪵 Upload InternalTrace logs
if: always()
uses: actions/upload-artifact@v4
with:
name: InternalTraceLogs
# This path is defined in build-settings.cake
path: "*.log"
# if-no-files-found: error

- name: 💾 Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: "Test Results"
path: test-results
16 changes: 8 additions & 8 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ var nugetPackage = new NuGetPackage(
"Images/Tree/Visual Studio/Success.png", "Images/Tree/Visual Studio/Failure.png", "Images/Tree/Visual Studio/Ignored.png", "Images/Tree/Visual Studio/Inconclusive.png", "Images/Tree/Visual Studio/Skipped.png") )
.WithDependencies(
KnownExtensions.Net462PluggableAgent.NuGetPackage.LatestDevBuild,
KnownExtensions.Net60PluggableAgent.NuGetPackage.LatestRelease,
KnownExtensions.Net70PluggableAgent.NuGetPackage.LatestRelease,
KnownExtensions.Net80PluggableAgent.NuGetPackage.LatestRelease
),
KnownExtensions.Net60PluggableAgent.NuGetPackage.LatestDevBuild,
KnownExtensions.Net70PluggableAgent.NuGetPackage.LatestDevBuild,
KnownExtensions.Net80PluggableAgent.NuGetPackage.LatestDevBuild
),
testRunner: new GuiSelfTester(BuildSettings.NuGetTestDirectory + "TestCentric.GuiRunner." + BuildSettings.PackageVersion + "/tools/testcentric.exe"),
checks: new PackageCheck[] {
HasFiles("CHANGES.txt", "LICENSE.txt", "NOTICES.txt", "testcentric.png"),
Expand Down Expand Up @@ -114,10 +114,10 @@ var chocolateyPackage = new ChocolateyPackage(
"Images/Tree/Visual Studio/Success.png", "Images/Tree/Visual Studio/Failure.png", "Images/Tree/Visual Studio/Ignored.png", "Images/Tree/Visual Studio/Inconclusive.png", "Images/Tree/Visual Studio/Skipped.png") )
.WithDependencies(
KnownExtensions.Net462PluggableAgent.ChocoPackage.LatestDevBuild,
KnownExtensions.Net60PluggableAgent.ChocoPackage.LatestRelease,
KnownExtensions.Net70PluggableAgent.ChocoPackage.LatestRelease,
KnownExtensions.Net80PluggableAgent.ChocoPackage.LatestRelease
),
KnownExtensions.Net60PluggableAgent.ChocoPackage.LatestDevBuild,
KnownExtensions.Net70PluggableAgent.ChocoPackage.LatestDevBuild,
KnownExtensions.Net80PluggableAgent.ChocoPackage.LatestDevBuild
),
testRunner: new GuiSelfTester(BuildSettings.ChocolateyTestDirectory + "testcentric-gui." + BuildSettings.PackageVersion + "/tools/testcentric.exe"),
checks: new PackageCheck[] {
HasDirectory("tools").WithFiles("CHANGES.txt", "LICENSE.txt", "NOTICES.txt", "VERIFICATION.txt", "testcentric.choco.addins").AndFiles(GUI_FILES).AndFiles(ENGINE_FILES).AndFile("testcentric.choco.addins"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace TestCentric.Gui.Presenters
using Views;
using Elements;
using System.IO;
using System.Linq;

/// <summary>
/// DisplayStrategy is the abstract base for the various
Expand Down Expand Up @@ -167,7 +168,7 @@ public TreeNode MakeTreeNode(TestNode testNode, bool recursive)

public string GroupDisplayName(TestGroup group)
{
return string.Format("{0} ({1})", group.Name, group.Count);
return string.Format("{0} ({1})", group.Name, group.Count());
}

public static int CalcImageIndex(ResultState outcome)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace TestCentric.Gui.Presenters
{
using System.Linq;
using Model;
using Views;

Expand Down Expand Up @@ -121,7 +122,7 @@ public void ApplyResultToGroup(ResultNode result)
treeNode.Remove();

// If it was last test in group, remove group
if (oldGroup.Count == 0)
if (oldGroup.Count() == 0)
oldParent.Remove();
else // update old group
{
Expand All @@ -132,12 +133,12 @@ public void ApplyResultToGroup(ResultNode result)
newParent.Text = GroupDisplayName(newGroup);
newParent.Expand();

if (newGroup.Count == 1)
if (newGroup.Count() == 1)
{
_view.Clear();
TreeNode topNode = null;
foreach (var group in _grouping.Groups)
if (group.Count > 0)
if (group.Count() > 0)
{
Add(group.TreeNode);
if (topNode == null)
Expand Down Expand Up @@ -188,7 +189,7 @@ protected void UpdateDisplay()
var treeNode = MakeTreeNode(group, true);
group.TreeNode = treeNode;
treeNode.Expand();
if (group.Count > 0)
if (group.Count() > 0)
{
_view.Add(treeNode);
if (topNode == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void WireUpEvents()
var selection = new TestSelection();

foreach (var node in checkedNodes)
selection.Add(node.Tag as TestNode);
selection.Add(node.Tag as ITestItem);

_model.SelectedTests = selection;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace TestCentric.Gui.Presenters
{
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using NSubstitute;
using NUnit.Framework;
Expand Down Expand Up @@ -200,7 +201,7 @@ private static void AssertTreeNodeAndTestGroup(List<TreeNode> treeNodes, string
// Assert testGroup
TestGroup testGroup = treeNode.Tag as TestGroup;
Assert.That(testGroup, Is.Not.Null);
Assert.That(testGroup.Count, Is.EqualTo(expectedInGroup));
Assert.That(testGroup.Count(), Is.EqualTo(expectedInGroup));
}

private string CreateTestFixtureXml(string testId, string category)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace TestCentric.Gui.Presenters
{
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
using NSubstitute;
Expand Down Expand Up @@ -287,7 +288,7 @@ private static void AssertTreeNodeAndTestGroup(List<TreeNode> treeNodes, string
// Assert testGroup
TestGroup testGroup = treeNode.Tag as TestGroup;
Assert.That(testGroup, Is.Not.Null);
Assert.That(testGroup.Count, Is.EqualTo(expectedInGroup));
Assert.That(testGroup.Count(), Is.EqualTo(expectedInGroup));
}

private string CreateTestcaseXml(string testId, string category)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ***********************************************************************

using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using NSubstitute;
using NUnit.Framework;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void WhenCheckedNodesChange_SelectedTestsAreSet()
_view.CheckedNodes.Returns(new List<TreeNode>( new[] { TEST_CASE_TREE_NODE }));

_view.AfterCheck += Raise.Event<TreeNodeActionHandler>(TEST_CASE_TREE_NODE);
_model.Received().SelectedTests = Arg.Is<TestSelection>(s => s.Count == 1 && s.Contains(TEST_CASE_NODE));
_model.Received().SelectedTests = Arg.Is<TestSelection>(s => s.Count() == 1 && s.Contains(TEST_CASE_NODE));
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace TestCentric.Gui.Presenters.TestTree
{
using System.Linq;
using Elements;
using TestCentric.Gui.Model;
using Views;
Expand Down Expand Up @@ -52,7 +53,7 @@ public void WhenSelectedNodeChanges_ActiveItemIsSet(TreeNode treeNode, TestNode
public void WhenSelectedNodeChanges_SelectedTestsAreSet(TreeNode treeNode, TestNode testNode)
{
_view.SelectedNodeChanged += Raise.Event<TreeNodeActionHandler>(treeNode);
_model.Received().SelectedTests = Arg.Is<TestSelection>(s => s.Count == 1 && s[0] == testNode);
_model.Received().SelectedTests = Arg.Is<TestSelection>(s => s.Count() == 1 && s.First() == testNode);
}
}
}
101 changes: 101 additions & 0 deletions src/TestCentric/tests/Presenters/TestTree/TreeViewPresenterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using TestCentric.Gui.Model;
using System;
using System.Runtime.InteropServices;
using TestCentric.Gui.Views;
using System.Collections.Generic;
using System.Linq;

namespace TestCentric.Gui.Presenters.TestTree
{
Expand Down Expand Up @@ -92,6 +95,104 @@ public void WhenContextMenuIsDisplayed_DebugCommand_EnabledState_IsUpdated(bool
Assert.That(_view.DebugContextCommand.Enabled, Is.EqualTo(expectedEnabled));
}

[Test]
public void TreeCheckBoxClicked_NoNodeSelected_SelectedTestsInModel_AreEmpty()
{
// 1. Arrange
IList<TreeNode> checkedNodes = new List<TreeNode>();
_view.CheckedNodes.Returns(checkedNodes);

// 2. Act
_view.AfterCheck += Raise.Event<TreeNodeActionHandler>((TreeNode)null);

// 3. Assert
TestSelection testSelection = _model.SelectedTests;
Assert.That(testSelection, Is.Empty);
}

[Test]
public void TreeCheckBoxClicked_TreeNodesAreSelected_AllTests_AreSelected()
{
// 1. Arrange
var treeNode1 = new TreeNode() { Tag = new TestNode("<test-case id='1' />") };
var treeNode2 = new TreeNode() { Tag = new TestNode("<test-case id='2' />") };

IList<TreeNode> checkedNodes = new List<TreeNode>() { treeNode1, treeNode2 };
_view.CheckedNodes.Returns(checkedNodes);

// 2. Act
_view.AfterCheck += Raise.Event<TreeNodeActionHandler>((TreeNode)null);

// 3. Assert
TestSelection testSelection = _model.SelectedTests;
Assert.That(testSelection.Count(), Is.EqualTo(2));
}

[Test]
public void TreeCheckBoxClicked_GroupIsSelected_AllTestsOfGroup_AreSelected()
{
// 1. Arrange
var subTestNode1 = new TestNode("<test-case id='2' />");
var subTestNode2 = new TestNode("<test-case id='3' />");
var testGroup = new TestGroup("Category_1") { subTestNode1, subTestNode2 };

var treeNode1 = new TreeNode() { Tag = testGroup };

IList<TreeNode> checkedNodes = new List<TreeNode>() { treeNode1 };
_view.CheckedNodes.Returns(checkedNodes);

// 2. Act
_view.AfterCheck += Raise.Event<TreeNodeActionHandler>((TreeNode)null);

// 3. Assert
TestSelection testSelection = _model.SelectedTests;
Assert.That(testSelection.Count(), Is.EqualTo(2));
}

[Test]
public void TreeCheckBoxClicked_TreeNodeAndGroupIsSelected_AllTests_AreSelected()
{
// 1. Arrange
var subTestNode1 = new TestNode("<test-case id='1' />");
var subTestNode2 = new TestNode("<test-case id='2' />");
var testGroup = new TestGroup("Category_1") { subTestNode1, subTestNode2 };

var treeNode1 = new TreeNode() { Tag = testGroup };
var treeNode2 = new TreeNode() { Tag = new TestNode("<test-case id='3' />") };

IList<TreeNode> checkedNodes = new List<TreeNode>() { treeNode1, treeNode2 };
_view.CheckedNodes.Returns(checkedNodes);

// 2. Act
_view.AfterCheck += Raise.Event<TreeNodeActionHandler>((TreeNode)null);

// 3. Assert
TestSelection testSelection = _model.SelectedTests;
Assert.That(testSelection.Count(), Is.EqualTo(3));
}

[Test]
public void TreeCheckBoxClicked_TreeNodeInsideGroupIsSelected_AllTests_AreSelected()
{
// 1. Arrange
var subTestNode1 = new TestNode("<test-case id='1' />");
var subTestNode2 = new TestNode("<test-case id='2' />");
var testGroup = new TestGroup("Category_1") { subTestNode1, subTestNode2 };

var treeNode1 = new TreeNode() { Tag = testGroup };
var treeNode2 = new TreeNode() { Tag = subTestNode1 };

IList<TreeNode> checkNodes = new List<TreeNode>() { treeNode1, treeNode2 };
_view.CheckedNodes.Returns(checkNodes);

// 2. Act
_view.AfterCheck += Raise.Event<TreeNodeActionHandler>((TreeNode)null);

// 3. Assert
TestSelection testSelection = _model.SelectedTests;
Assert.That(testSelection.Count(), Is.EqualTo(2));
}

// TODO: Version 1 Test - Make it work if needed.
//[Test]
//public void WhenContextNodeIsNotNull_RunCommandExecutesThatTest()
Expand Down
2 changes: 1 addition & 1 deletion src/TestModel/model/TestCentric.Gui.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<ItemGroup>
<PackageReference Include="Mono.Options" Version="6.12.0.148" />
<PackageReference Include="TestCentric.Engine" Version="2.0.0-dev00023" />
<PackageReference Include="TestCentric.Engine.Api" Version="2.0.0-dev00014" />
<PackageReference Include="TestCentric.Engine.Api" Version="2.0.0-dev00017" />
<PackageReference Include="TestCentric.Extensibility" Version="3.0.0" />
<PackageReference Include="TestCentric.InternalTrace" Version="1.2.0" />
</ItemGroup>
Expand Down
7 changes: 4 additions & 3 deletions src/TestModel/model/TestFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// ***********************************************************************

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

Expand Down Expand Up @@ -46,10 +47,10 @@ public static TestFilter MakeIdFilter(TestNode test)
return new TestFilter($"<filter><id>{test.Id}</id></filter>");
}

public static TestFilter MakeIdFilter(IList<TestNode> testNodes)
public static TestFilter MakeIdFilter(IEnumerable<TestNode> testNodes)
{
if (testNodes.Count == 1)
return MakeIdFilter(testNodes[0]);
if (testNodes.Count() == 1)
return MakeIdFilter(testNodes.First());

StringBuilder sb = new StringBuilder("<filter><or>");

Expand Down
2 changes: 1 addition & 1 deletion src/TestModel/model/TestModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private class TestRunSpecification

public bool DebuggingRequested { get; }

public bool IsEmpty => SelectedTests.Count == 0;
public bool IsEmpty => SelectedTests.Count() == 0;

public TestRunSpecification(TestSelection selectedTests, TestFilter filter, bool debuggingRequested)
{
Expand Down
Loading
Loading