I have a Prism DialogService to show a user control in a dialog box(with OK and Cancel buttons), and I use it this way
private void AddProduct()
{
Product selectedProduct = null;
_dialogService.ShowDialog("AddProduct", new DialogParameters(" "), r =>
{
selectedProduct = r.Parameters.GetValue<Product>("SelectedProduct");
});
if(selectedProduct == null) return
Products.Add(selectedProduct)
}
The dialogservice assigned in the constructor call like this:
public ProductViewModel(IDialogService dialogService)
{
_dialogService = dialogService;
}
The dialog registered in the container:
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterDialog<Product, ProductViewModel>();
}
It works well but I am not able to unit test my code after the return statement
if(selectedProduct == null)
, because selectedProduct is always null.
I'm using Nunit and Moq framework to mock the _DialogService.ShowDialog() method.
Maybe my approach for AddProduct dialog is not good, or maybe I am missing something, so any suggestion would be a great help for me
What I have tried:
I mocked the ShowDialog method but it will never set selectedProduct value