Inheritance: Waf.InformationManager.Common.Domain.ValidationModel
Esempio n. 1
0
        public void PropertiesTest()
        {
            var emailAccount = new EmailAccount();

            AssertHelper.PropertyChangedEvent(emailAccount, x => x.Name, () => emailAccount.Name = "Harry Thompson");
            Assert.AreEqual("Harry Thompson", emailAccount.Name);

            AssertHelper.PropertyChangedEvent(emailAccount, x => x.Email, () => emailAccount.Email = "*****@*****.**");
            Assert.AreEqual("*****@*****.**", emailAccount.Email);

            var exchangeSettings = new ExchangeSettings();
            AssertHelper.PropertyChangedEvent(emailAccount, x => x.EmailAccountSettings, () => emailAccount.EmailAccountSettings = exchangeSettings);
            Assert.AreEqual(exchangeSettings, emailAccount.EmailAccountSettings);
        }
Esempio n. 2
0
        public void ValidationTest()
        {
            var longText = "*****@*****.**";
            var emailAccount = new EmailAccount();

            Assert.AreEqual("The Name field is required.", emailAccount.Validate(nameof(EmailAccount.Name)));
            emailAccount.Name = "bill";
            Assert.AreEqual("", emailAccount.Validate(nameof(EmailAccount.Name)));

            Assert.AreEqual("The Email Address field is required.", emailAccount.Validate(nameof(EmailAccount.Email)));
            emailAccount.Email = longText;
            Assert.AreEqual("The field Email Address must be a string with a maximum length of 100.", emailAccount.Validate(nameof(EmailAccount.Email)));
            emailAccount.Email = "wrong email address";
            Assert.AreEqual("The Email Address field is not a valid e-mail address.", emailAccount.Validate(nameof(EmailAccount.Email)));
            emailAccount.Email = "*****@*****.**";
            Assert.AreEqual("", emailAccount.Validate(nameof(EmailAccount.Email)));
        }
Esempio n. 3
0
        public void CloneTest()
        {
            var exchangeSettings = new ExchangeSettings() { UserName = "******" };
            var emailAccount = new EmailAccount() { Name = "Harry Thompson", Email = "*****@*****.**", EmailAccountSettings = exchangeSettings };
            var clone = emailAccount.Clone();

            Assert.AreNotEqual(emailAccount, clone);
            Assert.AreEqual(emailAccount.Name, clone.Name);
            Assert.AreEqual(emailAccount.Email, clone.Email);
            
            Assert.AreNotEqual(emailAccount.EmailAccountSettings, clone.EmailAccountSettings);
            Assert.AreEqual(((ExchangeSettings)emailAccount.EmailAccountSettings).UserName, ((ExchangeSettings)clone.EmailAccountSettings).UserName);

            emailAccount.EmailAccountSettings = null;
            clone = emailAccount.Clone();
            Assert.IsNull(clone.EmailAccountSettings);
        }
        private void EditEmailAccountControllerRun(Action<MockEditEmailAccountView> showDialogAction, EmailAccount emailAccount)
        {
            var ownerWindow = new object();
            var controller = Container.GetExportedValue<EditEmailAccountController>();
            controller.OwnerWindow = ownerWindow;
            controller.EmailAccount = emailAccount;
            controller.Initialize();

            bool showDialogCalled = false;
            MockEditEmailAccountView.ShowDialogAction = v =>
            {
                showDialogCalled = true;
                showDialogAction(v);
            };
            controller.Run();
            Assert.IsTrue(showDialogCalled);

            MockEditEmailAccountView.ShowDialogAction = null;
        }
