Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
james1301 opened this issue Aug 23, 2024 · 2 comments

Comments

@james1301
Copy link

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 james1301 added the bug label Aug 23, 2024
@james1301 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 dansiegel removed the bug label Aug 28, 2024
@dansiegel 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
@dansiegel dansiegel transferred this issue from PrismLibrary/Prism Aug 28, 2024
@dansiegel
Copy link
Member

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.

@james1301
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants