Inheritance: Waf.InformationManager.Common.Domain.ValidationModel, IEmailDeletionService
Example #1
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));
        }
        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);
        }
Example #3
0
 public SampleEmailListViewModel() : base(new MockEmailListView())
 {
     EmailClientRoot root = new EmailClientRoot();
     foreach (var email in SampleDataProvider.CreateInboxEmails()) { root.Inbox.AddEmail(email); }
     Emails = root.Inbox.Emails;
     FilterText = "My filter text";
 }
Example #4
0
 public ModuleController(CompositionContainer container, IShellService shellService, INavigationService navigationService,
     EmailAccountsController emailAccountsController)
 {
     this.container = container;
     this.shellService = shellService;
     this.navigationService = navigationService;
     this.emailAccountsController = emailAccountsController;
     this.newEmailCommand = new DelegateCommand(NewEmail);
     this.root = new EmailClientRoot();
     this.itemCountSychronizers = new List<ItemCountSynchronizer>();
 }
        public void NewEditAndRemoveEmailAccount()
        {
            var root = new EmailClientRoot();
            var controller = Container.GetExportedValue<EmailAccountsController>();
            controller.Root = root;

            bool showDialogCalled = false;
            MockEmailAccountsView.ShowDialogAction = v =>
            {
                showDialogCalled = true;
                EmailAccountsViewShowDialog(v);
            };

            controller.EmailAccountsCommand.Execute(null);
            Assert.IsTrue(showDialogCalled);
            MockEmailAccountsView.ShowDialogAction = null;
        }
Example #6
0
        public void EmailFolderTest()
        {
            var root = new EmailClientRoot();

            Assert.IsNotNull(root.Inbox);
            Assert.IsNotNull(root.Outbox);
            Assert.IsNotNull(root.Sent);
            Assert.IsNotNull(root.Drafts);
            Assert.IsNotNull(root.Deleted);

            var email1 = new Email();
            root.Inbox.AddEmail(email1);
            root.Inbox.RemoveEmail(email1);
            Assert.AreEqual(email1, root.Deleted.Emails.Single());

            root.Deleted.RemoveEmail(email1);
            Assert.IsFalse(root.Deleted.Emails.Any());
        }
Example #7
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());
        }
Example #8
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);
        }
        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);
        }
        public void TryCreateNewEmailWithoutEmailAccounts()
        {
            var root = new EmailClientRoot();

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

            // Create a new email but no email account was created => error message

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

            controller.Run();

            Assert.AreEqual(MessageType.Error, messageService.MessageType);
            Assert.IsNotNull(messageService.Message);

            var newEmailViewModel = controller.NewEmailViewModel;
            var newEmailView = (MockNewEmailView)newEmailViewModel.View;
            Assert.IsFalse(newEmailView.IsVisible);
        }
        public void DeleteEmails()
        {
            var root = new EmailClientRoot();
            root.Inbox.AddEmail(new Email());
            root.Inbox.AddEmail(new Email());
            var email1 = root.Inbox.Emails.First();

            // Create the controller

            var controller = Container.GetExportedValue<EmailFolderController>();
            var emailLayoutViewModel = Container.GetExportedValue<EmailLayoutViewModel>();
            var emailListViewModel = controller.EmailListViewModel;
            var emailListView = (MockEmailListView)emailListViewModel.View;
            var emailViewModel = controller.EmailViewModel;
            var emailView = (MockEmailView)emailViewModel.View;

            // Initialize the controller

            Assert.IsNull(emailLayoutViewModel.EmailListView);
            Assert.IsNull(emailLayoutViewModel.EmailView);

            controller.EmailFolder = root.Inbox;
            controller.Initialize();

            Assert.AreEqual(emailListView, emailLayoutViewModel.EmailListView);
            Assert.AreEqual(emailView, emailLayoutViewModel.EmailView);

            // Run the controller

            var shellService = Container.GetExportedValue<MockShellService>();
            Assert.IsNull(shellService.ContentView);

            controller.Run();

            Assert.AreEqual(emailLayoutViewModel.View, shellService.ContentView);

            // Delete command is disabled when no Email is selected

            Assert.IsNull(emailListViewModel.SelectedEmail);
            Assert.IsFalse(controller.DeleteEmailCommand.CanExecute(null));

            // Select the first email and delete it

            emailListViewModel.EmailCollectionView = emailListViewModel.Emails;

            bool focusItemCalled = false;
            emailListView.FocusItemAction = view =>
            {
                focusItemCalled = true;
            };

            var emailToDelete = root.Inbox.Emails.First();
            AssertHelper.PropertyChangedEvent(emailViewModel, x => x.Email, () => emailListViewModel.SelectedEmail = emailToDelete);
            Assert.AreEqual(emailToDelete, emailViewModel.Email);

            controller.DeleteEmailCommand.Execute(null);

            Assert.IsFalse(root.Inbox.Emails.Contains(emailToDelete));
            Assert.IsTrue(focusItemCalled);

            // Remove selection => delete command gets disabled

            AssertHelper.CanExecuteChangedEvent(controller.DeleteEmailCommand, () => emailListViewModel.SelectedEmail = null);
            Assert.IsFalse(controller.DeleteEmailCommand.CanExecute(null));

            // Select the second and last email and delete it

            emailListViewModel.SelectedEmail = root.Inbox.Emails.Single();
            controller.DeleteEmailCommand.Execute(null);
            Assert.IsFalse(root.Inbox.Emails.Any());
            Assert.IsNull(emailListViewModel.SelectedEmail);

            // Shutdown the controller

            controller.Shutdown();

            Assert.IsNull(emailLayoutViewModel.EmailListView);
            Assert.IsNull(emailLayoutViewModel.EmailView);
        }
Example #12
0
 public SampleEmailAccountsViewModel() : base(new MockEmailAccountsView())
 {
     var root = new EmailClientRoot();
     root.AddEmailAccount(SampleDataProvider.CreateEmailAccount());
     base.EmailClientRoot = root;
 }