summaryrefslogtreecommitdiff
path: root/src/Notepad/Presentation/Context/NotepadApplicationContextSpecs.cs
blob: f8b97650307435c896e02a34e8352de6c1c47349 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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);
        }
    }
}