Question

I'm using the Confirmation class of Prism to ask users for Confirmation. When I'am unittesting the return value of the confirmation is always false. Maybe I could make the setter of the InteractionRequest public. My Code now looks like this and my unit test should verify that this.copyService.Execute is called.

public InteractionRequest<Confirmation> CopyProjectConfirmationRequest { get; private set; }

    bool confirmationResult = false;
    DialogConfirmation dialogConfirmation = new DialogConfirmation
                                              {
                                                Title = "Copy and Convert Project",
                                                Content = string.Format("This Project was created with Version {0} to be used with currentVersion({1}) it must be converted should it copyed and converted Project", projectVersion, toolVersion),
                                                ConfirmButtonText = "Copy & Convert",
                                                DeclineButtonText = "Cancel"
                                              };

    this.CopyProjectConfirmationRequest .Raise(dialogConfirmation, cb => { confirmationResult = cb.Confirmed; });

    if (confirmationResult)
    {
      this.copyService.Execute(this.Model);
    }
Was it helpful?

Solution

The Solution was quit simple. Just add this in the UnitTest

  sut.CopyProjectConfirmationRequest.Raised += (s, e) =>
  {
    Confirmation context = e.Context as Confirmation;
    context.Confirmed = true;
    e.Callback();
  };

OTHER TIPS

You can try mocking the copyService and testing against the mock Possible implementation with Moq

Mock<ICopyService> mockService;

.... inject in VM or the class that has the CopyProjectConfirmationRequest property.

mockService.Verify(x => x.Execute(It.Is<Model>(...));

As for the CopyProjectConfirmationRequest I would make the property public, and stub it in the unit test.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top