summaryrefslogtreecommitdiff
path: root/src/Notepad/Presentation/Context
diff options
context:
space:
mode:
Diffstat (limited to 'src/Notepad/Presentation/Context')
-rw-r--r--src/Notepad/Presentation/Context/NotepadApplicationContext.cs18
-rw-r--r--src/Notepad/Presentation/Context/NotepadApplicationContextSpecs.cs80
2 files changed, 98 insertions, 0 deletions
diff --git a/src/Notepad/Presentation/Context/NotepadApplicationContext.cs b/src/Notepad/Presentation/Context/NotepadApplicationContext.cs
new file mode 100644
index 0000000..8fda742
--- /dev/null
+++ b/src/Notepad/Presentation/Context/NotepadApplicationContext.cs
@@ -0,0 +1,18 @@
+using System.Windows.Forms;
+using Notepad.Presentation.Core;
+using Notepad.Presentation.Model.Menu.File.Commands;
+using Notepad.Presentation.Presenters.Shell;
+using Notepad.Presentation.Views.Shell;
+
+namespace Notepad.Presentation.Context {
+ public class NotepadApplicationContext : ApplicationContext {
+ public NotepadApplicationContext(
+ WindowShell shellView,
+ IExitCommand exitCommand,
+ IApplicationController applicationController) {
+ shellView.Closed += delegate { exitCommand.Execute(); };
+ applicationController.Run<IMainShellPresenter>();
+ MainForm = shellView;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Notepad/Presentation/Context/NotepadApplicationContextSpecs.cs b/src/Notepad/Presentation/Context/NotepadApplicationContextSpecs.cs
new file mode 100644
index 0000000..f8b9765
--- /dev/null
+++ b/src/Notepad/Presentation/Context/NotepadApplicationContextSpecs.cs
@@ -0,0 +1,80 @@
+using MbUnit.Framework;
+using Notepad.Presentation.Context;
+using Notepad.Presentation.Core;
+using Notepad.Presentation.Model.Menu.File.Commands;
+using Notepad.Presentation.Presenters.Shell;
+using Notepad.Presentation.Views.Shell;
+using Notepad.Test.Extensions;
+using Rhino.Mocks;
+using Rhino.Mocks.Constraints;
+using Rhino.Mocks.Interfaces;
+
+namespace Notepad.Presentation.Context {
+ public class NotepadApplicationContextSpecs {}
+
+ [TestFixture]
+ public class when_creating_the_application_context_ {
+ private MockRepository mockery;
+ private WindowShell shellView;
+ private IExitCommand exitCommand;
+ private IApplicationController applicationController;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ shellView = mockery.DynamicMock<WindowShell>();
+ exitCommand = mockery.DynamicMock<IExitCommand>();
+ applicationController = mockery.DynamicMock<IApplicationController>();
+ }
+
+ [Test]
+ public void should_register_for_the_main_shell_views_closing_event() {
+ using (mockery.Record()) {
+ shellView.Closed += null;
+ LastCall.Constraints(Is.NotNull());
+ }
+ using (mockery.Playback()) {
+ CreateSUT();
+ }
+ }
+
+ [Test]
+ public void should_execute_the_exit_application_command() {
+ IEventRaiser raiser;
+ using (mockery.Record()) {
+ shellView.Closed += null;
+ raiser = LastCall.Constraints(Is.NotNull()).GetEventRaiser();
+
+ exitCommand.Execute();
+ }
+ using (mockery.Playback()) {
+ CreateSUT();
+ raiser.Raise(null, null);
+ }
+ }
+
+ [Test]
+ public void should_specify_the_main_shell_view_as_the_main_form() {
+ using (mockery.Record()) {}
+
+ using (mockery.Playback()) {
+ CreateSUT().MainForm.ShouldBeEqualTo(shellView);
+ }
+ }
+
+ [Test]
+ public void should_run_the_main_shell_presenter() {
+ using (mockery.Record()) {
+ applicationController.Run<IMainShellPresenter>();
+ }
+
+ using (mockery.Playback()) {
+ CreateSUT();
+ }
+ }
+
+ private NotepadApplicationContext CreateSUT() {
+ return new NotepadApplicationContext(shellView, exitCommand, applicationController);
+ }
+ }
+} \ No newline at end of file