From 5ee1f55497a4e30322a56f133f897ecde1612967 Mon Sep 17 00:00:00 2001 From: mo Date: Sun, 4 Nov 2018 15:22:16 -0700 Subject: initial commit. --- .../Model/Menu/File/Commands/ExitCommandSpecs.cs | 34 ++++++++ .../Model/Menu/File/Commands/IExitCommand.cs | 18 ++++ .../Model/Menu/File/Commands/ISaveCommand.cs | 27 ++++++ .../Model/Menu/File/Commands/SaveCommandSpecs.cs | 95 ++++++++++++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 src/Notepad/Presentation/Model/Menu/File/Commands/ExitCommandSpecs.cs create mode 100644 src/Notepad/Presentation/Model/Menu/File/Commands/IExitCommand.cs create mode 100644 src/Notepad/Presentation/Model/Menu/File/Commands/ISaveCommand.cs create mode 100644 src/Notepad/Presentation/Model/Menu/File/Commands/SaveCommandSpecs.cs (limited to 'src/Notepad/Presentation/Model/Menu/File/Commands') 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(); + } + + [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(); + } + 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(); + tasks = mockery.DynamicMock(); + + SetupResult.For(tasks.HasAPathToSaveToBeenSpecified()).Return(false); + } + + [Test] + public void should_run_the_save_as_presenter() { + using (mockery.Record()) { + applicationController.Run(); + } + + 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(); + tasks = mockery.DynamicMock(); + + SetupResult.For(tasks.HasAPathToSaveToBeenSpecified()).Return(true); + } + + [Test] + public void should_not_run_the_save_as_presenter() { + using (mockery.Record()) { + applicationController.Run(); + 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 -- cgit v1.2.3