コード例 #1
0
        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;
        }
コード例 #2
0
        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;
        }
コード例 #3
0
 public ContactController(ILogService logService, IAddressBookService addressBookService, ContactListViewModel contactListViewModel)
 {
     this.logService         = logService;
     this.addressBookService = addressBookService;
     viewModel            = contactListViewModel;
     selectContactCommand = new DelegateCommand(SelectContact, CanSelectContact);
     deleteContactCommand = new DelegateCommand(DeleteContact, CanDeleteContact);
     root = new AddressBookRoot();
     contactListViewModel.PropertyChanged += ContactListViewModelPropertyChanged;
 }
コード例 #4
0
ファイル: ContactTest.cs プロジェクト: uzbekdev1/waf
        public void ValidationTest()
        {
            var root    = new AddressBookRoot();
            var contact = root.AddNewContact();

            Assert.AreEqual(nameof(contact.Firstname), contact.Errors.Single().MemberNames.Single());
            contact.Firstname = "Jesper";
            Assert.AreEqual(0, contact.Errors.Count);

            contact.Email = "*****@*****.**";
            Assert.IsFalse(contact.HasErrors);

            contact.Email = "jesper.aaberg@";
            Assert.AreEqual("The Email field is not a valid e-mail address.", contact.Errors.Single().ErrorMessage);
        }
コード例 #5
0
ファイル: AddressBookRootTest.cs プロジェクト: zwq00000/waf
        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 }));
        }
コード例 #6
0
ファイル: ContactControllerTest.cs プロジェクト: jbe2277/waf
    public void AddAndRemoveContacts()
    {
        var root     = new AddressBookRoot();
        var contact1 = root.AddNewContact();

        // Create the controller

        var controller             = Get <ContactController>();
        var contactLayoutViewModel = Get <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 = Get <MockShellService>();

        Assert.IsNull(shellService.ContentView);

        controller.Run();

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

        // Add a new contact

        bool focusItemCalled = false;

        contactListView.FocusItemAction = _ => focusItemCalled = true;
        controller.NewContactCommand.Execute(null);

        Assert.AreEqual(2, root.Contacts.Count);
        var contact2 = root.Contacts[^ 1];
コード例 #7
0
 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);
 }
コード例 #8
0
        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.Contacts = 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);
        }