public void GetAddressBookViewModel_WhenPassingPage_ShouldReturnModel()
        {
            var page   = new AddressBookPage();
            var result = _subject.GetAddressBookViewModel(page);

            Assert.Equal <AddressBookPage>(page, result.CurrentPage);
        }
        public void Index_WhenCreatingViewModel_ShouldCallGetViewModelOnService()
        {
            var page = new AddressBookPage();

            _subject.Index(page);

            _addressBookServiceMock.Verify(s => s.GetAddressBookViewModel(page));
        }
Example #3
0
        public void Index_WhenCreatingViewModel_ShouldCallGetViewModelOnService()
        {
            var page = new AddressBookPage();

            _subject.Index(page);

            _addressBookServiceMock.Verify(s => s.GetAddressBookViewModel(page));
        }
        public void EditForm_WhenCalledWithPage_ShouldCallLoadAddressOnService()
        {
            var page = new AddressBookPage();
            var guid = Guid.NewGuid();

            _subject.EditForm(page, guid);

            _addressBookServiceMock.Verify(s => s.LoadAddress(It.IsAny<Address>()));
        }
Example #5
0
        public void EditForm_WhenCalledWithPage_ShouldCallLoadAddressOnService()
        {
            var page = new AddressBookPage();
            var guid = Guid.NewGuid();

            _subject.EditForm(page, guid.ToString());

            _addressBookServiceMock.Verify(s => s.LoadAddress(It.IsAny <AddressModel>()));
        }
        public void Save_WhenModelStateIsValid_ShouldCallSaveOnService()
        {
            var viewModel = new AddressViewModel { Address = new Address() };
            AddressBookPage currentPage = new AddressBookPage();
            viewModel.Address.Name = "name";

            _subject.Save(currentPage, viewModel);

            _addressBookServiceMock.Verify(s => s.Save(viewModel.Address));
        }
        public void Save_WhenModelStateIsNotValid_ShouldNotCallSaveOnService()
        {
            AddressBookPage currentPage = new AddressBookPage();
            var viewModel = new AddressViewModel { Address = new Address() };
            _subject.ModelState.AddModelError("test", "not valid");

            _subject.Save(currentPage, viewModel);

            _addressBookServiceMock.Verify(s => s.Save(viewModel.Address), Times.Never);
        }
        public void Save_WhenAnotherAddressWithSameNameExists_ShouldNotSave()
        {
            AddressBookPage currentPage = new AddressBookPage();
            var viewModel = new AddressViewModel{ Address = new Address() };
            _addressBookServiceMock.Setup(x => x.CanSave(It.IsAny<Address>())).Returns(false);

            _subject.Save(currentPage, viewModel);

            _addressBookServiceMock.Verify(s => s.Save(viewModel.Address), Times.Never);
        }
Example #9
0
        public AddressCollectionViewModel GetAddressBookViewModel(AddressBookPage addressBookPage)
        {
            var model = new AddressCollectionViewModel
            {
                CurrentPage = addressBookPage,
                Addresses   = _customerContext.CurrentContact.ContactAddresses.Select(ConvertAddress)
            };

            return(model);
        }
        private Address ConvertAddress(CustomerAddress customerAddress, AddressBookPage currentPage)
        {
            Address address = null;

            if (customerAddress != null)
            {
                address = new Address();
                MapCustomerAddressToModel(address, customerAddress);
            }

            return(address);
        }
 public AddressCollectionViewModel GetAddressBookViewModel(AddressBookPage addressBookPage)
 {
     return(new AddressCollectionViewModel(addressBookPage)
     {
         CurrentContent = addressBookPage,
         Addresses = _customerService.GetCurrentContact()?
                     .Contact?
                     .ContactAddresses
                     .Select(ConvertAddress)
                     ?? Enumerable.Empty <AddressModel>()
     });
 }
        public void Save_WhenModelStateIsNotValid_ShouldNotCallSaveOnService()
        {
            AddressBookPage currentPage = new AddressBookPage();
            var             viewModel   = new AddressViewModel {
                Address = new Address()
            };

            _subject.ModelState.AddModelError("test", "not valid");

            _subject.Save(currentPage, viewModel);

            _addressBookServiceMock.Verify(s => s.Save(viewModel.Address), Times.Never);
        }
        public void Save_WhenAnotherAddressWithSameNameExists_ShouldNotSave()
        {
            AddressBookPage currentPage = new AddressBookPage();
            var             viewModel   = new AddressViewModel {
                Address = new Address()
            };

            _addressBookServiceMock.Setup(x => x.CanSave(It.IsAny <Address>())).Returns(false);

            _subject.Save(currentPage, viewModel);

            _addressBookServiceMock.Verify(s => s.Save(viewModel.Address), Times.Never);
        }
        public void Save_WhenModelStateIsValid_ShouldCallSaveOnService()
        {
            var viewModel = new AddressViewModel {
                Address = new Address()
            };
            AddressBookPage currentPage = new AddressBookPage();

            viewModel.Address.Name = "name";

            _subject.Save(currentPage, viewModel);

            _addressBookServiceMock.Verify(s => s.Save(viewModel.Address));
        }
