public void LookupWidgetPresenterLoadsWidgetFromIdWhenBothIdAndNameSet()
        {
            // Arrange
            var view = MockRepository.GenerateStub<ILookupWidgetView>();
            var asyncManager = new TestAsyncTaskManager();
            var widgetRepository = MockRepository.GenerateStub<IWidgetRepository>();
            var widget = new Widget { Id = 1, Name = "Test" };

            widgetRepository.Stub(w => w.BeginFind(1, null, null)).IgnoreArguments()
                .ExecuteAsyncCallback().Return(null);
            widgetRepository.Stub(w => w.EndFind(null)).IgnoreArguments()
                .Return(widget);

            var presenter = new LookupWidgetPresenter(view, widgetRepository)
            {
                AsyncManager = asyncManager
            };

            // Act
            view.Raise(v => v.Load += null, view, new EventArgs());
            view.Raise(v => v.Finding += null, view, new FindingWidgetEventArgs { Id = 1, Name = "Blah" });
            asyncManager.ExecuteRegisteredAsyncTasks(); // Execute the tasks here as ASP.NET would normally do for us

            // Assert
            Assert.AreEqual(widget, view.Model.Widgets.First());
        }
        public void AsyncMessagesPresenter_Load_AddsMessagesToView()
        {
            // Arrange
            var view = MockRepository.GenerateStub<IView<AsyncMessagesModel>>();
            var asyncManager = new TestAsyncTaskManager();

            var presenter = new AsyncMessagesPresenter(view)
            {
                AsyncManager = asyncManager
            };

            // Act
            view.Raise(v => v.Load += null, view, new EventArgs());
            asyncManager.ExecuteRegisteredAsyncTasks(); // Execute the tasks here as ASP.NET would normally do for us

            // Assert that both begin & end handlers were called
            Assert.IsTrue(view.Model.Messages.Any(m => m.Contains("begin handler")));
            Assert.IsTrue(view.Model.Messages.Any(m => m.Contains("end handler")));
        }
        public void LookupWidgetPresenterShowsResultsOnFinding()
        {
            // Arrange
            var view = MockRepository.GenerateStub<ILookupWidgetView>();
            var asyncManager = new TestAsyncTaskManager();
            var widgetRepository = MockRepository.GenerateStub<IWidgetRepository>();
            var widget = new Widget { Id = 1, Name = "Test" };

            widgetRepository.Stub(w => w.BeginFindByName("Test", null, null)).IgnoreArguments()
                .ExecuteAsyncCallback().Return(null);
            widgetRepository.Stub(w => w.EndFindByName(null)).IgnoreArguments()
                .Return(widget);

            var presenter = new LookupWidgetPresenter(view, widgetRepository)
            {
                AsyncManager = asyncManager
            };

            // Act
            view.Raise(v => v.Load += null, view, new EventArgs());
            view.Raise(v => v.Finding += null, view, new FindingWidgetEventArgs { Name = "Test" });

            // Assert
            Assert.AreEqual(true, view.Model.ShowResults);
        }