master
  1using MbUnit.Framework;
  2using Notepad.Presentation.Model.Menu.File.Commands;
  3using Notepad.Presentation.Presenters.Commands;
  4using Notepad.Presentation.Presenters.Menu.File;
  5using Notepad.Test.Extensions;
  6using Rhino.Mocks;
  7
  8namespace Notepad.Presentation.Model.Menu.File {
  9    public class SaveAsMenuItemSpecs {}
 10
 11    [TestFixture]
 12    public class when_asking_the_save_as_menu_item_for_its_name_ {
 13        [Test]
 14        public void should_return_the_correct_name() {
 15            CreateSUT().Name().ShouldBeEqualTo("Save &As...");
 16        }
 17
 18        private IMenuItem CreateSUT() {
 19            return new SaveAsMenuItem(null);
 20        }
 21    }
 22
 23    [TestFixture]
 24    public class when_clicking_on_the_save_as_menu_item_ {
 25        private MockRepository mockery;
 26        private IRunPresenterCommand<ISaveAsPresenter> saveAsCommand;
 27
 28        [SetUp]
 29        public void SetUp() {
 30            mockery = new MockRepository();
 31            saveAsCommand = mockery.DynamicMock<IRunPresenterCommand<ISaveAsPresenter>>();
 32        }
 33
 34        [Test]
 35        public void should_execute_the_save_as_command() {
 36            using (mockery.Record()) {}
 37
 38            using (mockery.Playback()) {
 39                CreateSUT().Click();
 40            }
 41        }
 42
 43        private IMenuItem CreateSUT() {
 44            return new SaveAsMenuItem(saveAsCommand);
 45        }
 46    }
 47
 48    [TestFixture]
 49    public class when_asking_the_save_as_menu_item_if_it_belongs_to_a_menu_that_it_does {
 50        private MockRepository mockery;
 51        private ISubMenu fileMenu;
 52
 53        [SetUp]
 54        public void SetUp() {
 55            mockery = new MockRepository();
 56            fileMenu = mockery.DynamicMock<ISubMenu>();
 57
 58            SetupResult.For(fileMenu.Name()).Return(MenuNames.File);
 59        }
 60
 61        [Test]
 62        public void should_return_true() {
 63            using (mockery.Record()) {}
 64
 65            using (mockery.Playback()) {
 66                CreateSUT().BelongsTo(fileMenu).ShouldBeEqualTo(true);
 67            }
 68        }
 69
 70        private IMenuItem CreateSUT() {
 71            return new SaveAsMenuItem(null);
 72        }
 73    }
 74
 75    [TestFixture]
 76    public class when_asking_the_save_as_menu_item_if_it_belongs_to_a_menu_item_that_it_does_not {
 77        private MockRepository mockery;
 78        private ISubMenu unknownMenu;
 79
 80        [SetUp]
 81        public void SetUp() {
 82            mockery = new MockRepository();
 83            unknownMenu = mockery.DynamicMock<ISubMenu>();
 84
 85            SetupResult.For(unknownMenu.Name()).Return("blah");
 86        }
 87
 88        [Test]
 89        public void should_return_false() {
 90            using (mockery.Record()) {}
 91
 92            using (mockery.Playback()) {
 93                CreateSUT().BelongsTo(unknownMenu).ShouldBeEqualTo(false);
 94            }
 95        }
 96
 97
 98        private IMenuItem CreateSUT() {
 99            return new SaveAsMenuItem(null);
100        }
101    }
102}