Skip to content

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

@james1301

Description

@james1301

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()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions