Inheritance: Waf.InformationManager.Common.Domain.ValidationModel
 public ModuleController(CompositionContainer container, IShellService shellService, INavigationService navigationService)
 {
     this.container = container;
     this.shellService = shellService;
     this.navigationService = navigationService;
     this.root = new AddressBookRoot();
 }
        public void SelectContactAndCancelTest()
        {
            var root = new AddressBookRoot();
            var contact1 = root.AddNewContact();
            var contact2 = root.AddNewContact();

            var controller = Container.GetExportedValue<SelectContactController>();

            controller.OwnerView = new object();
            controller.Root = root;

            controller.Initialize();

            bool showDialogActionCalled = false;
            MockSelectContactView.ShowDialogAction = view =>
            {
                showDialogActionCalled = true;
                // Do nothing, this simulates that the user has closed the window.
            };

            controller.Run();

            Assert.IsTrue(showDialogActionCalled);
            Assert.IsNull(controller.SelectedContact);

            MockSelectContactView.ShowDialogAction = null;
        }
        public void SelectContactTest()
        {
            var root = new AddressBookRoot();
            var contact1 = root.AddNewContact();
            var contact2 = root.AddNewContact();
            
            var controller = Container.GetExportedValue<SelectContactController>();

            controller.OwnerView = new object();
            controller.Root = root;

            controller.Initialize();

            MockSelectContactView.ShowDialogAction = view =>
            {
                var vm = ViewHelper.GetViewModel<SelectContactViewModel>(view);
                Assert.AreEqual(contact1, controller.ContactListViewModel.SelectedContact);

                AssertHelper.CanExecuteChangedEvent(vm.OkCommand, () => controller.ContactListViewModel.SelectedContact = null);
                Assert.IsFalse(vm.OkCommand.CanExecute(null));
                
                AssertHelper.CanExecuteChangedEvent(vm.OkCommand, () => controller.ContactListViewModel.SelectedContact = contact2);
                Assert.IsTrue(vm.OkCommand.CanExecute(null));
                
                vm.OkCommand.Execute(null);

                Assert.IsFalse(view.IsVisible);
            };

            controller.Run();

            Assert.AreEqual(contact2, controller.SelectedContact);
            MockSelectContactView.ShowDialogAction = null;
        }
        public void AddAndRemoveContacts()
        {
            var root = new AddressBookRoot();

            Assert.IsFalse(root.Contacts.Any());

            var contact1 = root.AddNewContact();
            Assert.IsTrue(root.Contacts.SequenceEqual(new[] { contact1 }));

            var contact2 = new Contact();
            root.AddContact(contact2);
            Assert.IsTrue(root.Contacts.SequenceEqual(new[] { contact1, contact2 }));

            root.RemoveContact(contact1);
            Assert.IsTrue(root.Contacts.SequenceEqual(new[] { contact2 }));
        }
        public void Initialize()
        {
            using (var stream = documentService.GetStream(documentPartPath, MediaTypeNames.Text.Xml, FileMode.Open))
            {
                if (stream.Length == 0)
                {
                    root = new AddressBookRoot();
                    foreach (var contact in SampleDataProvider.CreateContacts()) { root.AddContact(contact); }
                }
                else
                {
                    root = (AddressBookRoot)serializer.Value.ReadObject(stream);
                }
            }

            navigationService.AddNavigationNode("Contacts", ShowAddressBook, CloseAddressBook, 2, 1);
        }
        public void SelectContactTest()
        {
            var root = new AddressBookRoot();
            var contact1 = root.AddNewContact();
            var contact2 = root.AddNewContact();
            
            var controller = Container.GetExportedValue<SelectContactController>();

            controller.OwnerView = new object();
            controller.Root = root;

            controller.Initialize();

            MockSelectContactView.ShowDialogAction = view =>
            {
                controller.ContactListViewModel.SelectedContact = contact2;
                controller.SelectContactViewModel.OkCommand.Execute(null);
            };

            controller.Run();

            Assert.AreEqual(contact2, controller.SelectedContact);
            MockSelectContactView.ShowDialogAction = null;
        }
        public void AddAndRemoveContacts()
        {
            var root = new AddressBookRoot();
            var contact1 = root.AddNewContact();

            // Create the controller

            var controller = Container.GetExportedValue<ContactController>();
            var contactLayoutViewModel = Container.GetExportedValue<ContactLayoutViewModel>();
            var contactListViewModel = controller.ContactListViewModel;
            var contactListView = (MockContactListView)contactListViewModel.View;
            var contactViewModel = controller.ContactViewModel;
            var contactView = (MockContactView)contactViewModel.View;

            // Initialize the controller

            Assert.IsNull(contactLayoutViewModel.ContactListView);
            Assert.IsNull(contactLayoutViewModel.ContactView);

            controller.Root = root;
            controller.Initialize();

            Assert.AreEqual(contactListView, contactLayoutViewModel.ContactListView);
            Assert.AreEqual(contactView, contactLayoutViewModel.ContactView);

            // Run the controller

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

            controller.Run();

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

            // Add a new contact

            bool focusItemCalled = false;
            contactListView.FocusItemAction = view =>
            {
                focusItemCalled = true;
            };
            controller.NewContactCommand.Execute(null);

            Assert.AreEqual(2, root.Contacts.Count());
            var contact2 = root.Contacts.Last();
            Assert.AreEqual(contact2, contactViewModel.Contact);
            Assert.IsTrue(focusItemCalled);

            // Remove the first contact

            contactListViewModel.ContactCollectionView = root.Contacts;

            AssertHelper.CanExecuteChangedEvent(controller.DeleteContactCommand, () =>
                contactListViewModel.SelectedContact = contact1);

            controller.DeleteContactCommand.Execute(null);

            Assert.AreEqual(contact2, root.Contacts.Single());
            Assert.AreEqual(contact2, contactListViewModel.SelectedContact);

            // Remove the second contact

            controller.DeleteContactCommand.Execute(null);

            Assert.IsFalse(root.Contacts.Any());
            Assert.IsNull(contactListViewModel.SelectedContact);

            // Check that a delete is not possible because no contacts are left

            Assert.IsFalse(controller.DeleteContactCommand.CanExecute(null));

            // Shutdown the controller

            controller.Shutdown();

            Assert.IsNull(contactLayoutViewModel.ContactListView);
            Assert.IsNull(contactLayoutViewModel.ContactView);
        }