Prism-Documentation icon indicating copy to clipboard operation
Prism-Documentation copied to clipboard

[Testing] Testing Error with IDialogAware implemented ViewModel The DialogCloseCallback has not been properly initialized

Open james1301 opened this issue 6 months ago • 2 comments

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.

image

Repo: https://github.com/james1301/PrismDialogTestingError

Steps to Reproduce

  1. Create a class that implements IDialogAware, with a method that invokes to close the ViewModel e.g. this.RequestClose.Invoke(dialogResult);
  2. Create a unit test to call that method.
  3. 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()

james1301 avatar Aug 23 '24 10:08 james1301