Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8406363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T23:05:25+00:00 2026-06-09T23:05:25+00:00

I am trying to write some unit tests against a view model using SimpleMvvmToolkit,

  • 0

I am trying to write some unit tests against a view model using SimpleMvvmToolkit, and several of these tests require a message be sent to the message bus to fire events inside the view model. The problem is it appears that I can only ‘use’ the message bus once; the first test that sends a message passes, but the other two that send a message fail. But if I run each test individually, all three pass, and if I change the order, the first test, no matter which one it is, passes.

Here is a sample of one of the tests.

[TestMethod]
public void DeleteRequest()
{
    // mock the driver transaction service

    var driverTransactionService =
         new Mock<Services.IDriverTransactionService>();

    var viewModel = new ValidationRequestViewModel(
         driverTransactionService.Object);

    driverTransactionService.Setup(dts =>
         dts.DeleteValidationRequest(It.IsAny<Action<int>>(), 
              It.IsAny<Action<Exception>>(),
              It.IsAny<int>()))
        .Callback((Action<int> action, Action<Exception> ex, int id) => 
             action.Invoke(requestId));

    // make a validation request and add to the collection

    var validationRequest = new ValidationRequest...

    var collection = viewModel.ValidationRequestView.SourceCollection as 
         ObservableCollection<ValidationRequest>;

    collection.Add(validationRequest);

    //  delete the validation request; send the confirmation message as if
    //  the user clicked yes

    viewModel.DeleteValidationRequest(validationRequest);

    MessageBus.Default.Notify(
         NotificationMessages.DeleteValidationRequestConfirmation, 
         this, new NotificationEventArgs<String>(null, null));

    // verify the service call was made

    driverTransactionService.Verify(dts => 
         dts.DeleteValidationRequest(It.IsAny<Action<int>>(), 
              It.IsAny<Action<Exception>>(), requestId));
}

So I am creating a mock of a service (which is a wrapper around a WCF service) and verifying that DeleteValidatonRequest on the service is being called. In this case, the message bus is needed because a confirmation dialog would normally pop up and send the DeleteValidationRequestConfirmation message if the user clicks OK.

The test fails on the last line (Verify) and when I debug, the handler for the message in the view model never executes so it looks like the message is never actually sent. Again, this only fails if the test is not the first test to send a message to the bus. If it executes alone or is the first, the test passes.

Any ideas? All of the tests are independent and do not share any properties or variables of the test class so I don’t see how they could be stepping on each other.

EDIT: I used reflection to call the protected methods on the view model that the messages would normally fire; this gets me the code coverage I want, it just doesn’t verify that the view model is responding to messages correctly.

EDIT 2: Crap, the same thing is happening with PropertyChanged events on the view model. The event handler only fires if the test is run independently or is the first.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T23:05:26+00:00Added an answer on June 9, 2026 at 11:05 pm

    I’m not familiar with SimpleMvvmToolkit, but I am familiar with the concept of messaging.

    Don’t use MessageBus.Default. Modify your ViewModels to have a MessageBus, or IMessageBus if it exists, constructor parameter. Now your tests will be isolated, so you can run them all at once and they should pass.

    Additionally, if the IMessageBus interface exists, you can Mock it, which should make it even easier to test your ViewModels.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write some unit tests for a JPA model that I've built
Im trying to write some unit tests for a couple of merthods that are
I am trying to write some unit tests and I was wondering if there
I am currently trying to write some unit test against my zend framework controller.
I am trying to write some unit tests for a small web service written
I'm attempting to write some unit tests using EasyMock and TestNG and have run
I am trying to write some unit tests for my MVC3 project (the first
I am trying to write some Unit Tests to test some custom NSOperations that
I'm trying to write some unit tests for Command object validations. When my command
I am trying to use python's unittest library to write some unit tests. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.