コード例 #1
0
        public void SaveContactCommand_WhenEditDuplicateContactDetailInput_ShouldDisplayAlertAndNotRaiseEventsAndNotNavigateBackToContactsPage()
        {
            _contactViewModel.FirstName     = "Juan";
            _contactViewModel.LastName      = "Dela Cruz";
            _contactViewModel.ContactNumber = "09180000000";
            _contacts = new List <ContactViewModel>();
            _contacts.Add(new ContactViewModel()
            {
                FirstName = "Rics", LastName = "Magboo", ContactNumber = "09277607229"
            });
            bool isContactAddedEventCalled   = false;
            bool isContactUpdatedEventCalled = false;

            _viewModel = new ContactDetailPageViewModel(_contactViewModel, _pageService.Object, _contacts);
            _viewModel.Contact.FirstName     = "Rics";
            _viewModel.Contact.LastName      = "Magboo";
            _viewModel.Contact.ContactNumber = "09277607229";
            _viewModel.ContactAdded         += (sender, args) => isContactAddedEventCalled = true;
            _viewModel.ContactUpdated       += (sender, args) => isContactUpdatedEventCalled = true;
            _viewModel.SaveContactCommand.Execute(null);

            _pageService.Verify(x => x.DisplayAlert(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            Assert.IsFalse(isContactAddedEventCalled);
            Assert.IsFalse(isContactUpdatedEventCalled);
            _pageService.Verify(x => x.PopAsync(), Times.Never);
            _pageService.VerifyNoOtherCalls();
        }
コード例 #2
0
        public void WhenPageDisplayedAndIsInEditMode_ShouldDisplayUpdateButtonText()
        {
            _contactViewModel.FirstName     = "Rics";
            _contactViewModel.LastName      = "Magboo";
            _contactViewModel.ContactNumber = "09277607229";

            _viewModel = new ContactDetailPageViewModel(_contactViewModel, _pageService.Object, _contacts);

            Assert.IsTrue(_viewModel.ButtonText.Contains("Update"));
        }
コード例 #3
0
        public void WhenPageDisplayedAndIsInEditMode_ShouldDisplayTheContactDetails()
        {
            _contactViewModel.FirstName     = "Rics";
            _contactViewModel.LastName      = "Magboo";
            _contactViewModel.ContactNumber = "09277607229";

            _viewModel = new ContactDetailPageViewModel(_contactViewModel, _pageService.Object, _contacts);

            Assert.IsTrue(_viewModel.Contact.FirstName.Equals(_contactViewModel.FirstName));
            Assert.IsTrue(_viewModel.Contact.LastName.Equals(_contactViewModel.LastName));
            Assert.IsTrue(_viewModel.Contact.ContactNumber.Equals(_contactViewModel.ContactNumber));
        }
コード例 #4
0
        public ContactDetailPage(Contact contact = null)
        {
            InitializeComponent();
            if (contact == null)
            {
                ViewModel = new
                            ContactDetailPageViewModel(Navigation);
            }
            else
            {
                ViewModel = new
                            ContactDetailPageViewModel(Navigation, contact);
            }

            this.BindingContext = ViewModel;
        }
コード例 #5
0
        public void SaveContactCommand_WhenLastNameIsEmpty_ShouldDisplayAlertAndNotRaiseEventsAndNotNavigateBackToContactsPage()
        {
            _contactViewModel.FirstName     = "Rics";
            _contactViewModel.LastName      = "";
            _contactViewModel.ContactNumber = "09277607229";
            bool isContactAddedEventCalled   = false;
            bool isContactUpdatedEventCalled = false;

            _viewModel = new ContactDetailPageViewModel(_contactViewModel, _pageService.Object, _contacts);
            _viewModel.ContactAdded   += (sender, args) => isContactAddedEventCalled = true;
            _viewModel.ContactUpdated += (sender, args) => isContactUpdatedEventCalled = true;
            _viewModel.SaveContactCommand.Execute(null);

            _pageService.Verify(x => x.DisplayAlert(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Once);
            Assert.IsFalse(isContactAddedEventCalled);
            Assert.IsFalse(isContactUpdatedEventCalled);
            _pageService.Verify(x => x.PopAsync(), Times.Never);
            _pageService.VerifyNoOtherCalls();
        }
コード例 #6
0
        public ContactPage()
        {
            InitializeComponent();

            ViewModel = new ContactDetailPageViewModel(Navigation);
        }
コード例 #7
0
 public ContactDetailPage(ContactDetailPageViewModel viewModel)
 {
     InitializeComponent();
     BindingContext = viewModel;
 }
コード例 #8
0
 public ContactDetailPage(PhoneContact contactInfo)
 {
     viewModel = new ContactDetailPageViewModel(contactInfo);
     InitializeComponent();
     BindingContext = viewModel;
 }
コード例 #9
0
        public void WhenPageDisplayedAndIsInAddMode_ShouldDisplayUpdateButtonText()
        {
            _viewModel = new ContactDetailPageViewModel(_contactViewModel, _pageService.Object, _contacts);

            Assert.IsTrue(_viewModel.ButtonText.Contains("Save"));
        }
コード例 #10
0
        public void WhenPageDisplayedAndIsInAddMode_ShouldDisplayAddContactTitle()
        {
            _viewModel = new ContactDetailPageViewModel(_contactViewModel, _pageService.Object, _contacts);

            Assert.IsTrue(_viewModel.PageTitle.Contains("Add"));
        }
コード例 #11
0
 public ContactDetailPage()
 {
     InitializeComponent();
     BindingContext = new ContactDetailPageViewModel();
 }