Skip to content

Commit 89f9298

Browse files
authored
Merge pull request #5123 from bclothier/FixTodoExplorer
Clean up the ToDoExplorerViewModel class and add arrange to the tests.
2 parents d39d1dd + 6454da6 commit 89f9298

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

Rubberduck.Core/UI/ToDoItems/ToDoExplorerViewModel.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,16 @@ public ToDoExplorerViewModel(
4242
RubberduckParserState state,
4343
IConfigurationService<Configuration> configService,
4444
ISettingsFormFactory settingsFormFactory,
45-
ISelectionService selectionService,
46-
IUiDispatcher uiDispatcher)
45+
IUiDispatcher uiDispatcher,
46+
INavigateCommand navigateCommand)
4747
{
4848
_state = state;
4949
_configService = configService;
5050
_settingsFormFactory = settingsFormFactory;
5151
_uiDispatcher = uiDispatcher;
5252
_state.StateChanged += HandleStateChanged;
5353

54+
NavigateCommand = navigateCommand;
5455
RefreshCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(),
5556
_ =>
5657
{
@@ -191,9 +192,9 @@ private void HandleStateChanged(object sender, EventArgs e)
191192
});
192193
}
193194

194-
public INavigateCommand NavigateCommand { get; set; }
195+
public INavigateCommand NavigateCommand { get; }
195196

196-
public CommandBase RefreshCommand { get; set; }
197+
public CommandBase RefreshCommand { get; }
197198

198199
public CommandBase RemoveCommand { get; }
199200

RubberduckTests/TodoExplorer/TodoExplorerTests.cs

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public void PicksUpComments()
2929
' Bug this is a bug comment
3030
";
3131

32-
var selectionService = new Mock<ISelectionService>().Object;
33-
3432
var builder = new MockVbeBuilder();
3533
var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
3634
.AddComponent("Module1", ComponentType.StandardModule, inputCode)
@@ -41,7 +39,7 @@ public void PicksUpComments()
4139
using (var state = parser.State)
4240
{
4341
var cs = GetConfigService(new[] { "TODO", "NOTE", "BUG" });
44-
var vm = new ToDoExplorerViewModel(state, cs, null, selectionService, GetMockedUiDispatcher());
42+
var vm = ArrangeViewModel(state, cs);
4543

4644
parser.Parse(new CancellationTokenSource());
4745
if (state.Status >= ParserState.Error)
@@ -66,8 +64,6 @@ public void PicksUpComments_StrangeCasing()
6664
' bUg this is a bug comment
6765
";
6866

69-
var selectionService = new Mock<ISelectionService>().Object;
70-
7167
var builder = new MockVbeBuilder();
7268
var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
7369
.AddComponent("Module1", ComponentType.StandardModule, inputCode)
@@ -78,7 +74,7 @@ public void PicksUpComments_StrangeCasing()
7874
using (var state = parser.State)
7975
{
8076
var cs = GetConfigService(new[] { "TODO", "NOTE", "BUG" });
81-
var vm = new ToDoExplorerViewModel(state, cs, null, selectionService, GetMockedUiDispatcher());
77+
var vm = ArrangeViewModel(state, cs);
8278

8379
parser.Parse(new CancellationTokenSource());
8480
if (state.Status >= ParserState.Error)
@@ -103,8 +99,6 @@ public void PicksUpComments_SpecialCharacters()
10399
' bug: this should not be seen due to the colon
104100
";
105101

106-
var selectionService = new Mock<ISelectionService>().Object;
107-
108102
var builder = new MockVbeBuilder();
109103
var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
110104
.AddComponent("Module1", ComponentType.StandardModule, inputCode)
@@ -115,7 +109,7 @@ public void PicksUpComments_SpecialCharacters()
115109
using (var state = parser.State)
116110
{
117111
var cs = GetConfigService(new[] { "TO-DO", "N@TE", "BUG " });
118-
var vm = new ToDoExplorerViewModel(state, cs, null, selectionService, GetMockedUiDispatcher());
112+
var vm = ArrangeViewModel(state, cs);
119113

120114
parser.Parse(new CancellationTokenSource());
121115
if (state.Status >= ParserState.Error)
@@ -139,8 +133,6 @@ public void AvoidsFalsePositiveComments()
139133
' Denoted
140134
";
141135

142-
var selectionService = new Mock<ISelectionService>().Object;
143-
144136
var builder = new MockVbeBuilder();
145137
var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
146138
.AddComponent("Module1", ComponentType.StandardModule, inputCode)
@@ -151,7 +143,7 @@ public void AvoidsFalsePositiveComments()
151143
using (var state = parser.State)
152144
{
153145
var cs = GetConfigService(new[] { "TODO", "NOTE", "BUG" });
154-
var vm = new ToDoExplorerViewModel(state, cs, null, selectionService, GetMockedUiDispatcher());
146+
var vm = ArrangeViewModel(state, cs);
155147

156148
parser.Parse(new CancellationTokenSource());
157149
if (state.Status >= ParserState.Error)
@@ -175,8 +167,6 @@ public void RemoveRemovesComment()
175167
const string expected =
176168
@"Dim d As Variant ";
177169

178-
var selectionService = new Mock<ISelectionService>().Object;
179-
180170
var builder = new MockVbeBuilder();
181171
var project = builder.ProjectBuilder("TestProject1", ProjectProtection.Unprotected)
182172
.AddComponent("Module1", ComponentType.StandardModule, inputCode)
@@ -189,11 +179,8 @@ public void RemoveRemovesComment()
189179
using (var state = parser.State)
190180
{
191181
var cs = GetConfigService(new[] { "TODO", "NOTE", "BUG" });
192-
var vm = new ToDoExplorerViewModel(state, cs, null, selectionService, GetMockedUiDispatcher())
193-
{
194-
RefreshCommand = new ReparseCommand(vbe.Object, new Mock<IConfigurationService<GeneralSettings>>().Object, state, null, null, null, vbeEvents.Object)
195-
};
196-
182+
var vm = ArrangeViewModel(state, cs);
183+
197184
parser.Parse(new CancellationTokenSource());
198185
if (state.Status >= ParserState.Error)
199186
{
@@ -233,5 +220,10 @@ private IUiDispatcher GetMockedUiDispatcher()
233220
dispatcher.Setup(m => m.Invoke(It.IsAny<Action>())).Callback((Action argument) => argument.Invoke());
234221
return dispatcher.Object;
235222
}
223+
224+
private ToDoExplorerViewModel ArrangeViewModel(RubberduckParserState state, IConfigurationService<Configuration> configService)
225+
{
226+
return new ToDoExplorerViewModel(state, configService, null, GetMockedUiDispatcher(), null);
227+
}
236228
}
237229
}

0 commit comments

Comments
 (0)