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 6882637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:16:42+00:00 2026-05-27T05:16:42+00:00

I am new to rhino mocks and unit testing in general. I am starting

  • 0

I am new to rhino mocks and unit testing in general. I am starting to write some tests for my wpf mvvm app. Here is a sample scenario I am trying to test:

The view model:

List<DataItems> _theData = new List<DataItems>();
public MyViewModel(IServer server)
{
  _server = server;
  InitializeData();
}

private void InitializeData()
{
  _server.GetData(MyCallback);
}

private void MyCallback()
{
  _theData = _server.TheData;
}

public List<DataItems> VMData
{
   get
   {
     return _theData;
   }
}

Server:

public List<DataItems> TheData
{
  get
  {
    return _cachedData;
  }
}

public void GetData(Action callBack)
{
  //Populate cached data
  ...

  if(callBack != null)
  {
    callBack();
  }
}

In my test, I want to verify that viewModel.VMData.Count == server.TheData.Count. I tried using rhino mocks to stub the server, pre-poulating TheData with some values. The I called the view model constructor, and then tried to compare the counts.

My problem is that I do not know how to get my server to actually call back into my view model. After the vm constructor is called, InitializeData() is called as expected but the stub server’s GetData call is not made.

How can I make this simple test work?

  • 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-05-27T05:16:43+00:00Added an answer on May 27, 2026 at 5:16 am

    if you are stubbing IServer and expecting that the calling a method on the stub will invoke the implementation in your concrete class, that is your misconception. the GetData method on the stub instance will only return what you tell it to, and not execute any code in the concrete dependency. remember that the only thing your stub IServer object has in common with your concrete implemetation of IServer is that they both implement IServer. expecting that the side effects in the method in your concrete implemenation will happen when calling the method on the stub is just faulty.

    as to how to make it work: there’s not really a good way to do this test as you are stating with the design of these classes as is. you are trying to test that a side effect occurred in the dependency that you are stubbing out of participation. to really test what you want here and if you want to keep these classes with this relationship, i’d suggest that you don’t mock server at all and use the real object. redesign the server so that it depends on another component that loads from the cache so you can stub that thing instead.

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

Sidebar

Related Questions

I am new to Rhino Mocks, and using mock isolation frameworks in general for
a have some artefacts when using Rhino Mocks var mocks = new MockRepository(); INotifyMessageSender
I am using Rhino Mocks as a mocking framework for unit testing. I have
Is it possible to do some form of expect NEW in rhino mock. Example:
As per my previous question: Rhino Mocks - Testing Repository layer returns "object reference
Its prudent that I firstly say I'm new to both Rhino Mocks and to
I'll start by saying I am pretty new to unit testing and I'd like
We're currently facing some issues during Unit Testing. Our class is multithreading some function
I am new to Unit Testing, and I need to mock the File static
Is there a way to use mocks or fakes in your unit tests without

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.