public void buttonCancel_Click_ShouldCallCloseOnActiveForm() { MockRepository mock = new MockRepository(); Wizard wizard = new Wizard(); IWizardFormFactory formFactory = mock.StrictMock <IWizardFormFactory>(); WizardForm mockForm = mock.DynamicMock <WizardForm>(); DummyPage page = new DummyPage(); wizard.Pages.AddFirst(page); wizard.WizardFormFactory = formFactory; SetUpCommonExpectationsOnFormFactory(formFactory, mockForm); SetUpCommonExpectationsOnForm(mockForm); Expect.Call(mockForm.Close); mock.ReplayAll(); wizard.StartWizard(null); Button button = new Button(); EventArgs e = new EventArgs(); wizard.buttonCancel_Click(button, e); mock.VerifyAll(); }
/// <summary> /// Start the wizard by displaying the first page. /// </summary> /// <param name="owner"></param> public DialogResult StartWizard(IWin32Window owner) { ValidatePages(); activeForm = wizardFormFactory.NewForm(); activeForm.CancelButtonObject.Click += new EventHandler(buttonCancel_Click); activeForm.BackButton.Click += new EventHandler(buttonBack_Click); activeForm.NextButton.Click += new EventHandler(buttonNext_Click); activeForm.FinishButton.Click += new EventHandler(buttonFinish_Click); currentPage = -1; NextPage(); DialogResult formResult = DialogResult.None; if (owner == null) { formResult = activeForm.ShowDialog(); } else { formResult = activeForm.ShowDialog(owner); } return(formResult); }
private void SetUpCommonExpectationsOnForm(WizardForm mockForm) { Expect.Call(mockForm.ShowDialog()).Return(DialogResult.OK); Expect.Call(mockForm.CancelButtonObject).Return(new Button()); Expect.Call(mockForm.BackButton).Repeat.Any().Return(new Button()); Expect.Call(mockForm.NextButton).Repeat.Any().Return(new Button()); Expect.Call(mockForm.FinishButton).Repeat.Any().Return(new Button()); Expect.Call(mockForm.LabelPageTitle).Return(new Label()); Expect.Call(mockForm.PageContainer).Repeat.Any().Return(new Panel()); }
private void SetUpCommonExpectationsOnFormFactory(IWizardFormFactory formFactory, WizardForm mockForm) { Expect.Call(formFactory.NewForm()).Return(mockForm); }