Skip to content

Commit

Permalink
Merge pull request #1070 from TestCentric/issue-1069
Browse files Browse the repository at this point in the history
Re-open a saved TestCentric project from recent files menu
  • Loading branch information
CharliePoole authored May 15, 2024
2 parents 9ad7675 + 86eae60 commit fe211b9
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void ApplySettings()

foreach(var entry in PackageSettingChanges)
{
Model.TestProject.AddSetting(entry.Key, entry.Value);
Model.TestCentricProject.AddSetting(entry.Key, entry.Value);
}
}
#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AgentSelectionController(ITestModel model, IMainView view)

public bool AllowAgentSelection()
{
var package = _model.TestProject;
var package = _model.TestCentricProject;
return package != null &&
_model.GetAgentsForPackage(package).Count > 1;
}
Expand All @@ -44,8 +44,8 @@ public void PopulateMenu()

agentMenu.MenuItems.Add(defaultMenuItem);

var agentsToEnable = _model.GetAgentsForPackage(_model.TestProject);
var selectedAgentName = _model.TestProject.GetSetting(EnginePackageSettings.SelectedAgentName, "DEFAULT");
var agentsToEnable = _model.GetAgentsForPackage(_model.TestCentricProject);
var selectedAgentName = _model.TestCentricProject.GetSetting(EnginePackageSettings.SelectedAgentName, "DEFAULT");

