summaryrefslogtreecommitdiff
path: root/src/Notepad/Presentation/Core/ApplicationControllerSpecs.cs
blob: 834ec7c3b71a0e45216b046bd7b04b3aefe3273a (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
using MbUnit.Framework;
using Rhino.Mocks;

namespace Notepad.Presentation.Core {
    public class ApplicationControllerSpecs {}

    [TestFixture]
    public class when_the_application_controller_is_asked_to_run_a_presenter_ {
        private MockRepository mockery;
        private IPresenterRegistry presenterRegistry;

        [SetUp]
        public void SetUp() {
            mockery = new MockRepository();
            presenterRegistry = mockery.DynamicMock<IPresenterRegistry>();
        }

        [Test]
        public void should_ask_the_registered_presenters_for_an_instance_of_the_presenter_to_run() {
            var implementationOfThePresenter = mockery.DynamicMock<IPresenter>();
            using (mockery.Record()) {
                Expect
                    .Call(presenterRegistry.FindAnImplementationOf<IPresenter>())
                    .Return(implementationOfThePresenter)
                    .Repeat
                    .AtLeastOnce();
            }

            using (mockery.Playback()) {
                CreateSUT().Run<IPresenter>();
            }
        }

        [Test]
        public void should_initialize_the_presenter_to_run() {
            var presenterToInitialize = mockery.DynamicMock<IPresenter>();
            using (mockery.Record()) {
                SetupResult
                    .For(presenterRegistry.FindAnImplementationOf<IPresenter>())
                    .Return(presenterToInitialize);

                presenterToInitialize.Initialize();
            }

            using (mockery.Playback()) {
                CreateSUT().Run<IPresenter>();
            }
        }

        private IApplicationController CreateSUT() {
            return new ApplicationController(presenterRegistry);
        }
    }
}