public void InputFieldTextChanged_Test_PasswordEntryValidOthersInvalid(string to, string cc, string bcc, bool toFieldRed, bool ccFieldRed, bool bccFieldRed) { // arrange var fakeView = A.Fake <IEmailWindow>(); A.CallTo(() => fakeView.To).Returns(to); A.CallTo(() => fakeView.Cc).Returns(cc); A.CallTo(() => fakeView.Bcc).Returns(bcc); A.CallTo(() => fakeView.Password).Returns(ConvertToSecureString("password")); var fakeModel = A.Fake <IEmailModel>(); A.CallTo(() => fakeModel.IsValidEmail("*****@*****.**")).Returns(true); A.CallTo(() => fakeModel.IsValidEmail("")).Returns(false); A.CallTo(() => fakeModel.InvalidInputColour).Returns(System.Drawing.Color.Salmon); EmailWindowPresenter presenter = new EmailWindowPresenter(fakeView, fakeModel); // act presenter.InputFieldTextChanged(null, null); // assert Assert.IsFalse(fakeView.SaveAndSendButtonEnabled); Assert.IsTrue(fakeView.PwdFieldColour == System.Drawing.Color.Empty); Assert.AreEqual(toFieldRed, fakeView.ToFieldColour == System.Drawing.Color.Salmon); Assert.AreEqual(ccFieldRed, fakeView.CcFieldColour == System.Drawing.Color.Salmon); Assert.AreEqual(bccFieldRed, fakeView.BccFieldColour == System.Drawing.Color.Salmon); }
public void InputFieldTextChanged_Test_AllEntriesValid() { // arrange var fakeView = A.Fake <IEmailWindow>(); A.CallTo(() => fakeView.To).Returns("*****@*****.**"); A.CallTo(() => fakeView.Cc).Returns("*****@*****.**"); A.CallTo(() => fakeView.Bcc).Returns("*****@*****.**"); A.CallTo(() => fakeView.Password).Returns(ConvertToSecureString("password")); var fakeModel = A.Fake <IEmailModel>(); A.CallTo(() => fakeModel.IsValidEmail("*****@*****.**")).Returns(true); A.CallTo(() => fakeModel.InvalidInputColour).Returns(System.Drawing.Color.Salmon); EmailWindowPresenter presenter = new EmailWindowPresenter(fakeView, fakeModel); // act presenter.InputFieldTextChanged(null, null); // assert Assert.IsTrue(fakeView.SaveAndSendButtonEnabled); Assert.AreEqual(System.Drawing.Color.Empty, fakeView.PwdFieldColour); Assert.AreEqual(System.Drawing.Color.Empty, fakeView.ToFieldColour); Assert.AreEqual(System.Drawing.Color.Empty, fakeView.CcFieldColour); Assert.AreEqual(System.Drawing.Color.Empty, fakeView.BccFieldColour); }
public void SaveAndEmailButtonClicked(object sender, EventArgs args) { // disable controls the user shouldn't play with at this point DisableControlsDuringOperation(); // check if an invoice with this title already exists // if not, grab the title string title = GetInvoiceTitle(); if (this._view.CreatingNewInvoice) { bool exists = this._repo.InvoiceWithTitleExists(title); if (exists) { // invoice with this title already exists // tell the user via a dialog this._view.ShowErrorDialogOk("Invoice with title: " + title + " already exists. Please choose a different title."); EnableControlsAfterOperation(); return; } } // show send email dialog EmailWindowPresenter emailWindowPresenter = new EmailWindowPresenter(new EmailWindow(title, Configuration.INVALID_INPUT_COLOUR, Configuration.SenderEmailAddress, Configuration.RecipientEmailAddress), new EmailModel(Configuration.INVALID_INPUT_COLOUR)); emailWindowPresenter.View.Subject = "Invoice: " + title; // set default email subject if (this._view.CreatingNewInvoice) { emailWindowPresenter.View.SendButtonText = "Save and Send"; emailWindowPresenter.View.CancelButtonText = "Cancel Save and Send"; } else { emailWindowPresenter.View.SendButtonText = "Send"; emailWindowPresenter.View.CancelButtonText = "Cancel Send"; } DialogResult emailDialogResult = emailWindowPresenter.ShowDialog(); // send email, or cancel if (emailDialogResult == DialogResult.OK) { SetStatusBar("Sending Email", StatusBarState.InProgress); ExcelWriter excelWriter = new ExcelWriter(null, "Invoice: " + title, Configuration.SenderEmailAddress, Configuration.RecipientEmailAddress); excelWriter.AddItems(this._view.ItemsListEntries.ToList()); SecureString password = emailWindowPresenter.View.Password; string from = emailWindowPresenter.View.From; string to = emailWindowPresenter.View.To; string cc = emailWindowPresenter.View.Cc; string bcc = emailWindowPresenter.View.Bcc; string subject = emailWindowPresenter.View.Subject; string body = emailWindowPresenter.View.Body; // do it on a background thread to avoid blocking the UI BackgroundWorker sendEmailWorker = new BackgroundWorker(); sendEmailWorker.DoWork += BeginSendEmail; sendEmailWorker.RunWorkerCompleted += EndSendEmail; // new invoice will be saved to records upon successful sending of email sendEmailWorker.RunWorkerAsync(new object[] { title, excelWriter.CloseAndGetMemoryStream(), password, from, to, cc, bcc, subject, body }); } else { if (this._view.CreatingNewInvoice) { EnableControlsAfterOperation(); } else { this._view.SaveAndEmailButtonEnabled = true; this._view.SaveAndExportXLButtonEnabled = true; this._view.CancelButtonEnabled = true; SetStatusBar("Ready", StatusBarState.Ready); } } // dispose send email dialog emailWindowPresenter.DisposeDialog(); }