コード例 #1
0
        public void GetAddressBookViewModel_WhenPassingPage_ShouldReturnModel()
        {
            var page   = new AddressBookPage();
            var result = _subject.GetAddressBookViewModel(page);

            Assert.Equal <AddressBookPage>(page, result.CurrentPage);
        }
コード例 #2
0
        public void Index_WhenCreatingViewModel_ShouldCallGetViewModelOnService()
        {
            var page = new AddressBookPage();

            _subject.Index(page);

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

            _subject.Index(page);

            _addressBookServiceMock.Verify(s => s.GetAddressBookViewModel(page));
        }
コード例 #4
0
        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>()));
        }
コード例 #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>()));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public AddressCollectionViewModel GetAddressBookViewModel(AddressBookPage addressBookPage)
        {
            var model = new AddressCollectionViewModel
            {
                CurrentPage = addressBookPage,
                Addresses   = _customerContext.CurrentContact.ContactAddresses.Select(ConvertAddress)
            };

            return(model);
        }
コード例 #10
0
        private Address ConvertAddress(CustomerAddress customerAddress, AddressBookPage currentPage)
        {
            Address address = null;

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

            return(address);
        }
コード例 #11
0
 public AddressCollectionViewModel GetAddressBookViewModel(AddressBookPage addressBookPage)
 {
     return(new AddressCollectionViewModel(addressBookPage)
     {
         CurrentContent = addressBookPage,
         Addresses = _customerService.GetCurrentContact()?
                     .Contact?
                     .ContactAddresses
                     .Select(ConvertAddress)
                     ?? Enumerable.Empty <AddressModel>()
     });
 }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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));
        }
コード例 #15
0
ファイル: AddressBookTest.cs プロジェクト: orest77/Test
        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");
        }
コード例 #16
0
ファイル: AddressBookTest.cs プロジェクト: orest77/Test
        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");
        }
コード例 #17
0
ファイル: AddressBookTest.cs プロジェクト: orest77/Test
        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");
        }
コード例 #18
0
ファイル: AddressBookTest.cs プロジェクト: orest77/Test
        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");
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #21
0
        private Address ConvertAddress(CustomerAddress customerAddress, AddressBookPage currentPage)
        {
            Address address = null;

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

            return address;
        }
コード例 #22
0
 public AddressCollectionViewModel GetAddressBookViewModel(AddressBookPage addressBookPage)
 {
     var model = new AddressCollectionViewModel
     {
         CurrentPage = addressBookPage,
         Addresses = _customerContext.CurrentContact.ContactAddresses.Select(ConvertAddress)
     };
     return model;
 }
コード例 #23
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.IsInstanceOfType(((ViewResult)result).Model, typeof(AddressViewModel));
        }
コード例 #24
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.AreEqual<AddressBookPage>(currentPage, model.CurrentPage);

            Assert.IsInstanceOfType(_exceptionContext.Result, typeof(EmptyResult));
        }
コード例 #25
0
        public void GetAddressBookViewModel_WhenPassingPage_ShouldReturnModel()
        {
            var page = new AddressBookPage();
            var result = _subject.GetAddressBookViewModel(page);

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