public void EditProductCommandExecute_Raises_Product_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, "Product", () => 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);
        }