summaryrefslogtreecommitdiff
path: root/src/Notepad/Presentation/Presenters/Menu/File
diff options
context:
space:
mode:
Diffstat (limited to 'src/Notepad/Presentation/Presenters/Menu/File')
-rw-r--r--src/Notepad/Presentation/Presenters/Menu/File/ISaveAsPresenter.cs28
-rw-r--r--src/Notepad/Presentation/Presenters/Menu/File/SaveAsPresenterSpecs.cs69
2 files changed, 97 insertions, 0 deletions
diff --git a/src/Notepad/Presentation/Presenters/Menu/File/ISaveAsPresenter.cs b/src/Notepad/Presentation/Presenters/Menu/File/ISaveAsPresenter.cs
new file mode 100644
index 0000000..509d21c
--- /dev/null
+++ b/src/Notepad/Presentation/Presenters/Menu/File/ISaveAsPresenter.cs
@@ -0,0 +1,28 @@
+using Notepad.Infrastructure.Extensions;
+using Notepad.Presentation.Core;
+using Notepad.Presentation.Views.Menu.File;
+using Notepad.Tasks;
+
+namespace Notepad.Presentation.Presenters.Menu.File {
+ public interface ISaveAsPresenter : IPresenter {
+ void SaveToFileAt(string pathToSaveDocumentTo);
+ }
+
+ public class SaveAsPresenter : ISaveAsPresenter {
+ private readonly ISaveAsView view;
+ private readonly IDocumentTasks tasks;
+
+ public SaveAsPresenter(ISaveAsView view, IDocumentTasks tasks) {
+ this.view = view;
+ this.tasks = tasks;
+ }
+
+ public void Initialize() {
+ view.AttachTo(this);
+ }
+
+ public void SaveToFileAt(string pathToSaveDocumentTo) {
+ tasks.SaveActiveDocumentTo(pathToSaveDocumentTo.AsAnAbsoluteFilePath());
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Notepad/Presentation/Presenters/Menu/File/SaveAsPresenterSpecs.cs b/src/Notepad/Presentation/Presenters/Menu/File/SaveAsPresenterSpecs.cs
new file mode 100644
index 0000000..da5032f
--- /dev/null
+++ b/src/Notepad/Presentation/Presenters/Menu/File/SaveAsPresenterSpecs.cs
@@ -0,0 +1,69 @@
+using MbUnit.Framework;
+using Notepad.Infrastructure.Extensions;
+using Notepad.Presentation.Model.Menu.File.Commands;
+using Notepad.Presentation.Views.Menu.File;
+using Notepad.Tasks;
+using Rhino.Mocks;
+
+namespace Notepad.Presentation.Presenters.Menu.File {
+ public class SaveAsPresenterSpecs {}
+
+ [TestFixture]
+ public class when_initializing_the_save_as_presenter_ {
+ private MockRepository mockery;
+ private ISaveAsView view;
+ private ISaveAsPresenter sut;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ view = mockery.DynamicMock<ISaveAsView>();
+
+ sut = CreateSUT();
+ }
+
+ private ISaveAsPresenter CreateSUT() {
+ return new SaveAsPresenter(view, null);
+ }
+
+ [Test]
+ public void should_initialize_the_view_with_itself() {
+ using (mockery.Record()) {
+ view.AttachTo(sut);
+ }
+
+ using (mockery.Playback()) {
+ sut.Initialize();
+ }
+ }
+ }
+
+ [TestFixture]
+ public class when_selecting_a_file_path_to_save_to_ {
+ private MockRepository mockery;
+ private ISaveCommand saveCommand;
+ private IDocumentTasks tasks;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ tasks = mockery.DynamicMock<IDocumentTasks>();
+ }
+
+ [Test]
+ public void should_ask_the_active_document_to_save_the_path_specified() {
+ var pathToSaveFileTo = "some path";
+ using (mockery.Record()) {
+ tasks.SaveActiveDocumentTo(pathToSaveFileTo.AsAnAbsoluteFilePath());
+ }
+
+ using (mockery.Playback()) {
+ CreateSUT().SaveToFileAt(pathToSaveFileTo);
+ }
+ }
+
+ private ISaveAsPresenter CreateSUT() {
+ return new SaveAsPresenter(null, tasks);
+ }
+ }
+} \ No newline at end of file