Example #15
0
        public void Test2EditAddressTest(string oldAddress, string expected)
        {
            //Arrange
            AddressBookPage addressBook = new AddressBookPage();
            EditAddressPage editAddress = addressBook.EditAddress(oldAddress);

            addressBook = editAddress.FillAllNotRequareField(adressInput.GetCompany(),
                                                             adressInput.GetAddress2(), adressInput.GetPostCode()).Continue();

            //Act
            bool actual = addressBook.IsAddressInTableByShortAddress(expected);

            //Assert
            Assert.True(actual);
            log.Info("\"Edit Address Test\" pass");
        }
Example #16
0
        public void CreateFailedNewAddressTest()
        {
            //Arrange
            AddressBookPage   addressBook    = new AddressBookPage();
            AddNewAddressPage newAddressPage = addressBook.GoToNewAddressPage();

            newAddressPage.FillAllRequareField(invalidAdressInput.GetFirstName(), invalidAdressInput.GetLastName(),
                                               invalidAdressInput.GetAddress1(), invalidAdressInput.GetCity(), invalidAdressInput.GetPostCode(),
                                               invalidAdressInput.GetCountry(), invalidAdressInput.GetZone()).ClickContinueButton();

            //Act
            bool actual = newAddressPage.AddressForm.IsEmptyInputErrorMessage();

            //Assert
            Assert.IsTrue(actual);
            log.Info("\"Create Failed New Address Test\" pass");
        }
Example #17
0
        public void Test3DeleteAddressTest(string expected)
        {
            //Arrange
            AddressBookPage addressBook = new AddressBookPage();

            while (addressBook.IsAddressInTableByShortAddress(expected))
            {
                addressBook.GetAddressByShortAddress(expected).DeleteButton.Click();
            }

            //Act
            bool actual = addressBook.IsAddressInTableByShortAddress(expected);

            //Assert
            Assert.IsFalse(actual);
            log.Info("\"Delete Address Test\" pass");
        }
Example #18
0
        public void Test1CreateNewAddressTest(string expected)
        {
            //Arrange
            AddressBookPage   addressBook    = new AddressBookPage();
            AddNewAddressPage newAddressPage = addressBook.GoToNewAddressPage();

            addressBook = newAddressPage.FillAllRequareField(adressInput.GetFirstName(),
                                                             adressInput.GetLastName(), adressInput.GetAddress1(), adressInput.GetCity(),
                                                             adressInput.GetPostCode(), adressInput.GetCountry(), adressInput.GetZone())
                          .Continue();

            //Act
            bool actual = addressBook.IsAddressInTableByShortAddress(expected);

            //Assert
            Assert.IsTrue(actual);
            log.Info("\"Create New Address Test\" pass");
        }
