summaryrefslogtreecommitdiff
path: root/src/Notepad/Presentation/Model/Menu/File/Commands/SaveCommandSpecs.cs
blob: 7e4d827a93e4dcea1122f8e3b6bde7cdbd339cac (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using MbUnit.Framework;
using Notepad.Presentation.Core;
using Notepad.Presentation.Presenters.Menu.File;
using Notepad.Tasks;
using Rhino.Mocks;

namespace Notepad.Presentation.Model.Menu.File.Commands {
    public class SaveCommandSpecs {}

    [TestFixture]
    public class when_executing_the_save_command_and_a_file_path_to_save_to_has_not_been_specified_ {
        private MockRepository mockery;
        private IApplicationController applicationController;
        private IDocumentTasks tasks;

        [SetUp]
        public void SetUp() {
            mockery = new MockRepository();
            applicationController = mockery.DynamicMock<IApplicationController>();
            tasks = mockery.DynamicMock<IDocumentTasks>();

            SetupResult.For(tasks.HasAPathToSaveToBeenSpecified()).Return(false);
        }

        [Test]
        public void should_run_the_save_as_presenter() {
            using (mockery.Record()) {
                applicationController.Run<ISaveAsPresenter>();
            }

            using (mockery.Playback()) {
                CreateSUT().Execute();
            }
        }

        [Test]
        public void should_not_save_the_active_document() {
            using (mockery.Record()) {
                tasks.SaveTheActiveDocument();
                LastCall.Repeat.Never();
            }

            using (mockery.Playback()) {
                CreateSUT().Execute();
            }
        }

        private ISaveCommand CreateSUT() {
            return new SaveCommand(applicationController, tasks);
        }
    }

    [TestFixture]
    public class when_executing_the_save_command_and_a_path_to_save_to_has_already_been_specified_ {
        private MockRepository mockery;
        private IApplicationController applicationController;
        private IDocumentTasks tasks;

        [SetUp]
        public void SetUp() {
            mockery = new MockRepository();
            applicationController = mockery.DynamicMock<IApplicationController>();
            tasks = mockery.DynamicMock<IDocumentTasks>();

            SetupResult.For(tasks.HasAPathToSaveToBeenSpecified()).Return(true);
        }

        [Test]
        public void should_not_run_the_save_as_presenter() {
            using (mockery.Record()) {
                applicationController.Run<ISaveAsPresenter>();
                LastCall.Repeat.Never();
            }

            using (mockery.Playback()) {
                CreateSUT().Execute();
            }
        }

        [Test]
        public void should_save_the_active_document() {
            using (mockery.Record()) {
                tasks.SaveTheActiveDocument();
            }

            using (mockery.Playback()) {
                CreateSUT().Execute();
            }
        }

        private ISaveCommand CreateSUT() {
            return new SaveCommand(applicationController, tasks);
        }
    }
}