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()); }
partial void DeleteWidget(Widget instance);
partial void UpdateWidget(Widget instance);
partial void InsertWidget(Widget instance);
public void Save(Widget widget, Widget originalWidget) { if (widget.Id > 0) { // Update _db.Widgets.Attach(widget, originalWidget); } else { // Create _db.Widgets.InsertOnSubmit(widget); } _db.SubmitChanges(); }
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); }