Skip to content

Commit c3ddd6e

Browse files
committed
Show error message box when loading a tcproj failed (instead of crash)
1 parent 1aea4cc commit c3ddd6e

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace TestCentric.Gui.Presenters.Main
1313
{
14+
using System.Runtime.InteropServices;
15+
using System.Runtime.InteropServices.ComTypes;
1416
using Elements;
1517
using Model;
1618
using NUnit.Common;
@@ -95,6 +97,17 @@ public void OpenTestCentricProjectCommand_NoFileSelected_DoesNotCreateProject(st
9597
_model.DidNotReceiveWithAnyArgs().OpenExistingProject(null);
9698
}
9799

100+
[Test]
101+
public void OpenTestCentricProjectCommand_ThrowsException_ErrorMessage_IsDisplayed()
102+
{
103+
_view.DialogManager.GetFileOpenPath(null, null).ReturnsForAnyArgs("Test.dll");
104+
_model.When(m => m.OpenExistingProject("Test.dll")).Do(x => throw new IOException("Disk error"));
105+
106+
_view.OpenTestCentricProjectCommand.Execute += Raise.Event<CommandHandler>();
107+
108+
_view.MessageDisplay.Received().Error(Arg.Any<string>());
109+
}
110+
98111
[Test]
99112
public void OpenTestCentricProjectCommand_IsEnabled()
100113
{

src/GuiRunner/TestCentric.Gui/Presenters/TestCentricPresenter.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,16 @@ private void OpenTestCentricProject()
589589
var filter = "TestCentric Projects (*.tcproj)|*.tcproj";
590590

591591
string file = _view.DialogManager.GetFileOpenPath("Existing Project", filter);
592-
if (!string.IsNullOrEmpty(file))
593-
_model.OpenExistingProject(file);
592+
593+
try
594+
{
595+
if (!string.IsNullOrEmpty(file))
596+
_model.OpenExistingProject(file);
597+
}
598+
catch (Exception exception)
599+
{
600+
_view.MessageDisplay.Error("Unable to open project\n\n" + MessageBuilder.FromException(exception));
601+
}
594602
}
595603

596604
private void OpenTestAssembly()

0 commit comments

Comments
 (0)