Skip to content

Commit d385224

Browse files
committed
Automatic TestCentricProject Save - first cut
1 parent 1aea4cc commit d385224

36 files changed

+398
-593
lines changed

src/GuiRunner/TestCentric.Gui.Tests/Presenters/AgentSelectionControllerTests.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ namespace TestCentric.Gui.Presenters
1515
using TestCentric.Gui.Views;
1616

1717
[TestFixture]
18-
internal class AgentSelectionControllerTests
18+
internal class AgentSelectionControllerTests : PresenterTestBase<IMainView>
1919
{
20-
private ITestModel _model;
21-
private IMainView _view;
2220
private ToolStripMenuItem _selectAgentMenuItem;
2321
private AgentSelectionController _controller;
2422

2523
[SetUp]
2624
public void SetUp()
2725
{
28-
_model = Substitute.For<ITestModel>();
29-
_view = Substitute.For<IMainView>();
30-
3126
// Ensure that model always has at least an empty package with no settings
27+
var options = new GuiOptions();
28+
_model.Options.Returns(options);
29+
_model.TestCentricProject.Returns(new TestCentricProject(options));
3230
_model.TopLevelPackage.Returns(new NUnit.Engine.TestPackage());
3331

3432
// Create a real ToolStripMenuItem to get a real collection
@@ -289,15 +287,13 @@ public void UpdateMenuItems_NoSpecificAgentIsSelected_ChecksDefaultAgentMenuItem
289287
public void UpdateMenuItems_SpecificAgentIsSelected_ChecksAgentMenuItem()
290288
{
291289
// 1. Arrange
292-
var project = new TestCentricProject();
293-
_model.TestCentricProject.Returns(project);
294290
_model.GetAgentsForPackage(null).ReturnsForAnyArgs(new List<string>
295291
{
296292
"NUnit.TestAdapter.Agent1",
297293
"NUnit.TestAdapter.Agent2"
298294
});
299295

300-
project.AddSetting(SettingDefinitions.SelectedAgentName.WithValue("NUnit.TestAdapter.Agent2"));
296+
_model.TopLevelPackage.Settings.Add(SettingDefinitions.SelectedAgentName.WithValue("NUnit.TestAdapter.Agent2"));
301297

302298
_model.AvailableAgents.Returns(new List<string>
303299
{

src/GuiRunner/TestCentric.Gui.Tests/Presenters/Main/CommandTests.cs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ public class CommandTests : MainPresenterTestBase
2121
private static string[] NO_FILES_SELECTED = new string[0];
2222
private static string NO_FILE_PATH = null;
2323

24-
// TODO: Because the presenter opens dialogs for these commands,
25-
// they can't be tested directly. This could be fixed if the
26-
// presenter asked the view to open dialogs.
27-
2824
[TestCase(false, false, "Assemblies (*.dll,*.exe)|*.dll;*.exe|All Files (*.*)|*.*")]
2925
[TestCase(true, false, "Projects & Assemblies (*.nunit,*.dll,*.exe)|*.nunit;*.dll;*.exe|NUnit Projects (*.nunit)|*.nunit|Assemblies (*.dll,*.exe)|*.dll;*.exe|All Files (*.*)|*.*")]
3026
[TestCase(false, true, "Projects & Assemblies (*.csproj,*.fsproj,*.vbproj,*.vjsproj,*.vcproj,*.sln,*.dll,*.exe)|*.csproj;*.fsproj;*.vbproj;*.vjsproj;*.vcproj;*.sln;*.dll;*.exe|Visual Studio Projects (*.csproj,*.fsproj,*.vbproj,*.vjsproj,*.vcproj,*.sln)|*.csproj;*.fsproj;*.vbproj;*.vjsproj;*.vcproj;*.sln|Assemblies (*.dll,*.exe)|*.dll;*.exe|All Files (*.*)|*.*")]
@@ -166,19 +162,30 @@ public void CloseProjectCommand_CallsCloseProject(bool dirty)
166162
_model.Received().CloseProject();
167163
}
168164

169-
//[Test]
170-
//public void SaveCommand_CallsSaveProject()
171-
//{
172-
// _view.SaveCommand.Execute += Raise.Event<CommandHandler>();
173-
// _model.Received().SaveProject();
174-
//}
165+
[TestCase("dummy.dll")]
166+
[TestCase("MyProject.nunit")]
167+
[TestCase("test1.dll", "test2.dll", "test3.dll")]
168+
public void SaveCommand_CallsSaveProject(params string[] files)
169+
{
170+
var project = new TestCentricProject(new GuiOptions(files));
171+
_model.TestCentricProject.Returns(project);
172+
173+
if(files.Length > 0)
174+
_view.DialogManager.GetFileSavePath(null, null, null, null).ReturnsForAnyArgs("MyProject.tcproj");
175+
176+
_view.SaveProjectCommand.Execute += Raise.Event<CommandHandler>();
177+
178+
_model.Received().SaveProject(files.Length == 1
179+
? $"{files[0]}.tcproj"
180+
: "MyProject.tcproj");
181+
}
175182

176183
//[Test]
177184
//public void SaveAsCommand_CallsSaveProject()
178185
//{
179-
// View.SaveAsCommand.Execute += Raise.Event<CommandHandler>();
186+
// _view.SaveAsCommand.Execute += Raise.Event<CommandHandler>();
180187
// // This is NYI, change when we implement it
181-
// Model.DidNotReceive().SaveProject();
188+
// _model.DidNotReceive().SaveProject();
182189
//}
183190

184191
[Test]

src/GuiRunner/TestCentric.Gui.Tests/Presenters/Main/MainPresenterTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class MainPresenterTestBase : PresenterTestBase<IMainView>
2020
public void CreatePresenter()
2121
{
2222
_model.ResultFormats.Returns(new[] { "nunit3" });
23-
_presenter = new TestCentricPresenter(_view, _model, new GuiOptions());
23+
_presenter = new TestCentricPresenter(_view, _model);
2424
}
2525

2626
[TearDown]

src/GuiRunner/TestCentric.Gui.Tests/Presenters/Main/ProjectEventTests.cs

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,52 +12,49 @@ namespace TestCentric.Gui.Presenters.Main
1212
{
1313
using NUnit.Common;
1414

15+
[TestFixture("dummy.dll")]
16+
[TestFixture("test1.dll", "test2.dll")]
1517
public class ProjectEventTests : MainPresenterTestBase
1618
{
17-
[Test, Ignore("Needs work")] // TODO: Find a way to test this more narrowly
18-
public void WhenProjectIsCreated_TitleBarIsSet()
19-
{
20-
var project = new TestCentricProject(new GuiOptions("dummy.dll"));
21-
_model.TestCentricProject.Returns(project);
19+
private string[] _testFiles;
20+
private TestCentricProject _project;
2221

23-
FireProjectLoadedEvent();
22+
private const string DEFAULT_TITLE_BAR = "TestCentric Runner for NUnit";
2423

25-
_view.Received().Title = "TestCentric - UNNAMED.tcproj";
24+
public ProjectEventTests(params string[] testFiles)
25+
{
26+
_testFiles = testFiles;
27+
}
28+
29+
[SetUp]
30+
public void CreateProject()
31+
{
32+
_project = new TestCentricProject(new GuiOptions(_testFiles));
33+
_model.TestCentricProject.Returns(_project);
34+
_model.TopLevelPackage.Returns(_project.TopLevelPackage);
2635
}
2736

2837
[Test]
29-
public void WhenProjectIsClosed_TitleBarIsSet()
38+
public void WhenProjectIsCreated_TitleBarIsSetToDefault()
3039
{
31-
FireProjectUnloadedEvent();
40+
FireProjectLoadedEvent();
3241

33-
_view.Received().Title = "TestCentric Runner for NUnit";
42+
_view.Received().Title = DEFAULT_TITLE_BAR;
3443
}
3544

36-
3745
[Test]
38-
public void WhenProjectIsSaved_TitleBarIsSet()
46+
public void WhenProjectIsClosed_TitleBarIsSetToDefault()
3947
{
40-
// Arrange
41-
var project = new TestCentricProject(new GuiOptions("dummy.dll"));
42-
_model.TestCentricProject.Returns(project);
43-
_view.DialogManager.GetFileSavePath(null, null, null, null).ReturnsForAnyArgs("TestCentric.tcproj");
44-
45-
// Act
46-
project.SaveAs("TestCentric.tcproj");
47-
_view.SaveProjectCommand.Execute += Raise.Event<CommandHandler>();
48+
FireProjectUnloadedEvent();
4849

49-
// Assert
50-
_model.Received().SaveProject("TestCentric.tcproj");
51-
_view.Received().Title = "TestCentric - TestCentric.tcproj";
50+
_view.Received().Title = DEFAULT_TITLE_BAR;
5251
}
5352

54-
[TestCase(true), Ignore("Needs work")] // TODO: Find a way to test this more narrowly
53+
[TestCase(true)]
5554
[TestCase(false)]
5655
public void WhenProjectIsLoaded_RunAsX86Command_IsUpdatedFromProjectSetting(bool runAsX86)
5756
{
58-
var project = new TestCentricProject(new GuiOptions("dummy.dll"));
59-
project.SetTopLevelSetting(SettingDefinitions.RunAsX86.WithValue(runAsX86));
60-
_model.TestCentricProject.Returns(project);
57+
_project.SetTopLevelSetting(SettingDefinitions.RunAsX86.WithValue(runAsX86));
6158

6259
FireProjectLoadedEvent();
6360

src/GuiRunner/TestCentric.Gui.Tests/Presenters/Main/WhenPresenterIsCreated.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,19 @@ public void CheckCommandVisible(string propName, bool visible)
4040
ViewElement(propName).Received().Visible = visible;
4141
}
4242

43+
// NOTE: Tests below need to re-create the presenter, which was
44+
// created in MainPresenterTestBase, so that it will reflect different
45+
// values for user and package settings.
46+
4347
[TestCase("NUNIT_TREE")]
4448
[TestCase("TEST_LIST")]
45-
public void CheckMenu_DisplayFormat_SelectedItem_IsInitialzedFromSettings(string displayFormat)
49+
public void CheckMenu_DisplayFormat_SelectedItem_IsInitializedFromSettings(string displayFormat)
4650
{
4751
// 1. Arrange
4852
_settings.Gui.TestTree.DisplayFormat = displayFormat;
4953

5054
// 2. Act
51-
_presenter = new TestCentricPresenter(_view, _model, new GuiOptions());
55+
_presenter = new TestCentricPresenter(_view, _model);
5256

5357
// 3. Assert
5458
_view.DisplayFormat.Received().SelectedItem = displayFormat;
@@ -65,7 +69,7 @@ public void CheckMenu_NUnitTreeGroupBy_SelectedItem_IsInitializedFromSettings(st
6569
_settings.Gui.TestTree.NUnitGroupBy = groupBy;
6670

6771
// 2. Act
68-
_presenter = new TestCentricPresenter(_view, _model, new GuiOptions());
72+
_presenter = new TestCentricPresenter(_view, _model);
6973

7074
// 3. Assert
7175
_view.NUnitGroupBy.Received().SelectedItem = groupBy;
@@ -74,28 +78,28 @@ public void CheckMenu_NUnitTreeGroupBy_SelectedItem_IsInitializedFromSettings(st
7478
[TestCase("ASSEMBLY")]
7579
[TestCase("CATEGORY")]
7680
[TestCase("OUTCOME")]
77-
public void CheckMenu_TestListGroupBy_SelectedItem_TestList_IsInitialzedFromSettings(string groupBy)
81+
public void CheckMenu_TestListGroupBy_SelectedItem_TestList_IsInitializedFromSettings(string groupBy)
7882
{
7983
// 1. Arrange
8084
_settings.Gui.TestTree.DisplayFormat = "TEST_LIST";
8185
_settings.Gui.TestTree.TestList.GroupBy = groupBy;
8286

8387
// 2. Act
84-
_presenter = new TestCentricPresenter(_view, _model, new GuiOptions());
88+
_presenter = new TestCentricPresenter(_view, _model);
8589

8690
// 3. Assert
8791
_view.TestListGroupBy.Received().SelectedItem = groupBy;
8892
}
8993

9094
[TestCase(true)]
9195
[TestCase(false)]
92-
public void FilterButton_IsInitialzedFromSettings(bool filterIsVisible)
96+
public void FilterButton_IsInitializedFromSettings(bool filterIsVisible)
9397
{
9498
// 1. Arrange
9599
_settings.Gui.TestTree.ShowFilter = filterIsVisible;
96100

97101
// 2. Act
98-
_presenter = new TestCentricPresenter(_view, _model, new GuiOptions());
102+
_presenter = new TestCentricPresenter(_view, _model);
99103

100104
// 3. Assert
101105
_view.ShowHideFilterButton.Received().Checked = filterIsVisible;
@@ -111,7 +115,7 @@ public void FilterRunSelectedTestButton_Tooltip_IsUpdated(bool checkBoxVisible,
111115
_view.TreeView.ShowCheckBoxes.Checked.Returns(checkBoxVisible);
112116

113117
// 2. Act
114-
_presenter = new TestCentricPresenter(_view, _model, new GuiOptions());
118+
_presenter = new TestCentricPresenter(_view, _model);
115119

116120
// 3. Assert
117121
(runSelectedTestsButton as IToolTip).Received().ToolTipText = expectedTooltip;

src/GuiRunner/TestCentric.Gui.Tests/Presenters/Main/WhenSettingsChanged.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ public void ShowCheckBoxes_Changed_Tooltip_IsUpdated(bool checkBoxVisible, strin
9090
_view.TreeView.ShowCheckBoxes.Checked.Returns(checkBoxVisible);
9191

9292
// 2. Act
93-
_presenter = new TestCentricPresenter(_view, _model, new GuiOptions());
9493
_view.TreeView.ShowCheckBoxes.CheckedChanged += Raise.Event<CommandHandler>();
9594

9695
// 3. Assert

src/GuiRunner/TestCentric.Gui.Tests/Presenters/Main/WhenTestRunBegins.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,15 @@ public void CheckElementVisibility(string propName, bool visible)
4949
{
5050
ViewElement(propName).Received().Visible = visible;
5151
}
52+
53+
[Test]
54+
public void TestCentricProjectIsSaved()
55+
{
56+
var project = Substitute.For<TestCentricProject>(new GuiOptions("test.dll"));
57+
_model.TestCentricProject.Returns(project);
58+
59+
this.FireRunStartingEvent(123);
60+
project.Received().SaveAs("test.dll.tcproj");
61+
}
5262
}
5363
}

src/GuiRunner/TestCentric.Gui.Tests/Presenters/Main/WhenTestsAreLoading.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
using NSubstitute;
77
using NUnit.Framework;
8+
using TestCentric.Gui.Model;
89

910
namespace TestCentric.Gui.Presenters.Main
1011
{
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************************************
2+
// Copyright (c) Charlie Poole and TestCentric contributors.
3+
// Licensed under the MIT License. See LICENSE file in root directory.
4+
// ***********************************************************************
5+
6+
using NSubstitute;
7+
using NUnit.Framework;
8+
using TestCentric.Gui.Model;
9+
10+
namespace TestCentric.Gui.Presenters.Main
11+
{
12+
public class WhenTestsAreReloading : MainPresenterTestBase
13+
{
14+
[Test]
15+
public void TestCentricProjectIsSaved()
16+
{
17+
var project = Substitute.For<TestCentricProject>(new GuiOptions("test.dll"));
18+
_model.TestCentricProject.Returns(project);
19+
20+
FireTestsReloadingEvent();
21+
22+
project.Received().SaveAs("test.dll.tcproj");
23+
}
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************************************
2+
// Copyright (c) Charlie Poole and TestCentric contributors.
3+
// Licensed under the MIT License. See LICENSE file in root directory.
4+
// ***********************************************************************
5+
6+
using NSubstitute;
7+
using NUnit.Framework;
8+
using TestCentric.Gui.Model;
9+
10+
namespace TestCentric.Gui.Presenters.Main
11+
{
12+
public class WhenTestsAreUnloading : MainPresenterTestBase
13+
{
14+
[Test]
15+
public void TestCentricProjectIsSaved()
16+
{
17+
var project = Substitute.For<TestCentricProject>(new GuiOptions("test.dll"));
18+
_model.TestCentricProject.Returns(project);
19+
20+
FireTestsUnloadingEvent();
21+
22+
project.Received().SaveAs("test.dll.tcproj");
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)