master
 1using MbUnit.Framework;
 2using Notepad.Presentation.Context;
 3using Notepad.Presentation.Core;
 4using Notepad.Presentation.Model.Menu.File.Commands;
 5using Notepad.Presentation.Presenters.Shell;
 6using Notepad.Presentation.Views.Shell;
 7using Notepad.Test.Extensions;
 8using Rhino.Mocks;
 9using Rhino.Mocks.Constraints;
10using Rhino.Mocks.Interfaces;
11
12namespace Notepad.Presentation.Context {
13    public class NotepadApplicationContextSpecs {}
14
15    [TestFixture]
16    public class when_creating_the_application_context_ {
17        private MockRepository mockery;
18        private WindowShell shellView;
19        private IExitCommand exitCommand;
20        private IApplicationController applicationController;
21
22        [SetUp]
23        public void SetUp() {
24            mockery = new MockRepository();
25            shellView = mockery.DynamicMock<WindowShell>();
26            exitCommand = mockery.DynamicMock<IExitCommand>();
27            applicationController = mockery.DynamicMock<IApplicationController>();
28        }
29
30        [Test]
31        public void should_register_for_the_main_shell_views_closing_event() {
32            using (mockery.Record()) {
33                shellView.Closed += null;
34                LastCall.Constraints(Is.NotNull());
35            }
36            using (mockery.Playback()) {
37                CreateSUT();
38            }
39        }
40
41        [Test]
42        public void should_execute_the_exit_application_command() {
43            IEventRaiser raiser;
44            using (mockery.Record()) {
45                shellView.Closed += null;
46                raiser = LastCall.Constraints(Is.NotNull()).GetEventRaiser();
47
48                exitCommand.Execute();
49            }
50            using (mockery.Playback()) {
51                CreateSUT();
52                raiser.Raise(null, null);
53            }
54        }
55
56        [Test]
57        public void should_specify_the_main_shell_view_as_the_main_form() {
58            using (mockery.Record()) {}
59
60            using (mockery.Playback()) {
61                CreateSUT().MainForm.ShouldBeEqualTo(shellView);
62            }
63        }
64
65        [Test]
66        public void should_run_the_main_shell_presenter() {
67            using (mockery.Record()) {
68                applicationController.Run<IMainShellPresenter>();
69            }
70
71            using (mockery.Playback()) {
72                CreateSUT();
73            }
74        }
75
76        private NotepadApplicationContext CreateSUT() {
77            return new NotepadApplicationContext(shellView, exitCommand, applicationController);
78        }
79    }
80}