foreach (var agentName in _model.AvailableAgents)
{
Expand All @@ -60,7 +60,7 @@ public void PopulateMenu()

// Go through all menu items and check one
bool isItemChecked = false;
var packageSettings = _model.TestProject.Settings;
var packageSettings = _model.TestCentricProject.Settings;
foreach (ToolStripMenuItem item in agentMenu.MenuItems)
{
if ((string)item.Tag == selectedAgentName)
Expand All @@ -79,7 +79,7 @@ public void PopulateMenu()
// does not re-create the Engine. Since we just changed a setting, we must
// re-create the Engine by unloading/reloading the tests. We make a copy of
// __model.TestFiles because the method does an unload before it loads.
_model.TestProject.LoadTests();
_model.TestCentricProject.LoadTests();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public bool HasResults
/// </summary>
public abstract void OnTestLoaded(TestNode testNode, VisualState visualState);

public void SaveVisualState() => CreateVisualState().Save(VisualState.GetVisualStateFileName(_model.TestProject.TestFiles[0]));
public void SaveVisualState() => CreateVisualState().Save(VisualState.GetVisualStateFileName(_model.TestCentricProject.TestFiles[0]));

protected abstract VisualState CreateVisualState();

Expand Down
41 changes: 14 additions & 27 deletions src/TestCentric/testcentric.gui/Presenters/TestCentricPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public class TestCentricPresenter

private string _guiLayout;

private readonly RecentFiles _recentFiles;

private AgentSelectionController _agentSelectionController;

Expand All @@ -74,7 +73,6 @@ public TestCentricPresenter(IMainView view, ITestModel model, CommandLineOptions
_options = options;

_settings = _model.Settings;
_recentFiles = _model.RecentFiles;

_agentSelectionController = new AgentSelectionController(_model, _view);

Expand All @@ -100,7 +98,7 @@ private void WireUpEvents()

_model.Events.TestCentricProjectLoaded += (TestEventArgs e) =>
{
_view.Title = $"TestCentric - {_model.TestProject?.FileName ?? "UNNAMED.tcproj"}";
_view.Title = $"TestCentric - {_model.TestCentricProject?.FileName ?? "UNNAMED.tcproj"}";
};

_model.Events.TestCentricProjectUnloaded += (TestEventArgs e) =>
Expand All @@ -125,7 +123,7 @@ private void WireUpEvents()

UpdateViewCommands();

_lastFilesLoaded = _model.TestProject.TestFiles.ToArray();
_lastFilesLoaded = _model.TestCentricProject.TestFiles.ToArray();
};

_model.Events.TestsUnloading += (TestEventArgse) =>
Expand Down Expand Up @@ -278,23 +276,12 @@ void OnRunFinished(ResultNode result)
Application.DoEvents();

// Create an unnamed TestCentricProject and load test specified on command line
if (_options.InputFiles.Count != 0)
{
log.Debug($"Loading files from command-line: {string.Join(", ", _options.InputFiles.ToArray())}");
if (_options.InputFiles.Count == 1)
_model.OpenExistingFile(_options.InputFiles[0]);
else if (_options.InputFiles.Count >1)
_model.CreateNewProject(_options.InputFiles);
}
else if (_settings.Gui.LoadLastProject && !_options.NoLoad)
{
// Find the most recent file loaded, which still exists
foreach (string entry in _recentFiles.Entries)
{
if (entry != null && File.Exists(entry))
{
_model.CreateNewProject(new[] { entry });
break;
}
}
}
_model.OpenMostRecentFile();

//if ( guiOptions.include != null || guiOptions.exclude != null)
//{
Expand Down Expand Up @@ -408,7 +395,7 @@ void OnRunFinished(ResultNode result)
menuItem.Click += (sender, ea) =>
{
string path = ((ToolStripMenuItem)sender).Text.Substring(2);
_model.CreateNewProject(new[] { path });
_model.OpenExistingFile(path);
};
menuItems.Add(menuItem);
if (num >= _settings.Gui.RecentProjects.MaxFiles) break;
Expand Down Expand Up @@ -612,9 +599,9 @@ private void DisplayTestParametersDialog()
dlg.Font = _settings.Gui.Font;
dlg.StartPosition = FormStartPosition.CenterParent;

if (_model.TestProject.Settings.ContainsKey("TestParametersDictionary"))
if (_model.TestCentricProject.Settings.ContainsKey("TestParametersDictionary"))
{
var testParms = _model.TestProject .Settings["TestParametersDictionary"] as IDictionary<string, string>;
var testParms = _model.TestCentricProject .Settings["TestParametersDictionary"] as IDictionary<string, string>;
foreach (string key in testParms.Keys)
dlg.Parameters.Add(key, testParms[key]);
}
Expand Down Expand Up @@ -643,12 +630,12 @@ private void OpenProject()
{
var projectPath = _view.DialogManager.GetFileOpenPath("Open TestCentric Project", "TestCentric Project (*.tcproj) | *.tcproj");
if (projectPath != null)
_model.OpenProject(projectPath);
_model.OpenExistingProject(projectPath);
}

private void SaveProject()
{
var projectPath = _view.DialogManager.GetFileSavePath("Save TestCentric Project", "TestCentric Project(*.tcproj) | *.tcproj", null, null);
var projectPath = _view.DialogManager.GetFileSavePath("Save TestCentric Project", "TestCentric Project(*.tcproj) | *.tcproj", _model.WorkDirectory, null);
if (projectPath != null)
{
try
Expand Down Expand Up @@ -689,7 +676,7 @@ public void AddTestFiles()

if (filesToAdd.Count > 0)
{
var files = new List<string>(_model.TestProject.TestFiles);
var files = new List<string>(_model.TestCentricProject.TestFiles);
files.AddRange(filesToAdd);

_model.CreateNewProject(files);
Expand Down Expand Up @@ -822,7 +809,7 @@ private static string Quoted(string s)

private void ChangePackageSettingAndReload(string key, object setting)
{
var settings = _model.TestProject.Settings;
var settings = _model.TestCentricProject.Settings;
if (setting == null || setting as string == "DEFAULT")
settings.Remove(key);
else
Expand All @@ -832,7 +819,7 @@ private void ChangePackageSettingAndReload(string key, object setting)
// does not re-create the Engine. Since we just changed a setting, we must
// re-create the Engine by unloading/reloading the tests. We make a copy of
// __model.TestFiles because the method does an unload before it loads.
_model.TestProject.LoadTests();
_model.TestCentricProject.LoadTests();
}

private void applyFont(Font font)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,9 +279,9 @@ private bool TryLoadVisualState(out VisualState visualState)
{
visualState = null;

if (_model.TestProject.TestFiles.Count > 0)
if (_model.TestCentricProject.TestFiles.Count > 0)
{
var filename = VisualState.GetVisualStateFileName(_model.TestProject.TestFiles[0]);
var filename = VisualState.GetVisualStateFileName(_model.TestCentricProject.TestFiles[0]);
if (File.Exists(filename))
visualState = VisualState.LoadFrom(filename);
}
Expand Down
44 changes: 22 additions & 22 deletions src/TestCentric/testcentric.gui/Views/TestCentricMainView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ private void InitializeComponent()
this.newProjectMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.openProjectMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.saveProjectMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
this.closeMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator6 = new System.Windows.Forms.ToolStripSeparator();
this.addTestFileMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.reloadTestsMenuItem = new System.Windows.Forms.ToolStripMenuItem();
Expand Down Expand Up @@ -522,56 +522,56 @@ private void InitializeComponent()
// newProjectMenuItem
//
this.newProjectMenuItem.Name = "newProjectMenuItem";
this.newProjectMenuItem.Size = new System.Drawing.Size(180, 22);
this.newProjectMenuItem.Text = "&New Project";
this.newProjectMenuItem.Size = new System.Drawing.Size(187, 22);
this.newProjectMenuItem.Text = "Create &New Project";
//
// openProjectMenuItem
//
this.openProjectMenuItem.Name = "openProjectMenuItem";
this.openProjectMenuItem.Size = new System.Drawing.Size(180, 22);
this.openProjectMenuItem.Text = "&Open Project";
this.openProjectMenuItem.Size = new System.Drawing.Size(187, 22);
this.openProjectMenuItem.Text = "&Open Existing Project";
//
// saveProjectMenuItem
//
this.saveProjectMenuItem.Name = "saveProjectMenuItem";
this.saveProjectMenuItem.Size = new System.Drawing.Size(180, 22);
this.saveProjectMenuItem.Size = new System.Drawing.Size(187, 22);
this.saveProjectMenuItem.Text = "&Save Project";
//
// toolStripSeparator6
//
this.toolStripSeparator6.Name = "toolStripSeparator6";
this.toolStripSeparator6.Size = new System.Drawing.Size(177, 6);
//
// closeMenuItem
//
this.closeMenuItem.Name = "closeMenuItem";
this.closeMenuItem.Size = new System.Drawing.Size(180, 22);
this.closeMenuItem.Size = new System.Drawing.Size(187, 22);
this.closeMenuItem.Text = "&Close Project";
//
// toolStripSeparator6
//
this.toolStripSeparator6.Name = "toolStripSeparator6";
this.toolStripSeparator6.Size = new System.Drawing.Size(184, 6);
//
// addTestFileMenuItem
//
this.addTestFileMenuItem.Name = "addTestFileMenuItem";
this.addTestFileMenuItem.Size = new System.Drawing.Size(180, 22);
this.addTestFileMenuItem.Size = new System.Drawing.Size(187, 22);
this.addTestFileMenuItem.Text = "&Add Test File...";
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(177, 6);
this.toolStripSeparator1.Size = new System.Drawing.Size(184, 6);
//
// reloadTestsMenuItem
//
this.reloadTestsMenuItem.Name = "reloadTestsMenuItem";
this.reloadTestsMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.R)));
this.reloadTestsMenuItem.Size = new System.Drawing.Size(180, 22);
this.reloadTestsMenuItem.Size = new System.Drawing.Size(187, 22);
this.reloadTestsMenuItem.Text = "&Reload Tests";
//
// selectAgentMenu
//
this.selectAgentMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.selectAgentDummyMenuItem});
this.selectAgentMenu.Name = "selectAgentMenu";
this.selectAgentMenu.Size = new System.Drawing.Size(180, 22);
this.selectAgentMenu.Size = new System.Drawing.Size(187, 22);
this.selectAgentMenu.Text = "Select Agent";
//
// selectAgentDummyMenuItem
Expand All @@ -583,25 +583,25 @@ private void InitializeComponent()
// toolStripSeparator2
//
this.toolStripSeparator2.Name = "toolStripSeparator2";
this.toolStripSeparator2.Size = new System.Drawing.Size(177, 6);
this.toolStripSeparator2.Size = new System.Drawing.Size(184, 6);
//
// runAsX86MenuItem
//
this.runAsX86MenuItem.Name = "runAsX86MenuItem";
this.runAsX86MenuItem.Size = new System.Drawing.Size(180, 22);
this.runAsX86MenuItem.Size = new System.Drawing.Size(187, 22);
this.runAsX86MenuItem.Text = "Run as X86";
//
// toolStripSeparator3
//
this.toolStripSeparator3.Name = "toolStripSeparator3";
this.toolStripSeparator3.Size = new System.Drawing.Size(177, 6);
this.toolStripSeparator3.Size = new System.Drawing.Size(184, 6);
//
// recentFilesMenu
//
this.recentFilesMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.recentFilesDummyMenuItem});
this.recentFilesMenu.Name = "recentFilesMenu";
this.recentFilesMenu.Size = new System.Drawing.Size(180, 22);
this.recentFilesMenu.Size = new System.Drawing.Size(187, 22);
this.recentFilesMenu.Text = "Recent &Files";
//
// recentFilesDummyMenuItem
Expand All @@ -613,12 +613,12 @@ private void InitializeComponent()
// toolStripSeparator4
//
this.toolStripSeparator4.Name = "toolStripSeparator4";
this.toolStripSeparator4.Size = new System.Drawing.Size(177, 6);
this.toolStripSeparator4.Size = new System.Drawing.Size(184, 6);
//
// exitMenuItem
//
this.exitMenuItem.Name = "exitMenuItem";
this.exitMenuItem.Size = new System.Drawing.Size(180, 22);
this.exitMenuItem.Size = new System.Drawing.Size(187, 22);
this.exitMenuItem.Text = "E&xit";
//
// viewMenu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@
YC7xafsZGFig2tEMgGK5Brmbco1yoUd4pdSPcItuxmYIVDseA+rlfA7xiqjBDLjs6vf/jJYJ3BC4d1A0
Q70wW0dR/NXKtScuewT+Bim+4hH4/9er12BD4AZwiS9DNgAciLYFcpKHucVzDrGJvIFpelDdCKZBfJhm
ED7MLfYYbIBsvew2+SZ5zWNcoh6HOUWvISsCaQYBEI0sDsL7uUV/gg2AgYPc4k+QFRByAUg9VCsEgOIZ
JgnyK7ImmGFYwwAGDvOI2kznFv8HkgSFNrJiEEaPhaMcolZQrQhwhEtsKrImXBiobgpUCypYxcDAjM8Q
sAu5xCaD1EG1YAcg7xzmEl0OiipQaB/lFn0E8jNIHKpk0AAGBgBJ2zn9UL56hgAAAABJRU5ErkJggg==
JgnyK7ImmGFYwwAGDvOI2kzjFv8HkgSFNrJiEEaPhaMcolZQrQhwhEtsKrImXBiobgpUCypYxcDAjM8Q
sAu5xCaD1EG1YAcg7xzmEl0OiipQaB/lFn0E8jNIHKpk0AAGBgBHizn7G7n0NAAAAABJRU5ErkJggg==
</value>
</data>
<data name="stopRunButton.Image" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
Expand Down
2 changes: 1 addition & 1 deletion src/TestCentric/tests/Presenters/Main/CommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void AddTestFilesCommand_TellsModelToLoadTests()
testFiles.Add("FILE1");
testFiles.Add("FILE2");
var project = new TestCentricProject(_model, testFiles);
_model.TestProject.Returns(project);
_model.TestCentricProject.Returns(project);

