AddEmailAccount() public method

public AddEmailAccount ( EmailAccount emailAccount ) : void
emailAccount EmailAccount
return void
Esempio n. 1
0
        public void PropertiesTest()
        {
            var viewModel = Container.GetExportedValue<EmailAccountsViewModel>();

            var root = new EmailClientRoot();
            AssertHelper.PropertyChangedEvent(viewModel, x => x.EmailClientRoot, () => viewModel.EmailClientRoot = root);
            Assert.AreEqual(root, viewModel.EmailClientRoot);

            root = new EmailClientRoot();
            root.AddEmailAccount(new EmailAccount());
            root.AddEmailAccount(new EmailAccount());
            AssertHelper.PropertyChangedEvent(viewModel, x => x.SelectedEmailAccount, () => viewModel.EmailClientRoot = root);
            Assert.AreEqual(root.EmailAccounts.First(), viewModel.SelectedEmailAccount);

            AssertHelper.PropertyChangedEvent(viewModel, x => x.SelectedEmailAccount, () => viewModel.SelectedEmailAccount = root.EmailAccounts.ElementAt(1));
            Assert.AreEqual(root.EmailAccounts.ElementAt(1), viewModel.SelectedEmailAccount);

            var emptyCommand = new DelegateCommand(() => { });
            AssertHelper.PropertyChangedEvent(viewModel, x => x.NewAccountCommand, () => viewModel.NewAccountCommand = emptyCommand);
            Assert.AreEqual(emptyCommand, viewModel.NewAccountCommand);

            AssertHelper.PropertyChangedEvent(viewModel, x => x.RemoveAccountCommand, () => viewModel.RemoveAccountCommand = emptyCommand);
            Assert.AreEqual(emptyCommand, viewModel.RemoveAccountCommand);

            AssertHelper.PropertyChangedEvent(viewModel, x => x.EditAccountCommand, () => viewModel.EditAccountCommand = emptyCommand);
            Assert.AreEqual(emptyCommand, viewModel.EditAccountCommand);
        }
Esempio n. 2
0
        public void Initialize()
        {
            using (var stream = documentService.GetStream(documentPartPath, MediaTypeNames.Text.Xml, FileMode.Open))
            {
                if (stream.Length == 0)
                {
                    this.root = new EmailClientRoot();
                    root.AddEmailAccount(SampleDataProvider.CreateEmailAccount());
                    foreach (var email in SampleDataProvider.CreateInboxEmails()) { root.Inbox.AddEmail(email); }
                    foreach (var email in SampleDataProvider.CreateSentEmails()) { root.Sent.AddEmail(email); }
                    foreach (var email in SampleDataProvider.CreateDrafts()) { root.Drafts.AddEmail(email); }
                }
                else
                {
                    root = (EmailClientRoot)serializer.Value.ReadObject(stream);
                }
            }

            emailAccountsController.Root = root;

            INavigationNode node = navigationService.AddNavigationNode("Inbox", ShowInbox, CloseCurrentView, 1, 1);
            itemCountSychronizers.Add(new ItemCountSynchronizer(node, root.Inbox));
            node = navigationService.AddNavigationNode("Outbox", ShowOutbox, CloseCurrentView, 1, 2);
            itemCountSychronizers.Add(new ItemCountSynchronizer(node, root.Outbox));
            node = navigationService.AddNavigationNode("Sent", ShowSentEmails, CloseCurrentView, 1, 3);
            itemCountSychronizers.Add(new ItemCountSynchronizer(node, root.Sent));
            node = navigationService.AddNavigationNode("Drafts", ShowDrafts, CloseCurrentView, 1, 4);
            itemCountSychronizers.Add(new ItemCountSynchronizer(node, root.Drafts));
            node = navigationService.AddNavigationNode("Deleted", ShowDeletedEmails, CloseCurrentView, 1, 5);
            itemCountSychronizers.Add(new ItemCountSynchronizer(node, root.Deleted));
        }
Esempio n. 3
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());
        }
Esempio n. 4
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. 5
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. 6
0
 public SampleEmailAccountsViewModel() : base(new MockEmailAccountsView())
 {
     var root = new EmailClientRoot();
     root.AddEmailAccount(SampleDataProvider.CreateEmailAccount());
     base.EmailClientRoot = root;
 }