master
 1using MbUnit.Framework;
 2using Notepad.Presentation.Core;
 3using Notepad.Presentation.Presenters.Menu.File;
 4using Notepad.Tasks;
 5using Rhino.Mocks;
 6
 7namespace Notepad.Presentation.Model.Menu.File.Commands {
 8    public class SaveCommandSpecs {}
 9
10    [TestFixture]
11    public class when_executing_the_save_command_and_a_file_path_to_save_to_has_not_been_specified_ {
12        private MockRepository mockery;
13        private IApplicationController applicationController;
14        private IDocumentTasks tasks;
15
16        [SetUp]
17        public void SetUp() {
18            mockery = new MockRepository();
19            applicationController = mockery.DynamicMock<IApplicationController>();
20            tasks = mockery.DynamicMock<IDocumentTasks>();
21
22            SetupResult.For(tasks.HasAPathToSaveToBeenSpecified()).Return(false);
23        }
24
25        [Test]
26        public void should_run_the_save_as_presenter() {
27            using (mockery.Record()) {
28                applicationController.Run<ISaveAsPresenter>();
29            }
30
31            using (mockery.Playback()) {
32                CreateSUT().Execute();
33            }
34        }
35
36        [Test]
37        public void should_not_save_the_active_document() {
38            using (mockery.Record()) {
39                tasks.SaveTheActiveDocument();
40                LastCall.Repeat.Never();
41            }
42
43            using (mockery.Playback()) {
44                CreateSUT().Execute();
45            }
46        }
47
48        private ISaveCommand CreateSUT() {
49            return new SaveCommand(applicationController, tasks);
50        }
51    }
52
53    [TestFixture]
54    public class when_executing_the_save_command_and_a_path_to_save_to_has_already_been_specified_ {
55        private MockRepository mockery;
56        private IApplicationController applicationController;
57        private IDocumentTasks tasks;
58
59        [SetUp]
60        public void SetUp() {
61            mockery = new MockRepository();
62            applicationController = mockery.DynamicMock<IApplicationController>();
63            tasks = mockery.DynamicMock<IDocumentTasks>();
64
65            SetupResult.For(tasks.HasAPathToSaveToBeenSpecified()).Return(true);
66        }
67
68        [Test]
69        public void should_not_run_the_save_as_presenter() {
70            using (mockery.Record()) {
71                applicationController.Run<ISaveAsPresenter>();
72                LastCall.Repeat.Never();
73            }
74
75            using (mockery.Playback()) {
76                CreateSUT().Execute();
77            }
78        }
79
80        [Test]
81        public void should_save_the_active_document() {
82            using (mockery.Record()) {
83                tasks.SaveTheActiveDocument();
84            }
85
86            using (mockery.Playback()) {
87                CreateSUT().Execute();
88            }
89        }
90
91        private ISaveCommand CreateSUT() {
92            return new SaveCommand(applicationController, tasks);
93        }
94    }
95}