Esempio n. 5
0
        public void EmailAccountsTest()
        {
            var root = new EmailClientRoot();
            Assert.IsFalse(root.EmailAccounts.Any());

            var emailAccount1 = new EmailAccount();
            root.AddEmailAccount(emailAccount1);
            Assert.AreEqual(emailAccount1, root.EmailAccounts.Single());

            var emailAccount2 = new EmailAccount();
            root.AddEmailAccount(emailAccount2);
            Assert.IsTrue(root.EmailAccounts.SequenceEqual(new[] { emailAccount1, emailAccount2 }));

            root.RemoveEmailAccount(emailAccount1);
            Assert.AreEqual(emailAccount2, root.EmailAccounts.Single());

            var emailAccount3 = new EmailAccount();
            root.ReplaceEmailAccount(emailAccount2, emailAccount3);
            Assert.AreEqual(emailAccount3, root.EmailAccounts.Single());
        }
        public void PropertiesTest()
        {
            var viewModel = Container.GetExportedValue<BasicEmailAccountViewModel>();

            Assert.IsTrue(viewModel.IsPop3Checked);
            Assert.IsFalse(viewModel.IsExchangeChecked);

            // Set the email account and check that the boolean flags are set right.

            var emailAccount = new EmailAccount();
            emailAccount.EmailAccountSettings = new Pop3Settings();

            AssertHelper.PropertyChangedEvent(viewModel, x => x.EmailAccount, () => viewModel.EmailAccount = emailAccount);
            Assert.AreEqual(emailAccount, viewModel.EmailAccount);

            Assert.IsTrue(viewModel.IsPop3Checked);
            Assert.IsFalse(viewModel.IsExchangeChecked);

            emailAccount = new EmailAccount();
            emailAccount.EmailAccountSettings = new ExchangeSettings();
            viewModel.EmailAccount = emailAccount;

            Assert.IsFalse(viewModel.IsPop3Checked);
            Assert.IsTrue(viewModel.IsExchangeChecked);

            // Change the boolean flags

            AssertHelper.PropertyChangedEvent(viewModel, x => x.IsPop3Checked, () => viewModel.IsPop3Checked = true);

            Assert.IsTrue(viewModel.IsPop3Checked);
            Assert.IsFalse(viewModel.IsExchangeChecked);

            AssertHelper.PropertyChangedEvent(viewModel, x => x.IsExchangeChecked, () => viewModel.IsExchangeChecked = true);

            Assert.IsFalse(viewModel.IsPop3Checked);
            Assert.IsTrue(viewModel.IsExchangeChecked);

            AssertHelper.PropertyChangedEvent(viewModel, x => x.IsExchangeChecked, () => viewModel.IsPop3Checked = true);
            AssertHelper.PropertyChangedEvent(viewModel, x => x.IsPop3Checked, () => viewModel.IsExchangeChecked = true);
        }
Esempio n. 7
0
 public void AddEmailAccount(EmailAccount emailAccount)
 {
     emailAccounts.Add(emailAccount);
 }
Esempio n. 8
0
 public void ReplaceEmailAccount(EmailAccount oldEmailAccount, EmailAccount newEmailAccount)
 {
     int index = emailAccounts.IndexOf(oldEmailAccount);
     emailAccounts[index] = newEmailAccount;
 }
 public void EditExchangeEmailAccount()
 {
     var emailAccount = new EmailAccount() { EmailAccountSettings = new ExchangeSettings() };
     EditEmailAccountControllerRun(EditExchangeEmailAccountDialog, emailAccount);
 }
 public void NewExchangeEmailAccount()
 {
     var emailAccount = new EmailAccount();
     EditEmailAccountControllerRun(EditExchangeEmailAccountDialog, emailAccount);
 }
 public void EditPop3EmailAccount()
 {
     var emailAccount = new EmailAccount() { EmailAccountSettings = new Pop3Settings() };
     EditEmailAccountControllerRun(EditPop3EmailAccountDialog, emailAccount);
 }
 public void NewPop3EmailAccount()
 {
     var emailAccount = new EmailAccount();
     EditEmailAccountControllerRun(EditPop3EmailAccountDialog, emailAccount);
 }
Esempio n. 13
0
 public void AddEmailAccount(EmailAccount emailAccount)
 {
     emailAccounts.Add(emailAccount);
 }
Esempio n. 14
0
 public static EmailAccount CreateEmailAccount()
 {
     var emailAccount = new EmailAccount() { Name = "Harry Thompson", Email = "*****@*****.**" };
     emailAccount.EmailAccountSettings = new ExchangeSettings() { ServerPath = "exchange.example.com", UserName = "******" };
     return emailAccount;
 }
