You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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()
The text was updated successfully, but these errors were encountered:
james1301
changed the title
[BUG] <title> Testing Error with IDialogAware implemented ViewModel The DialogCloseCallback has not been properly initialized
[BUG] Testing Error with IDialogAware implemented ViewModel The DialogCloseCallback has not been properly initialized
Aug 23, 2024
dansiegel
changed the title
[BUG] Testing Error with IDialogAware implemented ViewModel The DialogCloseCallback has not been properly initialized
[Testing] Testing Error with IDialogAware implemented ViewModel The DialogCloseCallback has not been properly initialized
Aug 28, 2024
thanks @james1301 I can certainly see how this would have been an issue. As you've already discovered the correct way to initialize it for Unit Testing, you'll notice that I've moved this to the Documentation repo as an issue for us to better address in the docs.
This isn't something that we're planning on changing as this is a bit by design and the helper is there for you. Note that you can can also use that callback to help you in your unit tests for instance to confirm that a parameter is properly passed back.
Yeah it wasn't so bad, for the tests I knew I had to update as RequestClose was throwing up a compiler error. It was the ones that weren't were throwing up the test runner error which was a bit harder to find and track down as there is no link to the tests that cause it.
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
e.g.
this.RequestClose.Invoke(dialogResult);
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
The text was updated successfully, but these errors were encountered: