Prism-Documentation
Prism-Documentation copied to clipboard
[Testing] Testing Error with IDialogAware implemented ViewModel The DialogCloseCallback has not been properly initialized
Description
Trying to test a ViewModel that implements IDialogAware in Prism 9.0 produces an error that crashes TestExplorer as it fires from an async void on invocation of the DialogCloseListener.
Repo: https://github.com/james1301/PrismDialogTestingError
Steps to Reproduce
- Create a class that implements IDialogAware, with a method that invokes to close the ViewModel
e.g.
this.RequestClose.Invoke(dialogResult);
- Create a unit test to call that method.
- Error in Test Output window
Platform with bug
WPF
Affected platforms
Windows
Did you find any workaround?
To set use DialogUtitlities to initialise the listener.
e.g. DialogUtilities.InitializeListener(viewModel, (r) => { });
Relevant log output
Unhandled exception. System.InvalidOperationException: The DialogCloseCallback has not been properly initialized. This must be initialized by the DialogService, and should not be set by user code.
at Prism.Dialogs.DialogCloseListener.Invoke(IDialogResult result)
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
at System.Threading.QueueUserWorkItemCallback.Execute()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()