Example #19
0
        public void OnSaveException_WhenActionIsSave_ShouldCreateAddressBookFormModel()
        {
            var guid        = Guid.NewGuid();
            var currentPage = new AddressBookPage();

            //Setup
            {
                Setup_form_on_HttpRequestBase(new NameValueCollection()
                {
                    { "addressId", guid.ToString() }
                });
                Setup_exception(new HttpRequestValidationException());
                Setup_RequestContext_to_contain_routed_data(currentPage);
                Setup_GetAddressBookViewModel_to_return_model_having_same_page_as_inparameter();
                Setup_exception(new HttpRequestValidationException());
                Setup_action_for_controller("save", _subject);
            }

            var result = _subject.OnSaveException(_exceptionContext);

            Assert.IsType <AddressViewModel>(((ViewResult)result).Model);
        }
Example #20
0
        public void OnSaveException_WhenCurrentPageExist_ShouldCreateViewModelWithCurrentPageSet()
        {
            var guid        = Guid.NewGuid();
            var currentPage = new AddressBookPage();

            //Setup
            {
                Setup_form_on_HttpRequestBase(new NameValueCollection()
                {
                    { "addressId", guid.ToString() }
                });
                Setup_exception(new HttpRequestValidationException());
                Setup_RequestContext_to_contain_routed_data(currentPage);
                Setup_GetAddressBookViewModel_to_return_model_having_same_page_as_inparameter();
            }

            var result = _subject.OnSaveException(_exceptionContext);

            var model = ((ViewResult)result).Model as AddressViewModel;

            Assert.Equal <AddressBookPage>(currentPage, model.CurrentPage);

            Assert.IsType <EmptyResult>(_exceptionContext.Result);
        }
        private Address ConvertAddress(CustomerAddress customerAddress, AddressBookPage currentPage)
        {
            Address address = null;

            if (customerAddress != null)
            {
                address = new Address();
                MapCustomerAddressToModel(address, customerAddress);
            }

            return address;
        }
 public AddressCollectionViewModel GetAddressBookViewModel(AddressBookPage addressBookPage)
 {
     var model = new AddressCollectionViewModel
     {
         CurrentPage = addressBookPage,
         Addresses = _customerContext.CurrentContact.ContactAddresses.Select(ConvertAddress)
     };
     return model;
 }
        public void OnSaveException_WhenActionIsSave_ShouldCreateAddressBookFormModel()
        {
            var guid = Guid.NewGuid();
            var currentPage = new AddressBookPage();

            //Setup
            {
                Setup_form_on_HttpRequestBase(new NameValueCollection() { { "addressId", guid.ToString() } });
                Setup_exception(new HttpRequestValidationException());
                Setup_RequestContext_to_contain_routed_data(currentPage);
                Setup_GetAddressBookViewModel_to_return_model_having_same_page_as_inparameter();

                Setup_exception(new HttpRequestValidationException());
                Setup_action_for_controller("save", _subject);
            }

            var result = _subject.OnSaveException(_exceptionContext);

            Assert.IsInstanceOfType(((ViewResult)result).Model, typeof(AddressViewModel));
        }
        public void OnSaveException_WhenCurrentPageExist_ShouldCreateViewModelWithCurrentPageSet()
        {
            var guid = Guid.NewGuid();
            var currentPage = new AddressBookPage();

            //Setup
            {
                Setup_form_on_HttpRequestBase(new NameValueCollection() { { "addressId", guid.ToString() } });
                Setup_exception(new HttpRequestValidationException());
                Setup_RequestContext_to_contain_routed_data(currentPage);
                Setup_GetAddressBookViewModel_to_return_model_having_same_page_as_inparameter();
            }

            var result = _subject.OnSaveException(_exceptionContext);

            var model = ((ViewResult)result).Model as AddressViewModel;
            Assert.AreEqual<AddressBookPage>(currentPage, model.CurrentPage);

            Assert.IsInstanceOfType(_exceptionContext.Result, typeof(EmptyResult));
        }
        public void GetAddressBookViewModel_WhenPassingPage_ShouldReturnModel()
        {
            var page = new AddressBookPage();
            var result = _subject.GetAddressBookViewModel(page);

            Assert.Equal<AddressBookPage>(page, result.CurrentPage);
        }