var filesToAdd = new string[] { Path.GetFullPath("/path/to/test.dll") };
_view.DialogManager.SelectMultipleFiles(null, null).ReturnsForAnyArgs(filesToAdd);
Expand Down
2 changes: 1 addition & 1 deletion src/TestCentric/tests/Presenters/Main/ProjectEventTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ProjectEventTests : MainPresenterTestBase
public void WhenProjectIsCreated_TitleBarIsSet()
{
var project = new TestCentricProject(_model, "dummy.dll");
_model.TestProject.Returns(project);
_model.TestCentricProject.Returns(project);

FireProjectLoadedEvent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void SimulateTestLoad()
_model.LoadedTests.Returns(testNode);

var project = new TestCentricProject(_model, "dummy.dll");
_model.TestProject.Returns(project);
_model.TestCentricProject.Returns(project);
FireTestLoadedEvent(testNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void CreateDisplayStrategy()
_view.Nodes.Returns(nodes);

var project = new TestCentricProject(_model, "dummy.dll");
_model.TestProject.Returns(project);
_model.TestCentricProject.Returns(project);

_strategy = GetDisplayStrategy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void TreeShowsProperResult(ResultState resultState, int expectedIndex)
_model.LoadedTests.Returns(testNode);

var project = new TestCentricProject(_model, "dummy.dll");
_model.TestProject.Returns(project);
_model.TestCentricProject.Returns(project);

//var treeNode = _adapter.MakeTreeNode(result);
//_adapter.NodeIndex[suiteResult.Id] = treeNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void TreeShowsProperResult(ResultState resultState, int expectedIndex)
_model.LoadedTests.Returns(testNode);

var project = new TestCentricProject(_model, "dummy.dll");
_model.TestProject.Returns(project);
_model.TestCentricProject.Returns(project);

_model.Events.TestLoaded += Raise.Event<TestNodeEventHandler>(new TestNodeEventArgs(testNode));
_model.Events.SuiteFinished += Raise.Event<TestResultEventHandler>(new TestResultEventArgs(resultNode));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void SimulateTestLoad()

_model.HasTests.Returns(true);
_model.IsTestRunning.Returns(false);
_model.TestProject.Returns(new TestCentricProject(_model, "dummy.dll"));
_model.TestCentricProject.Returns(new TestCentricProject(_model, "dummy.dll"));

TestNode testNode = new TestNode("<test-suite id='1'/>");
_model.LoadedTests.Returns(testNode);
Expand Down
Loading

0 comments on commit fe211b9

Please sign in to comment.