public void SearchText_WhenChanged_ExecutesASearch(
            String searchText, Int32 brandId, Int32 categoryId,
            Boolean expectsNonEmptyResult)
        {
            // arrange
            var dialogService = new Mock <IDialogService>();
            var sut           = new XamlMVVMDemoCodeViewModel(_businessServiceMock, dialogService.Object);

            sut.OnNavigatedTo(_navigationContext);

            sut.SelectedBrand    = sut.Brands.Single(x => x.BrandIdent == brandId);
            sut.SelectedCategory = sut.Categories.Single(x => x.CategoryIdent == categoryId);

            // act

            sut.SearchText = searchText;

            // assert
            if (sut.SearchResults == null || sut.SearchResults.Count == 0)
            {
                Assert.True(expectsNonEmptyResult == false);
            }
            else
            {
                Assert.True((sut.SearchResults.Count == 1) == expectsNonEmptyResult);
                Assert.True((sut.SearchResults[0].ProductIdent == TestIdentValue) == expectsNonEmptyResult);
            }
        }
        public void SettingSelectedCategory_ExecutesSearch()
        {
            // arrange
            var dialogService = new Mock <IDialogService>();
            var sut           = new XamlMVVMDemoCodeViewModel(_businessServiceMock, dialogService.Object);

            sut.OnNavigatedTo(_navigationContext);

            // act

            // assert
            Assert.PropertyChanged(sut, "SearchResults", () => sut.SelectedCategory = sut.Categories.Single(x => x.CategoryIdent == TestIdentValue));
        }
        public void OnNavigatedTo_SetsDefaultSelectedItem_ForBrandAndCategory()
        {
            // arrange
            var dialogService = new Mock <IDialogService>();
            var sut           = new XamlMVVMDemoCodeViewModel(_businessServiceMock, dialogService.Object);

            // act
            sut.OnNavigatedTo(_navigationContext);

            // assert
            Assert.True(sut.SelectedBrand.BrandIdent == 0 && sut.SelectedBrand.Name == TestAllBrands);
            Assert.True(sut.SelectedCategory.CategoryIdent == 0 && sut.SelectedCategory.Name == TestAllCategories);
        }
        public void SettingSearchStringToEmpty_MakesSearchResults_Null()
        {
            // arrange
            var dialogService = new Mock <IDialogService>();
            var sut           = new XamlMVVMDemoCodeViewModel(_businessServiceMock, dialogService.Object);

            sut.OnNavigatedTo(_navigationContext);

            // act
            sut.SearchText = String.Empty;

            // assert
            Assert.Null(sut.SearchResults);
        }
        public void OnNavigatedTo_LoadsData()
        {
            // arrange
            var dialogService = new Mock <IDialogService>();
            var sut           = new XamlMVVMDemoCodeViewModel(
                _businessServiceMock, dialogService.Object);

            // act
            sut.OnNavigatedTo(_navigationContext);

            // assert
            Assert.True(sut.Brands.Count() == 3);
            Assert.True(sut.Categories.Count() == 2);
        }
        public void EditProductCommandExecute_Raises_IsNameFocused_PropertyChanged()
        {
            // arrange
            var dialogService = new Mock <IDialogService>();
            var searchResult  = new SearchResult {
                ProductIdent = TestIdentValue
            };
            var sut = new XamlMVVMDemoCodeViewModel(_businessServiceMock, dialogService.Object);

            sut.OnNavigatedTo(_navigationContext); // loads the data

            // act

            // assert
            Assert.PropertyChanged(sut, "IsNameFocused", () => sut.EditProductCommand.Execute(searchResult));
        }
        public void EditProductCommandExecute_ProductWithSameIdent_IsAvailableToUI()
        {
            // arrange
            var dialogService = new Mock <IDialogService>();
            var searchResult  = new SearchResult {
                ProductIdent = TestIdentValue
            };
            var sut = new XamlMVVMDemoCodeViewModel(_businessServiceMock, dialogService.Object);

            sut.OnNavigatedTo(_navigationContext); // loads the data

            // act
            sut.EditProductCommand.Execute(searchResult);

            // assert
            Assert.True(sut.Product.ProductIdent == searchResult.ProductIdent);
        }
        public void ConfirmNavigationRequest_WhenCallBackIsTrue_NoDialogIsDisplayed()
        {
            // arrange
            var dialogService = new Mock <IDialogService>();

            dialogService.Setup(x => x.ConfirmDialog(It.IsAny <String>(), It.IsAny <String>())).Returns(DialogResult.No);

            var sut = new XamlMVVMDemoCodeViewModel(_businessServiceMock, dialogService.Object);

            sut.OnNavigatedTo(_navigationContext);

            var test = false;

            // act
            sut.ConfirmNavigationRequest(It.IsAny <Prism.Regions.NavigationContext>(), confirm => test = confirm);

            // assert
            Assert.True(test);
            dialogService.Verify(x => x.ConfirmDialog(It.IsAny <String>(), It.IsAny <String>()), Times.Never());
        }
        public void ProductThatIsDirty_ConfirmNavigationRequest_CallBackIsFalseWhenDialogResultIsCancel()
        {
            // arrange
            var dialogService = new Mock <IDialogService>();

            dialogService.Setup(x => x.ConfirmDialog(It.IsAny <String>(), It.IsAny <String>())).Returns(DialogResult.Cancel);

            var sut = new XamlMVVMDemoCodeViewModel(_businessServiceMock, dialogService.Object);

            sut.OnNavigatedTo(_navigationContext);
            sut.Product = new Product {
                IsDirty = true
            };

            var test = false;

            // act
            sut.ConfirmNavigationRequest(It.IsAny <Prism.Regions.NavigationContext>(), confirm => test = confirm);

            // assert
            Assert.False(test);
            dialogService.Verify(x => x.ConfirmDialog(It.IsAny <String>(), It.IsAny <String>()), Times.Once);
        }