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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:57:11+00:00 2026-05-13T09:57:11+00:00

I am new to Rhino Mocks, and using mock isolation frameworks in general for

  • 0

I am new to Rhino Mocks, and using mock isolation frameworks in general for unit testing. I have written the following test, where I have set up an expectation for a mock IDataProvider object to return a collection of objects. The collection supplied has one object in it.

When I run the test, the call to the IDataProvider returns a empty list when it should return the list with one object in it.

Any ideas whats going wrong?

Here is my test: (Please excuse any bad practises here… feel free to mention any. Im trying to learn! Thanks)

[TestMethod()]
public void FetchDataSeries_NeedsUpdate_SuccessfulDataSeriesRetrievedFromDataProvider() {
  List<IDataSeries> dataSeries = new List<IDataSeries>();
  dataSeries.Add(new DataSeries("test"));
  DrillDownLevel level = DrillDownLevel.YEAR;
  int? year = 2008;

  var dataProvider = _MockRepository.CreateMock<IDataProvider>();
  dataProvider.Expect(dp => dp.GetDataSeries(String.Empty, level, year, null ,null, null)).Return(dataSeries);
  _DataSourceContext.DataProvider = dataProvider;

  CollectionAssert.AreEqual(dataSeries, _DataSourceContext.FetchDataSeries(level, year, null, null, null));
  dataProvider.VerifyAllExpectations();
}

Relevant portion of method under test: (The DataProvider.GetDataSeries call returns empty list… this should return stubbed list.)

      public override List<IDataSeries> FetchDataSeries(DrillDownLevel? drillDownLevel, int? year, int? month, DateTime? week, int? day) {

    List<IDataSeries> dataSeries = new List<IDataSeries>();

    // Cache data for maximum cache period
    // if data has been cached for longer than the maxium cache period OR the updateInterval has elapsed UNLESS LastUpdateAttempt was less than minimum update interval
    if (NeedsUpdate(LastUpdate, LastUpdateAttempt)) {

      // Attempt to get new data
      LoggingService.InfoFormat("DataSourceContext: {0}: Attempting to get new data:", Name);
      dataSeries = DataProvider.GetDataSeries(DataQuery, drillDownLevel, year, month, week, day);
    }

    return dataSeries;
  }
  • 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-13T09:57:11+00:00Added an answer on May 13, 2026 at 9:57 am

    You’re missing a call to ReplayAll:

        _MockRepository.ReplayAll();
        CollectionAssert.AreEqual(dataSeries, _DataSourceContext.FetchDataSeries(level, year, null, null, null));
    

    See: http://ayende.com/Wiki/Comparison+of+different+Rhino+Mocks+syntaxes.ashx

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

Sidebar

Related Questions

I am using .NET 4, NUnit and Rhino mocks. I want to unit test
How can I raise an event from a mock/stub using Rhino Mocks? I've found
I am trying to write a Rhino Mocks test to verify that I have
I'm using NUnit and Rhino Mocks. I use the AAA-syntax and I do the
I was playing around with testing using machine specifications and there is something that
Most of the time when we use Rhino mocks it works well, but we
I'm currently building a class using TDD. The class is responsible for waiting for
I have been stuck on this for a day or two, I have recently
How do I test for state in a S#arp Architecture project? For example, I
I'm struggling to find a complete example of how to create the the request

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.