summaryrefslogtreecommitdiff
path: root/src/Notepad/Presentation/Model/Menu/Help
diff options
context:
space:
mode:
Diffstat (limited to 'src/Notepad/Presentation/Model/Menu/Help')
-rw-r--r--src/Notepad/Presentation/Model/Menu/Help/AboutMenuItem.cs24
-rw-r--r--src/Notepad/Presentation/Model/Menu/Help/AboutMenuItemSpecs.cs101
-rw-r--r--src/Notepad/Presentation/Model/Menu/Help/HelpMenu.cs21
-rw-r--r--src/Notepad/Presentation/Model/Menu/Help/HelpMenuSpecs.cs76
4 files changed, 222 insertions, 0 deletions
diff --git a/src/Notepad/Presentation/Model/Menu/Help/AboutMenuItem.cs b/src/Notepad/Presentation/Model/Menu/Help/AboutMenuItem.cs
new file mode 100644
index 0000000..82a2839
--- /dev/null
+++ b/src/Notepad/Presentation/Model/Menu/Help/AboutMenuItem.cs
@@ -0,0 +1,24 @@
+using Notepad.Presentation.Presenters.Commands;
+using Notepad.Presentation.Presenters.Menu.Help;
+
+namespace Notepad.Presentation.Model.Menu.Help {
+ public class AboutMenuItem : IMenuItem {
+ private readonly IRunPresenterCommand<IAboutApplicationPresenter> displayAboutCommand;
+
+ public AboutMenuItem(IRunPresenterCommand<IAboutApplicationPresenter> displayAboutCommand) {
+ this.displayAboutCommand = displayAboutCommand;
+ }
+
+ public bool BelongsTo(ISubMenu menu) {
+ return menu.Name().Equals(MenuNames.Help);
+ }
+
+ public void Click() {
+ displayAboutCommand.Execute();
+ }
+
+ public string Name() {
+ return MenuItemNames.About;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Notepad/Presentation/Model/Menu/Help/AboutMenuItemSpecs.cs b/src/Notepad/Presentation/Model/Menu/Help/AboutMenuItemSpecs.cs
new file mode 100644
index 0000000..74d7663
--- /dev/null
+++ b/src/Notepad/Presentation/Model/Menu/Help/AboutMenuItemSpecs.cs
@@ -0,0 +1,101 @@
+using MbUnit.Framework;
+using Notepad.Presentation.Presenters.Commands;
+using Notepad.Presentation.Presenters.Menu.Help;
+using Notepad.Test.Extensions;
+using Rhino.Mocks;
+
+namespace Notepad.Presentation.Model.Menu.Help {
+ public class AboutMenuItemSpecs {}
+
+ [TestFixture]
+ public class when_asking_the_about_menu_item_for_its_name_ {
+ [Test]
+ public void should_return_the_correct_name() {
+ CreateSUT().Name().ShouldBeEqualTo(MenuItemNames.About);
+ }
+
+ private IMenuItem CreateSUT() {
+ return new AboutMenuItem(null);
+ }
+ }
+
+ [TestFixture]
+ public class when_clicking_on_the_about_menu_item_ {
+ private MockRepository mockery;
+ private IRunPresenterCommand<IAboutApplicationPresenter> displayAboutCommand;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ displayAboutCommand = mockery.DynamicMock<IRunPresenterCommand<IAboutApplicationPresenter>>();
+ }
+
+ [Test]
+ public void should_execute_the_display_about_command() {
+ using (mockery.Record()) {}
+
+ using (mockery.Playback()) {
+ CreateSUT().Click();
+ }
+ }
+
+ private IMenuItem CreateSUT() {
+ return new AboutMenuItem(displayAboutCommand);
+ }
+ }
+
+ [TestFixture]
+ public class when_asking_the_about_menu_item_if_it_belongs_to_a_menu_that_it_does {
+ private MockRepository mockery;
+ private ISubMenu menuThatThisItemBelongsTo;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ menuThatThisItemBelongsTo = mockery.DynamicMock<ISubMenu>();
+
+ SetupResult.For(menuThatThisItemBelongsTo.Name()).Return(MenuNames.Help);
+ }
+
+ [Test]
+ public void should_return_true() {
+ using (mockery.Record()) {}
+
+ using (mockery.Playback()) {
+ CreateSUT().BelongsTo(menuThatThisItemBelongsTo).ShouldBeEqualTo(true);
+ }
+ }
+
+ private IMenuItem CreateSUT() {
+ return new AboutMenuItem(null);
+ }
+ }
+
+ [TestFixture]
+ public class when_asking_the_about_menu_item_if_it_belongs_to_a_menu_item_that_it_does_not {
+ private MockRepository mockery;
+ private ISubMenu unknownMenu;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ unknownMenu = mockery.DynamicMock<ISubMenu>();
+
+ SetupResult.For(unknownMenu.Name()).Return("blah");
+ }
+
+ [Test]
+ public void should_return_false() {
+ using (mockery.Record()) {}
+
+ using (mockery.Playback()) {
+ CreateSUT().BelongsTo(unknownMenu).ShouldBeEqualTo(false);
+ }
+ }
+
+
+ private IMenuItem CreateSUT() {
+ return new AboutMenuItem(null);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Notepad/Presentation/Model/Menu/Help/HelpMenu.cs b/src/Notepad/Presentation/Model/Menu/Help/HelpMenu.cs
new file mode 100644
index 0000000..ace9696
--- /dev/null
+++ b/src/Notepad/Presentation/Model/Menu/Help/HelpMenu.cs
@@ -0,0 +1,21 @@
+using System.Collections.Generic;
+using Notepad.Domain.Repositories;
+using Notepad.Infrastructure.Extensions;
+
+namespace Notepad.Presentation.Model.Menu.Help {
+ public class HelpMenu : ISubMenu {
+ private readonly IRepository<IMenuItem> menuItems;
+
+ public HelpMenu(IRepository<IMenuItem> repository) {
+ menuItems = repository;
+ }
+
+ public IEnumerable<IMenuItem> AllMenuItems() {
+ return menuItems.All().ThatSatisfy(m => m.BelongsTo(this));
+ }
+
+ public string Name() {
+ return MenuNames.Help;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Notepad/Presentation/Model/Menu/Help/HelpMenuSpecs.cs b/src/Notepad/Presentation/Model/Menu/Help/HelpMenuSpecs.cs
new file mode 100644
index 0000000..c716376
--- /dev/null
+++ b/src/Notepad/Presentation/Model/Menu/Help/HelpMenuSpecs.cs
@@ -0,0 +1,76 @@
+using System.Collections.Generic;
+using MbUnit.Framework;
+using Notepad.Domain.Repositories;
+using Notepad.Infrastructure.Extensions;
+using Notepad.Presentation.Model.Menu.Help;
+using Notepad.Test.Extensions;
+using Rhino.Mocks;
+
+namespace Notepad.Presentation.Model.Menu.Help {
+ public class HelpMenuSpecs {}
+
+ [TestFixture]
+ public class when_asking_the_help_menu_for_its_name_ {
+ [Test]
+ public void should_return_the_correct_name() {
+ CreateSUT().Name().ShouldBeEqualTo(MenuNames.Help);
+ }
+
+ private ISubMenu CreateSUT() {
+ return new HelpMenu(null);
+ }
+ }
+
+ [TestFixture]
+ public class when_asking_the_help_menu_for_its_menu_items_ {
+ private MockRepository mockery;
+ private IRepository<IMenuItem> repository;
+ private ISubMenu sut;
+
+ [SetUp]
+ public void SetUp() {
+ mockery = new MockRepository();
+ repository = mockery.DynamicMock<IRepository<IMenuItem>>();
+ sut = CreateSUT();
+ }
+
+ [Test]
+ public void should_ask_the_repository_for_all_the_menu_items() {
+ using (mockery.Record()) {
+ Expect
+ .Call(repository.All())
+ .Return(new List<IMenuItem>())
+ .Repeat
+ .AtLeastOnce();
+ }
+
+ using (mockery.Playback()) {
+ sut.AllMenuItems().Walk();
+ }
+ }
+
+ [Test]
+ public void should_return_the_menu_items_that_belong_to_the_help_menu() {
+ var saveMenuItem = mockery.DynamicMock<IMenuItem>();
+ var helpMenuItem = mockery.DynamicMock<IMenuItem>();
+
+ var allMenuItems = new List<IMenuItem> {saveMenuItem, helpMenuItem};
+
+ using (mockery.Record()) {
+ SetupResult.For(repository.All()).Return(allMenuItems);
+ SetupResult.For(saveMenuItem.BelongsTo(sut)).Return(false);
+ SetupResult.For(helpMenuItem.BelongsTo(sut)).Return(true);
+ }
+
+ using (mockery.Playback()) {
+ var returnedItems = sut.AllMenuItems();
+ returnedItems.ShouldNotContain(saveMenuItem);
+ returnedItems.ShouldContain(helpMenuItem);
+ }
+ }
+
+ private ISubMenu CreateSUT() {
+ return new HelpMenu(repository);
+ }
+ }
+} \ No newline at end of file