Skip to content

Commit c0ffaab

Browse files
authored
Merge pull request #4769 from comintern/testing
Refresh Testing (Pun Intended)
2 parents 801c69d + 6910972 commit c0ffaab

File tree

89 files changed

+4089
-2675
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+4089
-2675
lines changed

Rubberduck.Core/Properties/Settings.Designer.cs

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Rubberduck.Core/Settings/ConfigurationLoader.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using Rubberduck.SettingsProvider;
44
using Rubberduck.SmartIndenter;
5+
using Rubberduck.UnitTesting.Settings;
56

67
namespace Rubberduck.Settings
78
{

Rubberduck.Core/Settings/UserSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Xml.Serialization;
22
using Rubberduck.SmartIndenter;
3+
using Rubberduck.UnitTesting.Settings;
34

45
namespace Rubberduck.Settings
56
{

Rubberduck.Core/UI/CodeExplorer/Commands/AddTestComponentCommand.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using System;
22
using System.Linq;
33
using System.Runtime.InteropServices;
4-
using Rubberduck.Interaction;
54
using Rubberduck.Navigation.CodeExplorer;
65
using Rubberduck.Parsing.VBA;
7-
using Rubberduck.Settings;
86
using Rubberduck.UI.UnitTesting.Commands;
9-
using Rubberduck.UnitTesting;
7+
using Rubberduck.UnitTesting.CodeGeneration;
108
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
119

1210
namespace Rubberduck.UI.CodeExplorer.Commands
@@ -21,8 +19,8 @@ public class AddTestComponentCommand : AddTestModuleCommand
2119
typeof(CodeExplorerMemberViewModel)
2220
};
2321

24-
public AddTestComponentCommand(IVBE vbe, RubberduckParserState state, IGeneralConfigService configLoader, IMessageBox messageBox, IVBEInteraction interaction)
25-
: base(vbe, state, configLoader, messageBox, interaction) { }
22+
public AddTestComponentCommand(IVBE vbe, RubberduckParserState state, ITestCodeGenerator codeGenerator)
23+
: base(vbe, state, codeGenerator) { }
2624

2725
protected override bool EvaluateCanExecute(object parameter)
2826
{

Rubberduck.Core/UI/Command/MenuItems/ParentMenus/CodePaneContextParentMenu.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,7 @@ public enum CodePaneContextMenuItemDisplayOrder
2020
FindSymbol,
2121
FindAllReferences,
2222
FindAllImplementations,
23+
RunSelectedTestModule,
24+
RunSelectedTest
2325
}
2426
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Rubberduck.Parsing.VBA;
2+
using Rubberduck.UI.Command.MenuItems.ParentMenus;
3+
4+
namespace Rubberduck.UI.Command.MenuItems
5+
{
6+
public class RunSelectedTestMethodCommandMenuItem : CommandMenuItemBase
7+
{
8+
public RunSelectedTestMethodCommandMenuItem(RunSelectedTestMethodCommand command) : base(command) { }
9+
10+
public override string Key => "ContextMenu_RunSelectedTest";
11+
public override int DisplayOrder => (int)CodePaneContextMenuItemDisplayOrder.RunSelectedTest;
12+
13+
public override bool EvaluateCanExecute(RubberduckParserState state)
14+
{
15+
return state != null && Command.CanExecute(null);
16+
}
17+
18+
public override bool HiddenWhenDisabled => true;
19+
20+
public override bool BeginGroup => false;
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Rubberduck.Parsing.VBA;
2+
using Rubberduck.UI.Command.MenuItems.ParentMenus;
3+
4+
namespace Rubberduck.UI.Command.MenuItems
5+
{
6+
public class RunSelectedTestModuleCommandMenuItem : CommandMenuItemBase
7+
{
8+
public RunSelectedTestModuleCommandMenuItem(RunSelectedTestModuleCommand command) : base(command) { }
9+
10+
public override string Key => "ContextMenu_RunSelectedTestModule";
11+
public override int DisplayOrder => (int)CodePaneContextMenuItemDisplayOrder.RunSelectedTestModule;
12+
13+
public override bool EvaluateCanExecute(RubberduckParserState state)
14+
{
15+
return state != null && Command.CanExecute(null);
16+
}
17+
18+
public override bool HiddenWhenDisabled => true;
19+
20+
public override bool BeginGroup => true;
21+
}
22+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Linq;
2+
using NLog;
3+
using Rubberduck.Parsing.Annotations;
4+
using Rubberduck.Parsing.Symbols;
5+
using Rubberduck.Parsing.VBA;
6+
using Rubberduck.UnitTesting;
7+
using Rubberduck.VBEditor.Utility;
8+
9+
namespace Rubberduck.UI.Command
10+
{
11+
public class RunSelectedTestMethodCommand : CommandBase
12+
{
13+
private readonly ITestEngine _engine;
14+
private readonly ISelectionService _selectionService;
15+
private readonly IDeclarationFinderProvider _finderProvider;
16+
17+
public RunSelectedTestMethodCommand(ITestEngine engine, ISelectionService selectionService, IDeclarationFinderProvider finderProvider)
18+
: base(LogManager.GetCurrentClassLogger())
19+
{
20+
_engine = engine;
21+
_selectionService = selectionService;
22+
_finderProvider = finderProvider;
23+
}
24+
25+
protected override bool EvaluateCanExecute(object parameter)
26+
{
27+
return (parameter ?? FindDeclarationFromSelection()) is Declaration candidate &&
28+
!(_engine.Tests.FirstOrDefault(test => test.Declaration.Equals(candidate)) is null) &&
29+
_engine.CanRun;
30+
}
31+
32+
protected override void OnExecute(object parameter)
33+
{
34+
if (!((parameter ?? FindDeclarationFromSelection()) is Declaration candidate) ||
35+
!(_engine.Tests.FirstOrDefault(test => test.Declaration.Equals(candidate)) is TestMethod selectedTest) ||
36+
!_engine.CanRun)
37+
{
38+
return;
39+
}
40+
41+
_engine.Run(new [] { selectedTest });
42+
}
43+
44+
private Declaration FindDeclarationFromSelection()
45+
{
46+
var active = _selectionService?.ActiveSelection();
47+
if (!active.HasValue)
48+
{
49+
return null;
50+
}
51+
52+
return _finderProvider.DeclarationFinder.FindDeclarationsForSelection(active.Value)
53+
.SingleOrDefault(declaration => declaration.DeclarationType == DeclarationType.Procedure &&
54+
declaration.Annotations.Any(annotation => annotation is TestMethodAnnotation));
55+
}
56+
}
57+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System.Linq;
2+
using NLog;
3+
using Rubberduck.Parsing.Annotations;
4+
using Rubberduck.Parsing.Symbols;
5+
using Rubberduck.Parsing.VBA;
6+
using Rubberduck.UnitTesting;
7+
using Rubberduck.VBEditor.Utility;
8+
9+
namespace Rubberduck.UI.Command
10+
{
11+
public class RunSelectedTestModuleCommand : CommandBase
12+
{
13+
private readonly ITestEngine _engine;
14+
private readonly ISelectionService _selectionService;
15+
private readonly IDeclarationFinderProvider _finderProvider;
16+
17+
public RunSelectedTestModuleCommand(ITestEngine engine, ISelectionService selectionService, IDeclarationFinderProvider finderProvider)
18+
: base(LogManager.GetCurrentClassLogger())
19+
{
20+
_engine = engine;
21+
_selectionService = selectionService;
22+
_finderProvider = finderProvider;
23+
}
24+
25+
protected override bool EvaluateCanExecute(object parameter)
26+
{
27+
return (parameter ?? FindModuleFromSelection()) is Declaration candidate &&
28+
candidate.DeclarationType == DeclarationType.ProceduralModule &&
29+
candidate.Annotations.Any(annotation => annotation is TestModuleAnnotation) &&
30+
_engine.CanRun &&
31+
_engine.Tests.Any(test => test.Declaration.QualifiedModuleName.Equals(candidate.QualifiedModuleName));
32+
}
33+
34+
protected override void OnExecute(object parameter)
35+
{
36+
if (!((parameter ?? FindModuleFromSelection()) is Declaration candidate) ||
37+
candidate.DeclarationType != DeclarationType.ProceduralModule ||
38+
!candidate.Annotations.Any(annotation => annotation is TestModuleAnnotation) ||
39+
!_engine.CanRun)
40+
{
41+
return;
42+
}
43+
44+
var tests = _engine.Tests.Where(test => test.Declaration.QualifiedModuleName.Equals(candidate.QualifiedModuleName)).ToList();
45+
46+
if (!tests.Any())
47+
{
48+
return;
49+
}
50+
51+
_engine.Run(tests);
52+
}
53+
54+
private Declaration FindModuleFromSelection()
55+
{
56+
var active = _selectionService?.ActiveSelection();
57+
return !active.HasValue
58+
? null
59+
: _finderProvider.DeclarationFinder.ModuleDeclaration(active.Value.QualifiedName);
60+
}
61+
}
62+
}

Rubberduck.Core/UI/Controls/GroupingGrid.xaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6-
xmlns:local="clr-namespace:Rubberduck.UI.Controls" x:Class="Rubberduck.UI.Controls.GroupingGrid"
6+
xmlns:local="clr-namespace:Rubberduck.UI.Controls"
7+
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
8+
x:Class="Rubberduck.UI.Controls.GroupingGrid"
79
mc:Ignorable="d"
810
d:DesignHeight="300" d:DesignWidth="300">
911
<DataGrid.Resources>
@@ -60,7 +62,8 @@
6062
<Setter Property="Template">
6163
<Setter.Value>
6264
<ControlTemplate>
63-
<Expander Background="WhiteSmoke" Foreground="Black" FontWeight="SemiBold">
65+
<Expander Background="WhiteSmoke" Foreground="Black" FontWeight="SemiBold"
66+
IsExpanded="{Binding InitialExpandedState, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:GroupingGrid}}}">
6467
<Expander.Header>
6568
<StackPanel Orientation="Horizontal">
6669
<TextBlock Margin="4"
@@ -76,6 +79,9 @@
7679
</StackPanel>
7780
</Expander.Header>
7881
<ItemsPresenter Margin="25,0,0,0" />
82+
<i:Interaction.Behaviors>
83+
<local:PersistGroupExpandedStateBehavior GroupName="{Binding Name}" />
84+
</i:Interaction.Behaviors>
7985
</Expander>
8086
</ControlTemplate>
8187
</Setter.Value>

0 commit comments

Comments
 (0)