diff options
Diffstat (limited to 'src/Notepad/Presentation/Model/Menu/File/Commands')
4 files changed, 174 insertions, 0 deletions
diff --git a/src/Notepad/Presentation/Model/Menu/File/Commands/ExitCommandSpecs.cs b/src/Notepad/Presentation/Model/Menu/File/Commands/ExitCommandSpecs.cs new file mode 100644 index 0000000..00855b6 --- /dev/null +++ b/src/Notepad/Presentation/Model/Menu/File/Commands/ExitCommandSpecs.cs @@ -0,0 +1,34 @@ +using MbUnit.Framework;
+using Notepad.Infrastructure.System;
+using Rhino.Mocks;
+
+namespace Notepad.Presentation.Model.Menu.File.Commands {
+ public class ExitCommandSpecs {}
+
+ [TestFixture]
+ public class when_executing_the_exit_command_specs_ {
+ private MockRepository mockery;
+ private IApplicationEnvironment application;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ application = mockery.DynamicMock<IApplicationEnvironment>();
+ }
+
+ [Test]
+ public void should_ask_the_application_environment_to_shut_down() {
+ using (mockery.Record()) {
+ application.ShutDown();
+ }
+
+ using (mockery.Playback()) {
+ CreateSUT().Execute();
+ }
+ }
+
+ private IExitCommand CreateSUT() {
+ return new ExitCommand(application);
+ }
+ }
+}
\ No newline at end of file diff --git a/src/Notepad/Presentation/Model/Menu/File/Commands/IExitCommand.cs b/src/Notepad/Presentation/Model/Menu/File/Commands/IExitCommand.cs new file mode 100644 index 0000000..a78c32b --- /dev/null +++ b/src/Notepad/Presentation/Model/Menu/File/Commands/IExitCommand.cs @@ -0,0 +1,18 @@ +using Notepad.Infrastructure.Core;
+using Notepad.Infrastructure.System;
+
+namespace Notepad.Presentation.Model.Menu.File.Commands {
+ public interface IExitCommand : ICommand {}
+
+ public class ExitCommand : IExitCommand {
+ private readonly IApplicationEnvironment application;
+
+ public ExitCommand(IApplicationEnvironment application) {
+ this.application = application;
+ }
+
+ public void Execute() {
+ application.ShutDown();
+ }
+ }
+}
\ No newline at end of file diff --git a/src/Notepad/Presentation/Model/Menu/File/Commands/ISaveCommand.cs b/src/Notepad/Presentation/Model/Menu/File/Commands/ISaveCommand.cs new file mode 100644 index 0000000..ea7c396 --- /dev/null +++ b/src/Notepad/Presentation/Model/Menu/File/Commands/ISaveCommand.cs @@ -0,0 +1,27 @@ +using Notepad.Infrastructure.Core;
+using Notepad.Presentation.Core;
+using Notepad.Presentation.Presenters.Menu.File;
+using Notepad.Tasks;
+
+namespace Notepad.Presentation.Model.Menu.File.Commands {
+ public interface ISaveCommand : ICommand {}
+
+ public class SaveCommand : ISaveCommand {
+ private readonly IApplicationController controller;
+ private readonly IDocumentTasks tasks;
+
+ public SaveCommand(IApplicationController controller, IDocumentTasks tasks) {
+ this.controller = controller;
+ this.tasks = tasks;
+ }
+
+ public void Execute() {
+ if (!tasks.HasAPathToSaveToBeenSpecified()) {
+ controller.Run<ISaveAsPresenter>();
+ }
+ else {
+ tasks.SaveTheActiveDocument();
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/src/Notepad/Presentation/Model/Menu/File/Commands/SaveCommandSpecs.cs b/src/Notepad/Presentation/Model/Menu/File/Commands/SaveCommandSpecs.cs new file mode 100644 index 0000000..7e4d827 --- /dev/null +++ b/src/Notepad/Presentation/Model/Menu/File/Commands/SaveCommandSpecs.cs @@ -0,0 +1,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);
+ }
+ }
+}
\ No newline at end of file |
