diff options
| author | mo <mo.khan@gmail.com> | 2018-11-04 15:22:16 -0700 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2018-11-04 15:22:16 -0700 |
| commit | 5ee1f55497a4e30322a56f133f897ecde1612967 (patch) | |
| tree | bf544e0879234c3623869627d8786776cb19b8e9 /src/Notepad/Presentation/Presenters/Menu | |
Diffstat (limited to 'src/Notepad/Presentation/Presenters/Menu')
6 files changed, 264 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 diff --git a/src/Notepad/Presentation/Presenters/Menu/Help/AboutApplicationPresenterSpecs.cs b/src/Notepad/Presentation/Presenters/Menu/Help/AboutApplicationPresenterSpecs.cs new file mode 100644 index 0000000..26d7148 --- /dev/null +++ b/src/Notepad/Presentation/Presenters/Menu/Help/AboutApplicationPresenterSpecs.cs @@ -0,0 +1,34 @@ +using MbUnit.Framework;
+using Notepad.Presentation.Views.Menu.Help;
+using Rhino.Mocks;
+
+namespace Notepad.Presentation.Presenters.Menu.Help {
+ public class AboutApplicationPresenterSpecs {}
+
+ [TestFixture]
+ public class when_initializing_the_application_information_presenter_ {
+ private MockRepository mockery;
+ private IAboutApplicationView view;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ view = mockery.DynamicMock<IAboutApplicationView>();
+ }
+
+ [Test]
+ public void should_display_the_view() {
+ using (mockery.Record()) {
+ view.Display();
+ }
+
+ using (mockery.Playback()) {
+ CreateSUT().Initialize();
+ }
+ }
+
+ private IAboutApplicationPresenter CreateSUT() {
+ return new AboutApplicationPresenter(view);
+ }
+ }
+}
\ No newline at end of file diff --git a/src/Notepad/Presentation/Presenters/Menu/Help/IAboutApplicationPresenter.cs b/src/Notepad/Presentation/Presenters/Menu/Help/IAboutApplicationPresenter.cs new file mode 100644 index 0000000..f4c593f --- /dev/null +++ b/src/Notepad/Presentation/Presenters/Menu/Help/IAboutApplicationPresenter.cs @@ -0,0 +1,18 @@ +using Notepad.Presentation.Core;
+using Notepad.Presentation.Views.Menu.Help;
+
+namespace Notepad.Presentation.Presenters.Menu.Help {
+ public interface IAboutApplicationPresenter : IPresenter {}
+
+ public class AboutApplicationPresenter : IAboutApplicationPresenter {
+ private readonly IAboutApplicationView view;
+
+ public AboutApplicationPresenter(IAboutApplicationView view) {
+ this.view = view;
+ }
+
+ public void Initialize() {
+ view.Display();
+ }
+ }
+}
\ No newline at end of file diff --git a/src/Notepad/Presentation/Presenters/Menu/IMainMenuPresenter.cs b/src/Notepad/Presentation/Presenters/Menu/IMainMenuPresenter.cs new file mode 100644 index 0000000..b40507d --- /dev/null +++ b/src/Notepad/Presentation/Presenters/Menu/IMainMenuPresenter.cs @@ -0,0 +1,29 @@ +using Notepad.Domain.Repositories;
+using Notepad.Infrastructure.Extensions;
+using Notepad.Presentation.Core;
+using Notepad.Presentation.Model.Menu;
+using Notepad.Presentation.Views.Menu;
+
+namespace Notepad.Presentation.Presenters.Menu {
+ public interface IMainMenuPresenter : IPresenter {}
+
+ public class MainMenuPresenter : IMainMenuPresenter {
+ private readonly IMainMenuView mainMenu;
+ private readonly IRepository<ISubMenu> repository;
+ private readonly ISubMenuItemComparer comparer;
+
+ public MainMenuPresenter(IMainMenuView mainMenu,
+ IRepository<ISubMenu> repository,
+ ISubMenuItemComparer comparer) {
+ this.mainMenu = mainMenu;
+ this.repository = repository;
+ this.comparer = comparer;
+ }
+
+ public void Initialize() {
+ foreach (var subMenuToAddToMainMenu in repository.All().SortedUsing(comparer)) {
+ mainMenu.Add(subMenuToAddToMainMenu);
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/src/Notepad/Presentation/Presenters/Menu/MainMenuPresenterSpecs.cs b/src/Notepad/Presentation/Presenters/Menu/MainMenuPresenterSpecs.cs new file mode 100644 index 0000000..a1b708b --- /dev/null +++ b/src/Notepad/Presentation/Presenters/Menu/MainMenuPresenterSpecs.cs @@ -0,0 +1,86 @@ +using System.Collections.Generic;
+using MbUnit.Framework;
+using Notepad.Domain.Repositories;
+using Notepad.Presentation.Model.Menu;
+using Notepad.Presentation.Views.Menu;
+using Rhino.Mocks;
+
+namespace Notepad.Presentation.Presenters.Menu {
+ public class MainMenuPresenterSpecs {}
+
+ [TestFixture]
+ public class when_initializing_the_main_menu_presenter_ {
+ private MockRepository mockery;
+ private IRepository<ISubMenu> repository;
+ private IMainMenuView mainMenu;
+ private ISubMenuItemComparer comparer;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ repository = mockery.DynamicMock<IRepository<ISubMenu>>();
+ mainMenu = mockery.DynamicMock<IMainMenuView>();
+ comparer = mockery.DynamicMock<ISubMenuItemComparer>();
+ }
+
+ [Test]
+ public void should_ask_the_repository_for_all_the_sub_menus() {
+ var subMenus = new List<ISubMenu>();
+ using (mockery.Record()) {
+ Expect
+ .Call(repository.All())
+ .Return(subMenus)
+ .Repeat
+ .AtLeastOnce();
+ }
+
+ using (mockery.Playback()) {
+ CreateSUT().Initialize();
+ }
+ }
+
+ [Test]
+ public void should_add_each_of_the_sub_menus_to_the_main_menu() {
+ var fileMenu = mockery.DynamicMock<ISubMenu>();
+ var subMenus = new List<ISubMenu> {fileMenu};
+
+ using (mockery.Record()) {
+ SetupResult
+ .For(repository.All())
+ .Return(subMenus);
+ mainMenu.Add(fileMenu);
+ }
+
+ using (mockery.Playback()) {
+ CreateSUT().Initialize();
+ }
+ }
+
+ [Test]
+ public void should_sort_the_sub_menus_using_the_comparer() {
+ var firstMenu = mockery.DynamicMock<ISubMenu>();
+ var secondMenu = mockery.DynamicMock<ISubMenu>();
+
+ var subMenus = new List<ISubMenu> {firstMenu, secondMenu};
+
+ using (mockery.Record()) {
+ SetupResult
+ .For(repository.All())
+ .Return(subMenus);
+ Expect
+ .Call(comparer.Compare(firstMenu, secondMenu))
+ .Return(0)
+ .Repeat
+ .AtLeastOnce();
+ }
+
+ using (mockery.Playback()) {
+ CreateSUT().Initialize();
+ }
+ }
+
+ private IMainMenuPresenter CreateSUT() {
+ return new MainMenuPresenter(mainMenu, repository, comparer);
+ }
+ }
+}
\ No newline at end of file |