Esempio n. 15
0
 public void RemoveEmailAccount(EmailAccount emailAccount)
 {
     emailAccounts.Remove(emailAccount);
 }
Esempio n. 16
0
 public void RemoveEmailAccount(EmailAccount emailAccount)
 {
     emailAccounts.Remove(emailAccount);
 }
Esempio n. 17
0
        public void TrySendNewEmailWithWrongEmailAddresses()
        {
            var root = new EmailClientRoot();
            var emailAccount = new EmailAccount() { Email = "*****@*****.**" };
            root.AddEmailAccount(emailAccount);

            var controller = Container.GetExportedValue<NewEmailController>();
            controller.Root = root;
            controller.Initialize();

            // Create a new email with a wrong address

            var newEmailViewModel = controller.NewEmailViewModel;
            var newEmailView = (MockNewEmailView)newEmailViewModel.View;

            controller.Run();

            Assert.IsTrue(newEmailView.IsVisible);

            newEmailViewModel.To = "wrong address";

            // Try to send the email => error message occurs

            var messageService = Container.GetExportedValue<MockMessageService>();
            messageService.Clear();

            newEmailViewModel.SendCommand.Execute(null);

            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.IsNotNull(messageService.Message);
            Assert.IsFalse(root.Sent.Emails.Any());

            // The view stays open

            Assert.IsTrue(newEmailView.IsVisible);
        }
Esempio n. 18
0
        public void SendNewEmail()
        {
            var root = new EmailClientRoot();
            var emailAccount = new EmailAccount() { Email = "*****@*****.**" };
            root.AddEmailAccount(emailAccount);

            var controller = Container.GetExportedValue<NewEmailController>();
            controller.Root = root;
            controller.Initialize();

            // Create a new email

            var newEmailViewModel = controller.NewEmailViewModel;
            var newEmailView = (MockNewEmailView)newEmailViewModel.View;

            controller.Run();

            Assert.IsTrue(newEmailView.IsVisible);
            Assert.AreEqual(emailAccount, newEmailViewModel.SelectedEmailAccount);

            // Select a contact for the To field and cancel the dialog

            var addressBookService = Container.GetExportedValue<MockAddressBookService>();
            ContactDto contactResult = null;
            addressBookService.ShowSelectContactViewAction = owner =>
            {
                Assert.AreEqual(newEmailView, owner);
                return contactResult;
            };

            newEmailViewModel.SelectContactCommand.Execute("To");

            // Select a contact for the To field

            contactResult = new ContactDto("", "", "*****@*****.**");
            newEmailViewModel.SelectContactCommand.Execute("To");
            Assert.AreEqual("*****@*****.**", newEmailViewModel.To);

            // Select a contact for the CC field

            contactResult = new ContactDto("", "", "*****@*****.**");
            newEmailViewModel.SelectContactCommand.Execute("CC");
            Assert.AreEqual("*****@*****.**", newEmailViewModel.CC);

            // Select a contact for the BCC field

            contactResult = new ContactDto("", "", "*****@*****.**");
            newEmailViewModel.SelectContactCommand.Execute("Bcc");
            Assert.AreEqual("*****@*****.**", newEmailViewModel.Bcc);

            // Pass a wrong parameter to the command => exception
            
            AssertHelper.ExpectedException<ArgumentException>(() => newEmailViewModel.SelectContactCommand.Execute("Wrong field"));

            // Send the email

            newEmailViewModel.SendCommand.Execute(null);

            var sendEmail = root.Sent.Emails.Single();
            Assert.AreEqual("*****@*****.**", sendEmail.From);
            Assert.AreNotEqual(new DateTime(0), sendEmail.Sent);

            Assert.IsFalse(newEmailView.IsVisible);
        }
Esempio n. 19
0
        public void ReplaceEmailAccount(EmailAccount oldEmailAccount, EmailAccount newEmailAccount)
        {
            int index = emailAccounts.IndexOf(oldEmailAccount);

            emailAccounts[index] = newEmailAccount;
        }